Class: CDWish

Inherits:
Djinni::Wish
  • Object
show all
Defined in:
lib/rubeepass/wish/cd_wish.rb

Instance Method Summary collapse

Instance Method Details

#aliasesObject



5
6
7
# File 'lib/rubeepass/wish/cd_wish.rb', line 5

def aliases
    return ["cd"]
end

#descriptionObject



9
10
11
# File 'lib/rubeepass/wish/cd_wish.rb', line 9

def description
    return "Change to new group"
end

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



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rubeepass/wish/cd_wish.rb', line 13

def execute(args, djinni_env = Hash.new)
    keepass = djinni_env["keepass"]
    cwd = djinni_env["cwd"]
    prompt_color = djinni_env["prompt_color"]

    path = keepass.absolute_path(args, cwd.path)
    new_cwd = keepass.find_group_like(path)

    if (new_cwd.nil?)
        puts "Group not found"
        return
    end

    djinni_env["cwd"] = new_cwd
    if (prompt_color)
        prompt = "rpass:#{new_cwd.name}> ".send(prompt_color)
    else
        prompt = "rpass:#{new_cwd.name}> "
    end
    djinni_env["djinni_prompt"] = prompt
end

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



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rubeepass/wish/cd_wish.rb', line 35

def tab_complete(input, djinni_env = Hash.new)
    cwd = djinni_env["cwd"]
    groups, _ = cwd.fuzzy_find(input)

    completions = Hash.new
    groups.each do |group|
        completions[group] = "Group"
    end

    return [completions, input.rpartition("/")[-1], "/"]
end

#usageObject



47
48
49
50
# File 'lib/rubeepass/wish/cd_wish.rb', line 47

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