rosh 0.9.4 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Makefile +6 -0
- data/README.md +1 -0
- data/lib/rosh/version.rb +1 -1
- data/lib/rosh.rb +32 -5
- data/test/rosh_forwarding_test.rb +22 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a9b04489aa21bdb87dd7a21a2696d33c0f1b29c45767593bca5bdc0b383b2a4
|
4
|
+
data.tar.gz: a43d640d729094bb85640cfece07ebe2f1b82bb007723d528b628fb5a495a23a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35972089d8384a358f3e79795fbf774be00e38b811872f690491057ccb17134488d3a19d21cdd2bc5854acab669033273689f2d99bc1fedbdb324d1eff31982c
|
7
|
+
data.tar.gz: 8a422f7936c8482d12b168ed6a5aab6dddda8691e98b327c206a676976f770ad3a02d4a0d19888eeb86188b0dea4431b370ed2e6989559758d99adaf2c696932
|
data/Makefile
ADDED
data/README.md
CHANGED
@@ -26,6 +26,7 @@ Or install it yourself as:
|
|
26
26
|
Default: "^t"
|
27
27
|
-I interval Reconnection interval.
|
28
28
|
-S Use GNU screen instead of tmux
|
29
|
+
-L socket-name Specify tmux socket name (tmux -L socket-name)
|
29
30
|
|
30
31
|
If ~/.ssh/config contains LocalForward or RemoteForward for the host, the same
|
31
32
|
forwarding options are passed to `ssh` automatically.
|
data/lib/rosh/version.rb
CHANGED
data/lib/rosh.rb
CHANGED
@@ -11,6 +11,7 @@ class Rosh
|
|
11
11
|
@ssh_opts = []
|
12
12
|
alive_interval = 5
|
13
13
|
@escape = '^t'
|
14
|
+
@tmux_socket_name = nil
|
14
15
|
OptionParser.new("test").tap do |opt|
|
15
16
|
opt.banner = 'Usage: rosh [options] hostname [session-name]'
|
16
17
|
opt.on('-a alive-interval'){|v| alive_interval = v.to_i}
|
@@ -18,6 +19,7 @@ class Rosh
|
|
18
19
|
opt.on('-I interval'){|v| @interval = v.to_f}
|
19
20
|
opt.on('-V'){|v| @verbose = true}
|
20
21
|
opt.on('-S'){|v| @screen = true}
|
22
|
+
opt.on('-L socket-name'){|v| @tmux_socket_name = v}
|
21
23
|
end.parse! args
|
22
24
|
@host, @name = *args, :default
|
23
25
|
abort 'hostname is required' if @host == :default
|
@@ -62,8 +64,9 @@ class Rosh
|
|
62
64
|
["ssh", *@ssh_opts, resolv,
|
63
65
|
'-t', "'screen -rx #{@name}'", '2>/dev/null']*' '
|
64
66
|
else
|
67
|
+
remote_cmd = single_quote(tmux_attach_command)
|
65
68
|
["ssh", *@ssh_opts, resolv,
|
66
|
-
'-t',
|
69
|
+
'-t', remote_cmd, '2>/dev/null']*' '
|
67
70
|
end
|
68
71
|
if @verbose
|
69
72
|
puts "connecting to #{@host}..."
|
@@ -227,24 +230,25 @@ private
|
|
227
230
|
|
228
231
|
def sh_has_session?
|
229
232
|
# tmux has-session -t <session_name>
|
230
|
-
ssh_tmux("
|
233
|
+
ssh_tmux("#{tmux_prefix} has-session -t #{tmux_session_name} 2>/dev/null")
|
231
234
|
end
|
232
235
|
|
233
236
|
def sh_new_session?
|
234
237
|
# tmux new-session -s <session_name> -d
|
235
|
-
create_with_override = "
|
238
|
+
create_with_override = "#{tmux_prefix} new-session -s #{tmux_session_name} -d \\; set-option -t #{tmux_session_name} destroy-unattached off"
|
236
239
|
return true if ssh_tmux(create_with_override)
|
237
240
|
|
238
241
|
puts "retrying tmux new-session without destroy-unattached override" if @verbose
|
239
|
-
ssh_tmux("
|
242
|
+
ssh_tmux("#{tmux_prefix} new-session -s #{tmux_session_name} -d")
|
240
243
|
end
|
241
244
|
|
242
245
|
def ssh_tmux(command)
|
246
|
+
remote_command = single_quote(command.to_s)
|
243
247
|
cmd = [
|
244
248
|
"ssh",
|
245
249
|
*@ssh_opts,
|
246
250
|
resolv,
|
247
|
-
|
251
|
+
remote_command
|
248
252
|
]*' '
|
249
253
|
puts cmd if @verbose
|
250
254
|
system cmd
|
@@ -293,4 +297,27 @@ private
|
|
293
297
|
rescue Exception
|
294
298
|
@host
|
295
299
|
end
|
300
|
+
|
301
|
+
def tmux_attach_command
|
302
|
+
"#{tmux_prefix} attach -t #{tmux_session_name}"
|
303
|
+
end
|
304
|
+
|
305
|
+
def tmux_prefix
|
306
|
+
return 'tmux' unless @tmux_socket_name
|
307
|
+
"tmux -L #{format_remote_arg(@tmux_socket_name)}"
|
308
|
+
end
|
309
|
+
|
310
|
+
def tmux_session_name
|
311
|
+
format_remote_arg(@name)
|
312
|
+
end
|
313
|
+
|
314
|
+
def format_remote_arg(value)
|
315
|
+
str = value.to_s
|
316
|
+
return str if str.match?(%r{\A[[:alnum:]@%+=:,./_-]+\z})
|
317
|
+
%("#{str.gsub(/(["\\$`])/, '\\\\\1')}")
|
318
|
+
end
|
319
|
+
|
320
|
+
def single_quote(str)
|
321
|
+
"'" + str.to_s.gsub("'", %q('\'') ) + "'"
|
322
|
+
end
|
296
323
|
end
|
@@ -118,4 +118,26 @@ class RoshForwardingTest < Minitest::Test
|
|
118
118
|
assert_includes commands.first, 'set-option -t grav destroy-unattached off'
|
119
119
|
refute_includes commands.last, 'set-option -t grav destroy-unattached off'
|
120
120
|
end
|
121
|
+
|
122
|
+
def test_tmux_commands_include_socket_name_when_specified
|
123
|
+
socket_name = 'work'
|
124
|
+
rosh = Rosh.new('-L', socket_name, 'grav')
|
125
|
+
rosh.instance_variable_set(:@name, 'grav')
|
126
|
+
|
127
|
+
assert_includes rosh.send(:tmux_attach_command), "-L #{socket_name}"
|
128
|
+
|
129
|
+
commands = []
|
130
|
+
rosh.stub(:system, ->(cmd) { commands << cmd; true }) do
|
131
|
+
rosh.send(:sh_has_session?)
|
132
|
+
end
|
133
|
+
|
134
|
+
assert_includes commands.first, "-L #{socket_name}"
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_tmux_default_socket_used_when_not_specified
|
138
|
+
rosh = Rosh.new('grav')
|
139
|
+
command = rosh.send(:tmux_attach_command)
|
140
|
+
|
141
|
+
refute_includes command, '-L'
|
142
|
+
end
|
121
143
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rosh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Takiuchi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-10-
|
11
|
+
date: 2025-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- ".gitignore"
|
80
80
|
- Gemfile
|
81
81
|
- LICENSE.txt
|
82
|
+
- Makefile
|
82
83
|
- README.md
|
83
84
|
- Rakefile
|
84
85
|
- bin/rosh
|