sesh 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/sesh +52 -35
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17fc8871ceac325d5a9344163c1dbac6bfad4d0a
|
4
|
+
data.tar.gz: 7ae48a72c52d78d6b511e50a4c76878951c7786e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0514a6354033fe60c716a24e094a0e6bf464ba74628d03c089ce7915dce42c7b5bf0f1eab5838312b6b16a7b3105abefc719a25833ce4bc65645fd14a1d43081
|
7
|
+
data.tar.gz: 1c72f43d3b349a374d48a0fe640e9a4a6a45499ccb2ae9b86c481aec4cb041ce4e37c90687f2f3ee4b10ae4bad913214856f40fc6e3c96768ac1eae985e23524
|
data/bin/sesh
CHANGED
@@ -1,20 +1,22 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
if ARGV.include? '-h' or ARGV.include? '--help' then puts <<-HELP
|
3
|
+
if ARGV.empty? or ARGV.include? '-h' or ARGV.include? '--help' then puts <<-HELP
|
4
4
|
Sesh: remote background sessions powered by tmux and tmuxinator.
|
5
5
|
Runs a headless tmuxinator session for remote slave machines to connect to.
|
6
6
|
|
7
|
-
Usage: #{File.basename $0}
|
7
|
+
Usage: #{File.basename $0} command [project]
|
8
8
|
|
9
9
|
Commands:
|
10
10
|
|
11
11
|
sesh new Create a new tmuxinator configuration.
|
12
|
-
sesh start [
|
13
|
-
sesh stop [
|
12
|
+
sesh start [project] Start a Sesh session for a project.
|
13
|
+
sesh stop [project] Stop a Sesh session for a project.
|
14
14
|
sesh list List running Sesh sessions on this machine.
|
15
15
|
sesh connect [project] user@host Connect as a slave to a remote Sesh session.
|
16
16
|
sesh enslave [project] user@host Connect a slave to a local Sesh session.
|
17
17
|
|
18
|
+
Leave project blank to use the name of your current directory.
|
19
|
+
|
18
20
|
HELP
|
19
21
|
exit; end
|
20
22
|
|
@@ -26,19 +28,19 @@ def debug(msg) $stderr.puts "> #{msg}" end
|
|
26
28
|
@options = ARGV[1..-1] || []
|
27
29
|
# debug("Options received: #{@options}") if @options.any?
|
28
30
|
|
31
|
+
def is_tmuxinator_project?(name)
|
32
|
+
path = File.expand_path("~/.tmuxinator/#{name}.yml")
|
33
|
+
File.exist? path
|
34
|
+
end
|
35
|
+
|
29
36
|
def get_project_name
|
30
|
-
if @options.any?
|
31
|
-
|
32
|
-
@options.shift if @options[1]
|
33
|
-
else
|
34
|
-
@options[0]
|
35
|
-
end
|
36
|
-
if pn_opt
|
37
|
-
pn_opt_path = File.expand_path("~/.tmuxinator/#{pn_opt}.yml")
|
38
|
-
return pn_opt if File.exist? pn_opt_path
|
39
|
-
end
|
37
|
+
if @options.any? && !@options[0].include?('@')
|
38
|
+
return @options.shift if is_tmuxinator_project? @options[0]
|
40
39
|
end
|
41
|
-
`printf '%q\n' "${PWD##*/}"`.strip
|
40
|
+
output = `printf '%q\n' "${PWD##*/}"`.strip
|
41
|
+
return output if is_tmuxinator_project?(output)
|
42
|
+
puts "Sesh project '#{output}' could not be found."
|
43
|
+
fatal "Hint: run sesh new or specify an existing project after your commmand."
|
42
44
|
end
|
43
45
|
@project_name = get_project_name
|
44
46
|
|
@@ -52,6 +54,16 @@ end
|
|
52
54
|
|
53
55
|
@socket = "/tmp/#{@project_name}.sock"
|
54
56
|
|
57
|
+
def get_remote_address
|
58
|
+
@options[@options.length>1 ? 1:0] if @options.any?
|
59
|
+
end
|
60
|
+
@remote_address = get_remote_address
|
61
|
+
|
62
|
+
def get_term_app
|
63
|
+
output = `osascript -e 'try' -e 'get exists application "iTerm"' -e 'end try'`.strip
|
64
|
+
output.length > 0 ? 'iTerm' : fatal("iTerm 2 is not installed.") # 'Terminal'
|
65
|
+
end
|
66
|
+
|
55
67
|
def project_name_matcher
|
56
68
|
pn = @project_name.gsub '-', '\-'
|
57
69
|
"[t]mux.*[#{pn[0]}]#{pn[1..-1]}"
|
@@ -66,7 +78,7 @@ def format_command(command) command.gsub(/\ [ ]+/, ' ').strip end
|
|
66
78
|
def format_and_run_command(command) `#{format_command(command)}`.strip end
|
67
79
|
|
68
80
|
def issue_server_start_command!
|
69
|
-
`tmux -
|
81
|
+
`tmux -S "#{@socket}" new-session -d "env TMUX='' mux start #{@project_name}"`
|
70
82
|
end
|
71
83
|
|
72
84
|
def issue_server_stop_command!
|
@@ -80,17 +92,24 @@ def connection_command(local=false)
|
|
80
92
|
end
|
81
93
|
|
82
94
|
def enter_slave_mode_command(local=false)
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
95
|
+
@term_app ||= get_term_app
|
96
|
+
case @term_app
|
97
|
+
when 'iTerm'
|
98
|
+
tell_term_app = 'tell application "' + @term_app + '"'
|
99
|
+
tell_term_process = 'tell application "System Events" to tell process "' +
|
100
|
+
@term_app + '"'
|
101
|
+
format_command <<-BASH
|
102
|
+
osascript \
|
103
|
+
-e '#{tell_term_app} to activate' \
|
104
|
+
-e '#{tell_term_process} to keystroke \"n\" using command down' \
|
105
|
+
-e 'delay 1' \
|
106
|
+
-e "#{tell_term_app.gsub('"', '\\"')} to tell session -1 of current \
|
107
|
+
terminal to write text \\"#{connection_command(local)}\\"" \
|
108
|
+
-e '#{tell_term_process} to keystroke return using command down'
|
109
|
+
BASH
|
110
|
+
when 'Terminal'
|
111
|
+
format_command connection_command(local)
|
112
|
+
end
|
94
113
|
end
|
95
114
|
|
96
115
|
def show_progress_until(condition_lambda, timeout=10)
|
@@ -160,21 +179,19 @@ if @command
|
|
160
179
|
fatal "There are no Sesh projects currently running."
|
161
180
|
end
|
162
181
|
when 'connect'
|
163
|
-
|
164
|
-
|
165
|
-
slave_address = @local_ssh_addr
|
182
|
+
if (is_local=@remote_address.nil?)
|
183
|
+
@remote_address = @local_ssh_addr
|
166
184
|
fatal("Sesh project '#{@project_name}' is not running!") unless already_running?
|
167
185
|
end
|
168
186
|
command = enter_slave_mode_command(is_local)
|
169
|
-
puts command
|
170
187
|
puts `#{command}`.strip
|
171
188
|
when 'enslave'
|
172
189
|
fatal("Sesh project '#{@project_name}' is not running!") unless already_running?
|
173
|
-
fatal("You must specify a machine to enslave! Eg: user@ip")
|
174
|
-
|
175
|
-
|
190
|
+
fatal("You must specify a machine to enslave! Eg: user@ip") if @remote_address.nil?
|
191
|
+
debug "Attempting to connect #{@remote_address} to Sesh project '#{@project_name}'..."
|
192
|
+
# ssh #{@remote_address} "#{enter_slave_mode_command.gsub(/([^\\])"/, '\1\\"')}"
|
176
193
|
output = format_and_run_command <<-BASH
|
177
|
-
|
194
|
+
#{enter_slave_mode_command} | ssh -T #{@remote_address} 1>/dev/null 2>&1 &
|
178
195
|
BASH
|
179
196
|
puts output
|
180
197
|
if $?
|