Module: UserShell

Defined in:
lib/usershell.rb,
lib/usershell/version.rb,
lib/usershell/user_not_found_error.rb

Defined Under Namespace

Classes: UserNotFoundError

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.path(user = nil) ⇒ Object

Get the shell path for the specified user, defaults to current user

Parameters:

  • user (String) (defaults to: nil)

    optional The target user

Raises:



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/usershell.rb', line 9

def self.path(user=nil)
  user ||='`whoami`'
  user_id = %x(id -u #{user}).to_i
  raise UserNotFoundError.new('User not found.') unless user_id > 0

  if RbConfig::CONFIG['host_os'] =~ /darwin|mac os/
    shell = %x(dscl . -read /Users/#{user} UserShell)
    shell.split(/\s/).last
  else
    shell = %x(getent passwd #{user})
    shell.split(':').last.strip
  end
end