Class: Barabara::Modules::WindowName

Inherits:
Object
  • Object
show all
Includes:
Wisper::Publisher
Defined in:
lib/barabara/modules/wname.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWindowName

Returns a new instance of WindowName.



7
8
9
# File 'lib/barabara/modules/wname.rb', line 7

def initialize
  @cmd = 'xtitle -sf "%s\n"'
end

Class Method Details

.limit(line) ⇒ Object



11
12
13
# File 'lib/barabara/modules/wname.rb', line 11

def self.limit(line)
  line.length > 80 ? line[0..60].gsub(/\s\w+\s*$/, '') : line
end

Instance Method Details

#watchObject



15
16
17
18
19
20
21
22
23
# File 'lib/barabara/modules/wname.rb', line 15

def watch
  PTY.spawn(@cmd) do |stdout, _stdin, pid|
    stdout.each do |line|
      title = WindowName.limit(line.chomp)
      publish(:event, 'window_title', title)
    end
    Process.wait pid
  end
end