Class: Ukiryu::Shell::Zsh

Inherits:
UnixBase show all
Defined in:
lib/ukiryu/shell/zsh.rb

Overview

Zsh shell implementation

Zsh uses the same quoting and escaping rules as Bash.

Constant Summary collapse

SHELL_NAME =
:zsh
EXECUTABLE =
'zsh'

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 Zsh alias

Zsh uses the same ‘type’ builtin as Bash.

Parameters:

  • command_name (String)

    the command to check

Returns:

  • (Hash, nil)

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



18
19
20
21
# File 'lib/ukiryu/shell/zsh.rb', line 18

def self.detect_alias(command_name)
  # Zsh uses the same 'type' builtin as Bash
  Bash.detect_alias(command_name)
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)



48
49
50
# File 'lib/ukiryu/shell/zsh.rb', line 48

def env_var(name)
  "$#{name}"
end

#escape(string) ⇒ Object

Zsh uses the same escaping as Bash



35
36
37
# File 'lib/ukiryu/shell/zsh.rb', line 35

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



57
58
59
# File 'lib/ukiryu/shell/zsh.rb', line 57

def join(executable, *args)
  [quote(executable), *args.map { |a| quote(a) }].join(' ')
end

#nameObject



23
24
25
# File 'lib/ukiryu/shell/zsh.rb', line 23

def name
  :zsh
end

#quote(string) ⇒ Object

Zsh uses the same quoting as Bash



40
41
42
# File 'lib/ukiryu/shell/zsh.rb', line 40

def quote(string)
  "'#{escape(string)}'"
end

#shell_commandString

Get the zsh command name to search for

Returns:

  • (String)

    the zsh command name



30
31
32
# File 'lib/ukiryu/shell/zsh.rb', line 30

def shell_command
  'zsh'
end