Class: Termup::Process
- Inherits:
-
Object
- Object
- Termup::Process
- Defined in:
- lib/termup/process.rb
Instance Attribute Summary collapse
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
- #app_name ⇒ Object
-
#initialize ⇒ Process
constructor
A new instance of Process.
- #iterm? ⇒ Boolean
- #lookup_pid ⇒ Object
- #term_like_pids ⇒ Object
- #terminal? ⇒ Boolean
Constructor Details
#initialize ⇒ Process
Returns a new instance of Process.
5 6 7 |
# File 'lib/termup/process.rb', line 5 def initialize lookup_pid end |
Instance Attribute Details
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
3 4 5 |
# File 'lib/termup/process.rb', line 3 def pid @pid end |
Instance Method Details
#app_name ⇒ Object
17 18 19 |
# File 'lib/termup/process.rb', line 17 def app_name @app_name ||= ExecJS.eval "Application(#{@pid}).name()" end |
#iterm? ⇒ Boolean
13 14 15 |
# File 'lib/termup/process.rb', line 13 def iterm? app_name == 'iTerm' end |
#lookup_pid ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/termup/process.rb', line 21 def lookup_pid pid = ::Process.ppid pids = [] # Go up the process tree to find term-like process while pid > 1 do pids << pid if term_like_pids.include?(pid) pid = `ps -p #{pid} -o ppid=`.strip.to_i end abort 'terminal pid not found!' if pids.empty? @pid = pids.last end |
#term_like_pids ⇒ Object
36 37 38 |
# File 'lib/termup/process.rb', line 36 def term_like_pids @term_like_pids ||= `ps x | grep Term`.split("\n").reject{|i| i =~ /grep/ }.map{|i| i.match(/\d+/).to_s.to_i } end |
#terminal? ⇒ Boolean
9 10 11 |
# File 'lib/termup/process.rb', line 9 def terminal? app_name == 'Terminal' end |