Module: Lab42::Tmux::Command
Instance Method Summary
collapse
#tmux_current_window, #tmux_current_window_command, #tmux_current_window_designation, #tmux_current_window_number, #tmux_current_window_number=
Instance Method Details
#tmux_increase_current_window_number(by = 1) ⇒ Object
def tmux_execute_window_commands
( @tmux_window_precommands || [] ).each do | blk |
blk.()
end
end
20
21
22
|
# File 'lib/lab42/tmux/command.rb', line 20
def tmux_increase_current_window_number by=1
self.tmux_current_window_number += by
end
|
#tmux_new_session(params = nil) ⇒ Object
tmux new-session -s $session_name -n console -d
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/lab42/tmux/command.rb', line 25
def tmux_new_session params=nil
if session_exists?
system "tmux attach -t #{session_name}"
exit 0
end
suffix = params ? " #{params}" : ""
tmux "new-session -s #{session_name} -d#{suffix}"
unless @options.no_source_file || @options.tmux_source_file.nil?
tmux "source-file #{@options.tmux_source_file}"
end
tmux "set-window-option -g automatic-rename off"
unless @options.no_cd
tmux_project_home
end
end
|
#tmux_new_window(name = nil, dir = nil) ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/lab42/tmux/command.rb', line 41
def tmux_new_window name=nil, dir=nil
tmux_increase_current_window_number
suffix = name ? %{ -n "#{name}"} : nil
tmux "new-window -t #{@options.session_name}#{suffix}"
tmux_set_window_options "automatic-rename off", "allow-rename off"
tmux_project_home dir
tmux_execute_window_commands
end
|
#tmux_open_irb(options = {}) ⇒ Object
59
60
61
62
|
# File 'lib/lab42/tmux/command.rb', line 59
def tmux_open_irb options={}
lib = options.delete( :lib ){ "./lib" }
tmux_send_keys "irb -I#{lib}"
end
|
#tmux_open_vim(options = {}) ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/lab42/tmux/command.rb', line 50
def tmux_open_vim options={}
dir = options.delete( :dir ){ "." }
tmux_send_keys "vi #{dir}"
options.each do | cmd, params |
command = ":#{[cmd,params].compact.join(" ")}"
tmux_send_keys command
end
end
|
#tmux_prefixed_command(cmd, eol = true) ⇒ Object
64
65
66
|
# File 'lib/lab42/tmux/command.rb', line 64
def tmux_prefixed_command cmd, eol=true
tmux_send_keys [@options.cmd_prefix, cmd].mk_string, eol
end
|
#tmux_project_home(dir = project_home) ⇒ Object
68
69
70
71
|
# File 'lib/lab42/tmux/command.rb', line 68
def tmux_project_home dir=project_home
dir = File.join project_home, dir if dir && %r{\A[^/~]} === dir
tmux_send_keys "cd #{dir}"
end
|
#tmux_register_window_command(noexec = false, &blk) ⇒ Object
73
74
75
76
77
|
# File 'lib/lab42/tmux/command.rb', line 73
def tmux_register_window_command noexec=false, &blk
blk.() unless noexec
@tmux_window_precommands ||= []
@tmux_window_precommands << blk
end
|
#tmux_send_keys(keys, eol = true) ⇒ Object
79
80
81
82
|
# File 'lib/lab42/tmux/command.rb', line 79
def tmux_send_keys keys, eol=true
suffix = eol ? " C-m" : nil
tmux_current_window_command "send-keys", %{"#{keys}"}, suffix
end
|
#tmux_set_window_option(option) ⇒ Object
84
85
86
|
# File 'lib/lab42/tmux/command.rb', line 84
def tmux_set_window_option option
tmux_current_window_command "set-window-option", option
end
|
#tmux_set_window_options(*options) ⇒ Object
88
89
90
91
92
|
# File 'lib/lab42/tmux/command.rb', line 88
def tmux_set_window_options *options
options.each do | option |
tmux_set_window_option option
end
end
|