Class: LSWish

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

Instance Method Summary collapse

Instance Method Details

#aliasesObject



4
5
6
# File 'lib/rubeepass/wish/ls_wish.rb', line 4

def aliases
    return ["ls", "dir"]
end

#descriptionObject



8
9
10
# File 'lib/rubeepass/wish/ls_wish.rb', line 8

def description
    return "List groups and entries in current group"
end

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



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

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

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

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

    new_cwd.group_names.each do |group|
        puts "#{group}/"
    end
    new_cwd.entry_titles.each do |entry|
        puts "#{entry}"
    end
end

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



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rubeepass/wish/ls_wish.rb', line 33

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



45
46
47
48
# File 'lib/rubeepass/wish/ls_wish.rb', line 45

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