Class: Ukiryu::Shell::Fish

Inherits:
UnixBase show all
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

UnixBase::PLATFORM

Constants inherited from Base

Base::PLATFORM, Base::SPECIAL_CHARS_PATTERN, Base::WHITESPACE_PATTERN

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • command_name (String)

    the command to check

Returns:

  • (Hash, nil)

    “…”, target: “…” or nil if not an alias



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

Parameters:

  • name (String)

    the variable name

Returns:

  • (String)

    the formatted reference ($VAR)



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

Parameters:

  • executable (String)

    the executable path

  • args (Array<String>)

    the arguments

Returns:

  • (String)

    the complete 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

#nameObject



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_commandString

Get the fish command name to search for

Returns:

  • (String)

    the fish command name



38
39
40
# File 'lib/ukiryu/shell/fish.rb', line 38

def shell_command
  'fish'
end