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 = {}) ⇒ Object



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

def execute(args, djinni_env = {})
    keepass = djinni_env["keepass"]
    cwd = djinni_env["cwd"]

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

    if (new_cwd)
        djinni_env["cwd"] = new_cwd
        prompt = "rpass:#{new_cwd.name}> ".white
        djinni_env["djinni_prompt"] = prompt
    else
        puts "Group \"#{args}\" doesn't exist!"
    end
end

#tab_complete(input, djinni_env = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rubeepass/wish/cd_wish.rb', line 29

def tab_complete(input, djinni_env = {})
    cwd = djinni_env["cwd"]
    input, groups = cwd.fuzzy_find(input)
    return input.gsub(%r{^#{cwd.path}/?}, "") if (groups.empty?)

    path, dest = input.rsplit("/")

    if (dest.empty?)
        if (groups.length == 1)
            input = "#{path}/#{groups.first}/"
            return input.gsub(%r{^#{cwd.path}/?}, "")
        end
        puts
        groups.each do |group|
            puts "#{group}/"
        end
        return input.gsub(%r{^#{cwd.path}/?}, "")
    end

    input = "#{path}/#{groups.first}/"
    return input.gsub(%r{^#{cwd.path}/?}, "")
end

#usageObject



52
53
54
55
# File 'lib/rubeepass/wish/cd_wish.rb', line 52

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