Module: Completion::Shell::Fish
- Defined in:
- lib/completion/shell/fish.rb
Overview
Fish completion adapter generation.
Class Method Summary collapse
-
.complete_function ⇒ Object
Generate the Fish completion function.
-
.register_default_function ⇒ Object
Generate the Fish generic registration function.
-
.register_function ⇒ Object
Generate the Fish command registration function.
-
.resolve_function ⇒ Object
Generate the Fish completion command resolver function.
-
.script(executable) ⇒ Object
Generate a Fish completion adapter script.
-
.shared_functions ⇒ Object
Get the shared Fish helper function files.
-
.supported_function ⇒ Object
Generate the Fish support detection function.
Class Method Details
.complete_function ⇒ Object
Generate the Fish completion function.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/completion/shell/fish.rb', line 44 def self.complete_function Shell.annotate(<<~SCRIPT, kind: "helper", shell: "fish") function __completion_complete --description 'Complete commands with adjacent completion executables' set -l argv (commandline -opc) set -e argv[1] set -l current (commandline -ct) if test -n "$current" set -a argv $current else set -a argv "" end set -l completer (__completion_resolve) $completer $argv | while read -l line set -l fields (string split (printf "\\t") -- $line) set -l type $fields[1] set -l value $fields[2] set -l description $fields[3] set -l metadata $fields[4..-1] switch "$type" case path __fish_complete_path "$value" case directory __fish_complete_directories "$value" case executable complete -C "$value" case delegate set -l index for field in $metadata switch "$field" case "index=*" set index (string replace "index=" "" -- "$field") end end if test -n "$index" set -l start (math $index + 1) set -l delegated $argv[$start..-1] complete -C (string join " " -- (string escape -- $delegated)) end case "*" echo "$value $description" end end end SCRIPT end |
.register_default_function ⇒ Object
Generate the Fish generic registration function.
108 109 110 111 112 113 114 |
# File 'lib/completion/shell/fish.rb', line 108 def self.register_default_function Shell.annotate(<<~SCRIPT, kind: "helper", shell: "fish") function __completion_register_default --description 'Register generic completion' complete -c "*" -n "__completion_supported" -f -a "(__completion_complete)" end SCRIPT end |
.register_function ⇒ Object
Generate the Fish command registration function.
97 98 99 100 101 102 103 |
# File 'lib/completion/shell/fish.rb', line 97 def self.register_function Shell.annotate(<<~SCRIPT, kind: "helper", shell: "fish") function __completion_register --description 'Register command completion' complete -c $argv[1] -f -a "(__completion_complete)" end SCRIPT end |
.resolve_function ⇒ Object
Generate the Fish completion command resolver function.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/completion/shell/fish.rb', line 119 def self.resolve_function Shell.annotate(<<~SCRIPT, kind: "helper", shell: "fish") function __completion_resolve --description 'Resolve completion command' set -l argv (commandline -opc) set -l command $argv[1] set -l basename (basename "$command") if string match -q "*/*" "$command" echo (dirname "$command")/completion-$basename else echo completion-$basename end end SCRIPT end |
.script(executable) ⇒ Object
Generate a Fish completion adapter script.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/completion/shell/fish.rb', line 14 def self.script(executable) command = Shell.command_name(executable) if executable return Shell.annotate(<<~SCRIPT, kind: "adapter", shell: "fish", executable: executable) __completion_register #{command} SCRIPT end Shell.annotate(<<~SCRIPT, kind: "adapter", shell: "fish") __completion_register_default SCRIPT end |
.shared_functions ⇒ Object
Get the shared Fish helper function files.
31 32 33 34 35 36 37 38 39 |
# File 'lib/completion/shell/fish.rb', line 31 def self.shared_functions { "__completion_complete.fish" => complete_function, "__completion_register.fish" => register_function, "__completion_register_default.fish" => register_default_function, "__completion_resolve.fish" => resolve_function, "__completion_supported.fish" => supported_function, } end |
.supported_function ⇒ Object
Generate the Fish support detection function.
138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/completion/shell/fish.rb', line 138 def self.supported_function Shell.annotate(<<~SCRIPT, kind: "helper", shell: "fish") function __completion_supported --description 'Check completion support' set -l completer (__completion_resolve) if string match -q "*/*" "$completer" test -x "$completer" else type -q "$completer" end end SCRIPT end |