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.



182
183
184
# File 'lib/env/variables.rb', line 182

def browser
  env['BROWSER']
end

#columnsInteger

The number of columns in the terminal.



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

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

#debug?Boolean

Determines whether optional Debugging was enabled.

Since:

  • 0.2.0



194
195
196
# File 'lib/env/variables.rb', line 194

def debug?
  true if env['DEBUG']
end

#editorString?

The default editor to use.



172
173
174
# File 'lib/env/variables.rb', line 172

def editor
  env['EDITOR']
end

#envHash{String => String}

The environment variables.



13
14
15
# File 'lib/env/variables.rb', line 13

def env
  ENV
end

#homePathname

The home directory.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/env/variables.rb', line 69

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

  return Pathname.new(path)
end

#host_nameString

The host-name of the system.

Since:

  • 0.3.0



45
46
47
# File 'lib/env/variables.rb', line 45

def host_name
  env['HOSTNAME']
end

#langArray<String, String>

The default language.



96
97
98
99
100
101
102
# File 'lib/env/variables.rb', line 96

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

#ld_library_pathsArray<Pathname>

The directories to search within for libraries.



33
34
35
# File 'lib/env/variables.rb', line 33

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

#linesInteger

The number of lines in the terminal.



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

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

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

Parses a String containing multiple paths.



206
207
208
209
210
211
212
213
214
# File 'lib/env/variables.rb', line 206

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.



23
24
25
# File 'lib/env/variables.rb', line 23

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

#shellString?

The path of the default shell.



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

def shell
  env['SHELL']
end

#shell_nameString?

The name of the default shell.



152
153
154
# File 'lib/env/variables.rb', line 152

def shell_name
  File.basename(shell) if shell
end

#terminalString?

The default terminal to use.



162
163
164
# File 'lib/env/variables.rb', line 162

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

#timezoneString?

The default timezone.

Since:

  • 0.2.0



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

def timezone
  env['TZ']
end

#userString

The name of the current user.

Since:

  • 0.3.0



57
58
59
60
61
# File 'lib/env/variables.rb', line 57

def user
  # USER is used on GNU/Linux and Windows
  # LOGNAME is the POSIX user-name ENV variable
  env['USER'] || env['LOGNAME']
end