Class: RenameWish

Inherits:
Djinni::Wish
  • Object
show all
Defined in:
lib/zoom/wish/rename_wish.rb

Instance Method Summary collapse

Instance Method Details

#aliasesObject



4
5
6
# File 'lib/zoom/wish/rename_wish.rb', line 4

def aliases
    return ["mv", "rename"]
end

#descriptionObject



8
9
10
# File 'lib/zoom/wish/rename_wish.rb', line 8

def description
    return "Rename the specified profile"
end

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



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/zoom/wish/rename_wish.rb', line 12

def execute(args, djinni_env = {})
    if (args.split(" ").length != 2)
        usage
        return
    end

    config = djinni_env["config"]

    old, new = args.split(" ")
    if (!config.has_profile?(old))
        puts("Profile does not exist: #{old}")
    elsif (config.has_profile?(new))
        puts("Profile already exists: #{new}")
    else
        profiles = config.parse_profiles
        profiles[new] = profiles.delete(old)
        profiles[new].name(new)
        config.set_profiles(profiles)

        # Update prompt
        if (config.get_current_profile_name == old)
            config.set_current_profile_name(new)
            prompt_color = djinni_env["prompt_color"]
            if (prompt_color)
                prompt = "zoom(#{new})> ".send(prompt_color)
            else
                prompt = "zoom(#{new})> "
            end
            djinni_env["djinni_prompt"] = prompt
        end
    end
end

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



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/zoom/wish/rename_wish.rb', line 45

def tab_complete(input, djinni_env = {})
    return [{}, "", ""] if (input.include?(" "))

    profiles = djinni_env["config"].parse_profiles
    completions = Hash.new

    profiles.keys.sort do |a, b|
        a.downcase <=> b.downcase
    end.each do |name|
        profile = profiles[name]
        completions[name] = profile.to_s.split("\n")[1].strip
    end

    completions.keep_if do |name, desc|
        name.downcase.start_with?(input.downcase)
    end

    return [completions, input, " "]
end

#usageObject



65
66
67
68
# File 'lib/zoom/wish/rename_wish.rb', line 65

def usage
    puts("#{aliases.join(", ")} <old_name> <new_name>")
    puts("    #{description}.")
end