Class: Tomo::Commands::CompletionScript

Inherits:
Object
  • Object
show all
Defined in:
lib/tomo/commands/completion_script.rb

Class Method Summary collapse

Class Method Details

.parse(_argv) ⇒ Object



6
7
8
9
10
11
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
44
45
# File 'lib/tomo/commands/completion_script.rb', line 6

def self.parse(_argv)
  puts <<~'SCRIPT'
    # TOMO COMPLETIONS FOR BASH
    #
    # Assuming tomo is in your PATH, you can install tomo bash completions by
    # adding this line to your .bashrc:
    #
    #   eval "$(tomo completion-script)"
    #
    # The eval technique is a bit slow but ensures bash is always using the
    # latest version of the tomo completion script.
    #
    # Alternatively, you can copy and paste the current version of the script
    # into your .bashrc. The full script is listed below.

    _tomo_complete() {
      local cur="${COMP_WORDS[COMP_CWORD]}"
      local prev="${COMP_WORDS[COMP_CWORD-1]}"

      if [[ $prev == "-c" || $prev == "--config" ]]; then
        COMPREPLY=($(compgen -f -- ${cur}))
        return 0
      fi

      if [[ "${COMP_LINE: -1}" == " " ]]; then
        command=${COMP_LINE/tomo/tomo --complete}
      else
        command=${COMP_LINE/tomo/tomo --complete-word}
      fi

      suggestions=$($command)
      local IFS=$'\n'
      COMPREPLY=($suggestions)
      return 0
    }

    complete -o nospace -F _tomo_complete tomo

  SCRIPT
end