class Djinni::Wish::History
Public Instance Methods
aliases()
click to toggle source
# File lib/djinni/wish/history.rb, line 2 def aliases return ["hist", "history"] end
description()
click to toggle source
# File lib/djinni/wish/history.rb, line 6 def description return "Show history or execute commands from history" end
execute(args, djinni_env = {})
click to toggle source
# File lib/djinni/wish/history.rb, line 10 def execute(args, djinni_env = {}) djinni = djinni_env["djinni"] history = djinni_env["djinni_history"] if (args.empty?) history.each_with_index do |hist, index| puts "#{index}: #{hist}" end return end args.split(" ").each do |arg| case arg when "clear" # Do nothing when /^[0-9]+$/ index = arg.to_i if ((index < 0) || (index >= history.length)) puts "Index out of bounds; #{index}" end else usage return end end args.split(" ").each do |arg| case arg when "clear" history.clear when /^[0-9]+$/ index = arg.to_i print "\e[F" djinni.grant_wish("#{history[index]}\n", djinni_env) end end end
tab_complete(input, djinni_env = {})
click to toggle source
# File lib/djinni/wish/history.rb, line 48 def tab_complete(input, djinni_env = {}) history = djinni_env["djinni_history"] input, found, last = input.rpartition(" ") included = input.split(" ") completions = Hash.new (0...history.length).each do |i| completions[i.to_s] = history[i] end completions["clear"] = "Clear history" completions.keep_if do |item, desc| !included.include?(item) end if (!last.empty?) completions.keep_if do |item, desc| item.downcase.start_with?(last.downcase) end end return [completions, last, " "] end
usage()
click to toggle source
# File lib/djinni/wish/history.rb, line 72 def usage puts "history [option]" puts " #{description}." puts " OPTIONS" puts " [0-9]+ Execute command from history" puts " clear Clear history" end