Class: User Private

Inherits:
String show all
Defined in:
Library/Homebrew/utils/user.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A system user.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from String

#f, #undent

Class Method Details

.currentObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the current user.


23
24
25
26
27
28
29
30
# File 'Library/Homebrew/utils/user.rb', line 23

def self.current
  return @current if defined?(@current)

  pwuid = Etc.getpwuid(Process.euid)
  return if pwuid.nil?

  @current = new(pwuid.name)
end

Instance Method Details

#gui?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return whether the user has an active GUI session.

Returns:

  • (Boolean)

13
14
15
16
17
18
19
20
# File 'Library/Homebrew/utils/user.rb', line 13

def gui?
  out, _, status = system_command "who"
  return false unless status.success?

  out.lines
     .map(&:split)
     .any? { |user, type,| user == self && type == "console" }
end