Class: Ukiryu::Shell::Fish
- Defined in:
- lib/ukiryu/shell/fish.rb
Overview
Fish shell implementation
Fish uses similar quoting to Bash for most cases.
Constant Summary collapse
- SHELL_NAME =
:fish- EXECUTABLE =
'fish'
Constants inherited from UnixBase
Constants inherited from Base
Base::PLATFORM, Base::SPECIAL_CHARS_PATTERN, Base::WHITESPACE_PATTERN
Class Method Summary collapse
-
.detect_alias(command_name) ⇒ Hash?
Detect if a command is a Fish alias.
Instance Method Summary collapse
-
#env_var(name) ⇒ String
Format an environment variable reference.
-
#escape(string) ⇒ Object
Fish uses the same escaping as Bash.
-
#join(executable, *args) ⇒ String
Join executable and arguments into a command line.
- #name ⇒ Object
-
#quote(string) ⇒ Object
Fish uses the same quoting as Bash.
-
#shell_command ⇒ String
Get the fish command name to search for.
Methods inherited from UnixBase
#execute_command, #execute_command_with_stdin, #shell_executable
Methods inherited from Base
#capabilities, #encoding, #environment_to_h, #execute_command, #execute_command_with_stdin, #format_environment, #format_path, #headless_environment, #needs_quoting?, #supports?
Class Method Details
.detect_alias(command_name) ⇒ Hash?
Detect if a command is a Fish alias
Fish uses ‘type’ command with different output format than Bash.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ukiryu/shell/fish.rb', line 18 def self.detect_alias(command_name) # Fish uses 'type' command with different output result = `type #{command_name} 2>/dev/null` return nil unless result if result.include?("#{command_name} is an alias") && (result =~ /alias #{command_name} ['"](.*)['"]/) # Parse fish alias format # Format: "alias ll 'ls -l --color=auto'" { definition: result.strip, target: ::Regexp.last_match(1) } end nil end |
Instance Method Details
#env_var(name) ⇒ String
Format an environment variable reference
56 57 58 |
# File 'lib/ukiryu/shell/fish.rb', line 56 def env_var(name) "$#{name}" end |
#escape(string) ⇒ Object
Fish uses the same escaping as Bash
43 44 45 |
# File 'lib/ukiryu/shell/fish.rb', line 43 def escape(string) string.to_s.gsub("'") { "'\\''" } end |
#join(executable, *args) ⇒ String
Join executable and arguments into a command line
65 66 67 |
# File 'lib/ukiryu/shell/fish.rb', line 65 def join(executable, *args) [quote(executable), *args.map { |a| quote(a) }].join(' ') end |
#name ⇒ Object
31 32 33 |
# File 'lib/ukiryu/shell/fish.rb', line 31 def name :fish end |
#quote(string) ⇒ Object
Fish uses the same quoting as Bash
48 49 50 |
# File 'lib/ukiryu/shell/fish.rb', line 48 def quote(string) "'#{escape(string)}'" end |
#shell_command ⇒ String
Get the fish command name to search for
38 39 40 |
# File 'lib/ukiryu/shell/fish.rb', line 38 def shell_command 'fish' end |