rosh 0.8.0 → 0.9.0

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rosh/version.rb +1 -1
  3. data/lib/rosh.rb +47 -6
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b2fab6f41d5905467f31451ef95acb39c7eb8fe20c7f73d7a1738db8a8a7e87
4
- data.tar.gz: cc245fe892759cf80f32f3c3350ce20311e1323f77f69bcf8bb9ccc900246602
3
+ metadata.gz: f64f95564122ea852fb93ffc481aac5a7977aca6c6858f716e3495f17ae07fc5
4
+ data.tar.gz: c364da8eeea9ec17bf927ecca79eda010393043c5580d4259929f7eded253a8d
5
5
  SHA512:
6
- metadata.gz: e6b64bd51c565a4656c6d4592fb5ba77ef873e3046baf01927836cc5077695b81ba0f5823d3a8c32d3ef7814eefba44f37baafbc7ad7bb9cbfe40f7f37cda6ce
7
- data.tar.gz: 44a80483ac889fce806662c003797b5ca785b84ea28fda96d0a00994a43d81f453f05426a70a718bdfdfce28a809bec8e8e7bcb90c928fb36eee29276a0d6161
6
+ metadata.gz: 5eb516a7aecaa2d2baed09ca47941da6b6ba25530ba3b8b7eee3c04db2d5633164c038c913b1b0d326be9e2f8a91f9360acdaaa08f4d75a86b2267f170128f83
7
+ data.tar.gz: d565efa2e2a73328570f810270018935056c21328b75130e9f636b8ad1715bf1a35ee10a966493814540cf3aaacaffe2b6532ab6a39c4029aa7ebde9c2c8abb6
data/lib/rosh/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Rosh
2
- VERSION = '0.8.0'
2
+ VERSION = '0.9.0'
3
3
  end
data/lib/rosh.rb CHANGED
@@ -16,6 +16,7 @@ class Rosh
16
16
  opt.on('-e escape'){|v| @escape = v}
17
17
  opt.on('-I interval'){|v| @interval = v.to_f}
18
18
  opt.on('-V'){|v| @verbose = true}
19
+ opt.on('-S'){|v| @screen = true}
19
20
  end.parse! args
20
21
  @host, @name = *args, :default
21
22
  abort 'hostname is required' if @host == :default
@@ -45,8 +46,13 @@ class Rosh
45
46
  end
46
47
 
47
48
  def connect
48
- cmd = ["ssh", *@ssh_opts, resolv,
49
- '-t', "'screen -rx #{@name}'", '2>/dev/null']*' '
49
+ cmd = if @screen
50
+ ["ssh", *@ssh_opts, resolv,
51
+ '-t', "'screen -rx #{@name}'", '2>/dev/null']*' '
52
+ else
53
+ ["ssh", *@ssh_opts, resolv,
54
+ '-t', "'tmux attach -t #{@name}'", '2>/dev/null']*' '
55
+ end
50
56
  if @verbose
51
57
  puts "connecting to #{@host}..."
52
58
  puts cmd
@@ -56,10 +62,21 @@ class Rosh
56
62
 
57
63
  def reconnect
58
64
  if @first_try
59
- if !sh('-p 0 -X echo ok', '2>&1 >/dev/null')
60
- print "creating new screen session #{@name}... "
61
- if sh %{-c /dev/null -e "#{@escape*2}" -dm} and
62
- sh '-p 0 -X eval "stuff STY=\\040screen\\015"'
65
+ session_exists = if @screen
66
+ sh('-p 0 -X echo ok', '2>&1 >/dev/null')
67
+ else
68
+ sh_has_session?
69
+ end
70
+ unless session_exists
71
+ type = @screen ? 'screen' : 'tmux'
72
+ print "creating new #{type} session #{@name}..."
73
+ new_session = if @screen
74
+ sh %{-c /dev/null -e "#{@escape*2}" -dm} and
75
+ sh '-p 0 -X eval "stuff STY=\\040screen\\015"'
76
+ else
77
+ sh_new_session?
78
+ end
79
+ if new_session
63
80
  puts "done."
64
81
  else
65
82
  puts "failed."
@@ -82,6 +99,30 @@ private
82
99
  system cmd
83
100
  end
84
101
 
102
+ def sh_has_session?
103
+ # tmux has-session -t <session_name>
104
+ cmd = [
105
+ "ssh",
106
+ *@ssh_opts,
107
+ resolv,
108
+ "'tmux has-session -t #{@name} 2>/dev/null'"
109
+ ]*' '
110
+ puts cmd if @verbose
111
+ system cmd
112
+ end
113
+
114
+ def sh_new_session?
115
+ # tmux new-session -s <session_name> -d
116
+ cmd = [
117
+ "ssh",
118
+ *@ssh_opts,
119
+ resolv,
120
+ "'tmux new-session -s #{@name} -d'"
121
+ ]*' '
122
+ puts cmd if @verbose
123
+ system cmd
124
+ end
125
+
85
126
  def resolv
86
127
  uri = URI("//#{@host}")
87
128
  uri.host = Resolv::DNS.new.getaddress(uri.host).to_s
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.8.0
4
+ version: 0.9.0
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-03-13 00:00:00.000000000 Z
11
+ date: 2025-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh