27 lines
495 B
Ruby
Raw Normal View History

# frozen_string_literal: true
require "delegate"
require "etc"
require "system_command"
class User < DelegateClass(String)
def gui?
out, _, status = system_command "who"
return false unless status.success?
out.lines
.map(&:split)
.any? { |user, type,| user == self && type == "console" }
end
def self.current
2020-07-09 01:35:39 +05:30
return @current if defined?(@current)
pwuid = Etc.getpwuid(Process.euid)
return if pwuid.nil?
@current = new(pwuid.name)
end
end