Class: Mnenv::Shells::ShellFactory
- Inherits:
-
Object
- Object
- Mnenv::Shells::ShellFactory
- Defined in:
- lib/mnenv/shells/factory.rb
Overview
Factory for detecting and creating shell instances
Constant Summary collapse
- SHELLS =
{ 'bash' => BashShell, 'sh' => BashShell, 'dash' => BashShell, 'zsh' => BashShell, 'fish' => BashShell, # Fish can run bash scripts in compatibility mode 'powershell' => PowerShellShell, 'pwsh' => PowerShellShell, 'cmd' => CmdShell }.freeze
Class Method Summary collapse
-
.detect ⇒ Object
Detect the current shell from environment.
-
.get(shell_name) ⇒ Object
Get shell by name.
-
.platform_shells ⇒ Object
Get all shells for the current platform.
Class Method Details
.detect ⇒ Object
Detect the current shell from environment
25 26 27 28 29 30 31 32 33 |
# File 'lib/mnenv/shells/factory.rb', line 25 def detect shell_env = ENV['SHELL'] || ENV['COMSPEC'] || '' if windows? detect_windows_shell(shell_env) else detect_unix_shell(shell_env) end end |
.get(shell_name) ⇒ Object
Get shell by name
36 37 38 39 40 41 |
# File 'lib/mnenv/shells/factory.rb', line 36 def get(shell_name) shell_class = SHELLS[shell_name.downcase] raise ArgumentError, "Unknown shell: #{shell_name}" unless shell_class shell_class.new end |
.platform_shells ⇒ Object
Get all shells for the current platform
44 45 46 47 48 49 50 |
# File 'lib/mnenv/shells/factory.rb', line 44 def platform_shells if windows? [PowerShellShell.new, CmdShell.new] else [BashShell.new] end end |