Module: CommandKit::Env::Shell

Includes:
CommandKit::Env
Included in:
Completion::Install
Defined in:
lib/command_kit/env/shell.rb

Overview

Methods related to the SHELL environment variable.

Environment Variables

  • SHELL - The current shell.

Since:

  • 0.5.0

Instance Attribute Summary collapse

Attributes included from CommandKit::Env

#env

Instance Method Summary collapse

Instance Attribute Details

#shellString? (readonly)

The current shell.

Returns:

  • (String, nil)

Since:

  • 0.5.0



22
23
24
# File 'lib/command_kit/env/shell.rb', line 22

def shell
  @shell
end

#shell_type:bash, ... (readonly)

The current shell type.

Returns:

  • (:bash, :zsh, :fish, :dash, :mksh, :ksh, :tcsh, :csh, :sh, nil)

Since:

  • 0.5.0



27
28
29
# File 'lib/command_kit/env/shell.rb', line 27

def shell_type
  @shell_type
end

Instance Method Details

#initialize(**kwargs) ⇒ Object

Initialize #shell and #shell_type based on the SHELL environment variable.

Parameters:

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments.

Since:

  • 0.5.0



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/command_kit/env/shell.rb', line 38

def initialize(**kwargs)
  super(**kwargs)

  @shell      = env['SHELL']
  @shell_type = if @shell
                  case File.basename(@shell)
                  when /bash/ then :bash
                  when /zsh/  then :zsh
                  when /fish/ then :fish
                  when /dash/ then :dash
                  when /mksh/ then :mksh
                  when /ksh/  then :ksh
                  when /tcsh/ then :tcsh
                  when /csh/  then :csh
                  when /sh/   then :sh
                  end
                end
end