class ListDirectoryWish
Public Class Methods
new()
click to toggle source
# File lib/git_xplorer/wish/list_directory_wish.rb, line 39 def initialize @space = 4 end
Public Instance Methods
aliases()
click to toggle source
# File lib/git_xplorer/wish/list_directory_wish.rb, line 4 def aliases return ["ls", "ll"] end
description()
click to toggle source
# File lib/git_xplorer/wish/list_directory_wish.rb, line 8 def description return "List directory contents or file revisions" end
execute(args, djinni_env = Hash.new)
click to toggle source
# File lib/git_xplorer/wish/list_directory_wish.rb, line 12 def execute(args, djinni_env = Hash.new) gitx = djinni_env["gitXplorer"] long = false case djinni_env["djinni_input"] when "ll" long = true end if (args.match(/(^| )(-l|--long)( |$)/)) args.gsub!(/(^| )(-l|--long)( |$)/, "") long = true end begin children = gitx.ls(args) if (long) long(children) else children.each do |child| puts child end end rescue GitXplorer::Error => e puts e.message end end
tab_complete(input, djinni_env = Hash.new)
click to toggle source
# File lib/git_xplorer/wish/list_directory_wish.rb, line 72 def tab_complete(input, djinni_env = Hash.new) gitx = djinni_env["gitXplorer"] _, found, partial = input.rpartition(":") _, _, partial = input.rpartition("/") if (found.empty?) completions = Hash.new gitx.get_completions(input).each do |child| completions.merge!(child.tab_complete) end return [completions, partial, ""] end
usage()
click to toggle source
# File lib/git_xplorer/wish/list_directory_wish.rb, line 86 def usage puts "#{aliases.join(", ")} [OPTIONS] [directory/file]" puts " #{description}." puts puts "OPTIONS" puts " -l, --long Show more info for files" end
Private Instance Methods
long(children)
click to toggle source
# File lib/git_xplorer/wish/list_directory_wish.rb, line 43 def long(children) max = children.max_by do |child| child.to_s.length end.to_s.length nlfill = " " * (max + @space) width = %x(tput cols).to_i - (max + @space) - 2 children.each do |child| name = child.to_s desc = child.desc fill = " " * (max + @space - name.length) fill = "" if ((max + @space - name.length) <= 0) lines = Array.new if (desc) lines = desc.scan(/\S.{0,#{width}}\S(?=\s|$)|\S+/) end if (lines.empty?) puts name else start = lines.delete_at(0) puts "#{name}#{fill}#{start}" lines.each do |line| puts "#{nlfill}#{line}" end end end end