Class: Ukiryu::Shell::Bash
- Defined in:
- lib/ukiryu/shell/bash.rb
Overview
Bash shell implementation
Bash uses single quotes for literal strings and backslash for escaping. Environment variables are referenced with $VAR syntax.
Constant Summary collapse
- SHELL_NAME =
:bash- EXECUTABLE =
'bash'
Constants inherited from UnixBase
Constants inherited from Base
Ukiryu::Shell::Base::PLATFORM, Ukiryu::Shell::Base::SPECIAL_CHARS_PATTERN, Ukiryu::Shell::Base::WHITESPACE_PATTERN
Class Method Summary collapse
-
.detect_alias(command_name) ⇒ Hash?
Detect if a command is a Bash alias.
-
.extract_command_from_alias(alias_def) ⇒ String
Extract the first word from an alias definition.
Instance Method Summary collapse
-
#env_var(name) ⇒ String
Format an environment variable reference.
-
#escape(string) ⇒ String
Escape a string for Bash Single quotes are literal (no escaping inside), so we end the quote, add an escaped quote, and restart the quote.
-
#headless_environment ⇒ Hash
Get headless environment (disable DISPLAY on Unix).
-
#join(executable, *args) ⇒ String
Join executable and arguments into a command line.
- #name ⇒ Object
-
#quote(string) ⇒ String
Quote an argument for Bash Uses single quotes for literal strings.
-
#shell_command ⇒ String
Get the bash 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, #needs_quoting?, #supports?
Class Method Details
.detect_alias(command_name) ⇒ Hash?
Detect if a command is a Bash alias
Uses the ‘type’ builtin which returns “X is alias Y” for aliases.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ukiryu/shell/bash.rb', line 19 def self.detect_alias(command_name) # Use 'type' builtin which returns "alias is alias" for aliases result = `type #{command_name} 2>/dev/null` return nil unless result if result =~ /^#{command_name} is alias (.*)$/ alias_definition = ::Regexp.last_match(1) # Extract target from alias definition # Format: alias ll='ls -l' if alias_definition =~ /^'(.*)'$/ target = ::Regexp.last_match(1) target = extract_command_from_alias(target) { definition: result.strip, target: target } end end nil end |
.extract_command_from_alias(alias_def) ⇒ String
Extract the first word from an alias definition
41 42 43 44 45 |
# File 'lib/ukiryu/shell/bash.rb', line 41 def self.extract_command_from_alias(alias_def) # Extract the first word from the alias definition # e.g., "ls -l --color=auto" -> "ls" alias_def.split(/\s+/).first end |
Instance Method Details
#env_var(name) ⇒ String
Format an environment variable reference
81 82 83 |
# File 'lib/ukiryu/shell/bash.rb', line 81 def env_var(name) "$#{name}" end |
#escape(string) ⇒ String
Escape a string for Bash Single quotes are literal (no escaping inside), so we end the quote, add an escaped quote, and restart the quote.
64 65 66 |
# File 'lib/ukiryu/shell/bash.rb', line 64 def escape(string) string.to_s.gsub("'") { "'\\''" } end |
#headless_environment ⇒ Hash
Get headless environment (disable DISPLAY on Unix)
For macOS, adds additional variables to prevent GUI initialization that can cause crashes in GUI applications like Inkscape.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/ukiryu/shell/bash.rb', line 100 def headless_environment env = {} # Completely remove DISPLAY instead of setting to empty string # This ensures full headless mode with no display connection # The executor will exclude this key from the environment entirely # Add macOS-specific environment variables to prevent GUI initialization if Ukiryu::Platform.detect == :macos env['NSAppleEventsSuppressStartupAlert'] = 'true' # Suppress Apple Events env['NSUIElement'] = '1' # Run as background agent env['GDK_BACKEND'] = 'x11' # Force X11 backend (respects missing DISPLAY) end env end |
#join(executable, *args) ⇒ String
Join executable and arguments into a command line
90 91 92 |
# File 'lib/ukiryu/shell/bash.rb', line 90 def join(executable, *args) [quote(executable), *args.map { |a| quote(a) }].join(' ') end |
#name ⇒ Object
47 48 49 |
# File 'lib/ukiryu/shell/bash.rb', line 47 def name :bash end |
#quote(string) ⇒ String
Quote an argument for Bash Uses single quotes for literal strings
73 74 75 |
# File 'lib/ukiryu/shell/bash.rb', line 73 def quote(string) "'#{escape(string)}'" end |
#shell_command ⇒ String
Get the bash command name to search for
54 55 56 |
# File 'lib/ukiryu/shell/bash.rb', line 54 def shell_command 'bash' end |