Module: Completion::Shell
- Defined in:
- lib/completion/shell.rb,
lib/completion/shell/zsh.rb,
lib/completion/shell/bash.rb,
lib/completion/shell/fish.rb
Overview
Shell adapter generation helpers.
Defined Under Namespace
Class Method Summary collapse
-
.command_name(executable) ⇒ Object
Get the command name from an executable path.
-
.default_directory(shell) ⇒ Object
Get the default completion directory for a shell.
-
.default_function_directory ⇒ Object
Get the default Fish function directory.
-
.default_shell ⇒ Object
Detect the current shell from the environment.
-
.file_name(shell, executable = nil) ⇒ Object
Get the installed adapter file name for a shell.
-
.script(shell:, executable: nil) ⇒ Object
Generate a shell adapter script.
-
.shared_file_name(shell) ⇒ Object
Get the installed shared helper file name for a shell.
-
.shared_script(shell:) ⇒ Object
Generate a shared shell helper script.
-
.shell_name(path) ⇒ Object
Extract a shell name from a path.
Class Method Details
.command_name(executable) ⇒ Object
Get the command name from an executable path.
120 121 122 |
# File 'lib/completion/shell.rb', line 120 def self.command_name(executable) File.basename(executable || "completion") end |
.default_directory(shell) ⇒ Object
Get the default completion directory for a shell.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/completion/shell.rb', line 28 def self.default_directory(shell) case shell when "bash" File.("~/.local/share/bash-completion/completions") when "fish" File.("~/.config/fish/completions") when "zsh" File.("~/.zsh/completions") else raise ArgumentError, "Unsupported shell: #{shell.inspect}" end end |
.default_function_directory ⇒ Object
Get the default Fish function directory.
44 45 46 |
# File 'lib/completion/shell.rb', line 44 def self.default_function_directory File.("~/.config/fish/functions") end |
.default_shell ⇒ Object
Detect the current shell from the environment.
20 21 22 |
# File 'lib/completion/shell.rb', line 20 def self.default_shell shell_name(ENV["SHELL"]) end |
.file_name(shell, executable = nil) ⇒ Object
Get the installed adapter file name for a shell.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/completion/shell.rb', line 53 def self.file_name(shell, executable = nil) command = executable || "completion" case shell when "bash" command when "fish" "#{command}.fish" when "zsh" "_#{command}" else raise ArgumentError, "Unsupported shell: #{shell.inspect}" end end |
.script(shell:, executable: nil) ⇒ Object
Generate a shell adapter script.
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/completion/shell.rb', line 88 def self.script(shell:, executable: nil) case shell.to_sym when :bash Bash.script(executable) when :fish Fish.script(executable) when :zsh Zsh.script(executable) else raise ArgumentError, "Unsupported shell: #{shell.inspect}" end end |
.shared_file_name(shell) ⇒ Object
Get the installed shared helper file name for a shell.
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/completion/shell.rb', line 72 def self.shared_file_name(shell) case shell when "bash" "completion.bash" when "zsh" "completion.zsh" else raise ArgumentError, "Unsupported shell: #{shell.inspect}" end end |
.shared_script(shell:) ⇒ Object
Generate a shared shell helper script.
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/completion/shell.rb', line 105 def self.shared_script(shell:) case shell.to_sym when :bash Bash.shared_script when :zsh Zsh.shared_script else raise ArgumentError, "Unsupported shell: #{shell.inspect}" end end |
.shell_name(path) ⇒ Object
Extract a shell name from a path.
13 14 15 |
# File 'lib/completion/shell.rb', line 13 def self.shell_name(path) File.basename(path.to_s) end |