2018-10-01 12:29:21 +02:00
|
|
|
require "delegate"
|
|
|
|
require "etc"
|
|
|
|
|
|
|
|
require "system_command"
|
|
|
|
|
|
|
|
class User < DelegateClass(String)
|
|
|
|
def gui?
|
|
|
|
out, _, status = system_command "who"
|
|
|
|
return false unless status.success?
|
2019-02-19 13:12:52 +00:00
|
|
|
|
2018-10-01 12:29:21 +02:00
|
|
|
out.lines
|
|
|
|
.map(&:split)
|
|
|
|
.any? { |user, type,| user == self && type == "console" }
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.current
|
|
|
|
@current ||= new(Etc.getpwuid(Process.euid).name)
|
|
|
|
end
|
|
|
|
end
|