Module: Env::Variables

Included in:
Env
Defined in:
lib/env/variables.rb

Instance Method Summary collapse

Instance Method Details

#browserString?

The default browser to use.

Returns:

  • (String, nil)

    The name of the browser program.



142
143
144
# File 'lib/env/variables.rb', line 142

def browser
  env_hash['BROWSER']
end

#columnsInteger

The number of columns in the terminal.

Returns:

  • (Integer)

    The number of columns.



82
83
84
# File 'lib/env/variables.rb', line 82

def columns
  env_hash['COLUMNS'].to_i if env_hash['COLUMNS']
end

#editorString?

The default editor to use.

Returns:

  • (String, nil)

    The name of the editor program.



132
133
134
# File 'lib/env/variables.rb', line 132

def editor
  env_hash['EDITOR']
end

#env_hashHash{String => String}

The environment variables.

Returns:

  • (Hash{String => String})

    The Hash of environment variable names and values.



11
12
13
# File 'lib/env/variables.rb', line 11

def env_hash
  ENV
end

#homePathname

The home directory.

Returns:

  • (Pathname)

    The path of the home directory.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/env/variables.rb', line 41

def home
  # logic adapted from Gem.find_home.
  path = if (env_hash['HOME'] || env_hash['USERPROFILE'])
           env_hash['HOME'] || env_hash['USERPROFILE']
         elsif (env_hash['HOMEDRIVE'] && env_hash['HOMEPATH'])
           "#{env_hash['HOMEDRIVE']}#{env_hash['HOMEPATH']}"
         else
           begin
             File.expand_path('~')
           rescue
             if File::ALT_SEPARATOR
               'C:/'
             else
               '/'
             end
           end
         end

  return Pathname.new(path)
end

#langArray<String, String>

The default language.

Returns:

  • (Array<String, String>)

    The language name and encoding.



68
69
70
71
72
73
74
# File 'lib/env/variables.rb', line 68

def lang
  if (lang = env_hash['LANG'])
    lang.split('.',2)
  else
    []
  end
end

#ld_library_pathsArray<Pathname>

The directories to search within for libraries.

Returns:

  • (Array<Pathname>)

    The paths of the directories.



31
32
33
# File 'lib/env/variables.rb', line 31

def ld_library_paths
  parse_paths(env_hash['LD_LIBRARY_PATH'])
end

#linesInteger

The number of lines in the terminal.

Returns:

  • (Integer)

    The number of lines.



92
93
94
# File 'lib/env/variables.rb', line 92

def lines
  env_hash['LINES'].to_i if env_hash['LINES']
end

#parse_paths(paths) ⇒ Array<Pathname> (protected)

Parses a String containing multiple paths.

Returns:

  • (Array<Pathname>)

    The multiple paths.



154
155
156
157
158
159
160
161
162
# File 'lib/env/variables.rb', line 154

def parse_paths(paths)
  if paths
    paths.split(File::PATH_SEPARATOR).map do |path|
      Pathname.new(path)
    end
  else
    []
  end
end

#pathsArray<Pathname>

The directories to search within for executables.

Returns:

  • (Array<Pathname>)

    The paths of the directories.



21
22
23
# File 'lib/env/variables.rb', line 21

def paths
  parse_paths(env_hash['PATH'])
end

#shellString?

The path of the default shell.

Returns:

  • (String, nil)

    The path to the default shell.



102
103
104
# File 'lib/env/variables.rb', line 102

def shell
  env_hash['SHELL']
end

#shell_nameString?

The name of the default shell.

Returns:

  • (String, nil)

    The program name of the shell.



112
113
114
# File 'lib/env/variables.rb', line 112

def shell_name
  File.basename(shell) if shell
end

#terminalString?

The default terminal to use.

Returns:

  • (String, nil)

    The name of the terminal program.



122
123
124
# File 'lib/env/variables.rb', line 122

def terminal
  env_hash['COLORTERM'] || env_hash['TERM']
end