Class: Inspec::ShellDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/shell_detector.rb

Overview

ShellDetector attempts to detect the shell the invoking user is running by checking:

- The command of our parent
- The SHELL environment variable
- The shell returned by getpwuid for our process UID

Since none of these methods is fullproof, the detected shell is verified against a list of known shells before being returned to the caller.

Constant Summary collapse

NOT_DETECTED =
Object.new.freeze
KNOWN_SHELLS =
%w{bash zsh ksh csh sh fish}.freeze

Instance Method Summary collapse

Constructor Details

#initializeShellDetector

Returns a new instance of ShellDetector.



22
23
24
# File 'lib/inspec/shell_detector.rb', line 22

def initialize
  @shell = NOT_DETECTED
end

Instance Method Details

#shellObject



26
27
28
29
# File 'lib/inspec/shell_detector.rb', line 26

def shell
  @shell = detect if !detected?(@shell)
  @shell
end

#shell!Object



31
32
33
# File 'lib/inspec/shell_detector.rb', line 31

def shell!
  @shell = detect
end