Class: ChangeDirectoryWish

Inherits:
Djinni::Wish
  • Object
show all
Defined in:
lib/git_xplorer/wish/change_directory_wish.rb

Instance Method Summary collapse

Instance Method Details

#aliasesObject



5
6
7
# File 'lib/git_xplorer/wish/change_directory_wish.rb', line 5

def aliases
    return ["cd"]
end

#descriptionObject



9
10
11
# File 'lib/git_xplorer/wish/change_directory_wish.rb', line 9

def description
    return "Change to new directory"
end

#execute(args, djinni_env = Hash.new) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/git_xplorer/wish/change_directory_wish.rb', line 13

def execute(args, djinni_env = Hash.new)
    gitx = djinni_env["gitXplorer"]
    begin
        gitx.cd(args)
        prompt = "#{gitx.pwd_short}$ ".light_white
        djinni_env["djinni_prompt"] = prompt
    rescue GitXplorer::Error => e
        puts e.message
    end
end

#tab_complete(input, djinni_env = Hash.new) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/git_xplorer/wish/change_directory_wish.rb', line 24

def tab_complete(input, djinni_env = Hash.new)
    gitx = djinni_env["gitXplorer"]

    _, _, partial = input.rpartition("/")
    partial = "" if (input.end_with?("/"))

    completions = Hash.new
    gitx.get_completions(input).select do |child|
        child.is_a?(GitXplorer::GitObject::Directory)
    end.each do |child|
        completions.merge!(child.tab_complete)
    end

    return [completions, partial, ""]
end

#usageObject



40
41
42
43
# File 'lib/git_xplorer/wish/change_directory_wish.rb', line 40

def usage
    puts "#{aliases.join(", ")} [directory]"
    puts "    #{description}."
end