Class: LSWish

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

Instance Method Summary collapse

Instance Method Details

#aliasesObject



5
6
7
# File 'lib/builtins/ls_wish.rb', line 5

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

#descriptionObject



9
10
11
# File 'lib/builtins/ls_wish.rb', line 9

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

#execute(args, djinni_env = {}) ⇒ Object



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

def execute(args, djinni_env = {})
    keepass = djinni_env["keepass"]
    cwd = djinni_env["cwd"]
    args = cwd.path if (args.nil? || args.empty?)

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

    if (new_cwd)
        new_cwd.group_names.each do |group|
            puts "#{group}/"
        end
        new_cwd.entry_titles.each do |entry|
            puts "#{entry}"
        end
    else
        puts "Group \"#{args}\" doesn't exist!"
    end
end

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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/builtins/ls_wish.rb', line 33

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



56
57
58
59
# File 'lib/builtins/ls_wish.rb', line 56

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