sesh 0.0.7 → 0.0.8

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/bin/sesh +38 -10
  3. data/lib/sesh/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50d0337c695c990ec335062762013468a25119a3
4
- data.tar.gz: 61b01a4d0b26b2800f823a18bdf92492610c6670
3
+ metadata.gz: d2b2b6726a4931f7ab2b379307da2ad4f8759a10
4
+ data.tar.gz: db3e61656ca079e4eab18dc29f0a1bb4caa31cca
5
5
  SHA512:
6
- metadata.gz: ad89b3a4554eafea4dfee6afb22f38ef431a0e1c5d489b2f7360e06790dddbf793ad3b6ab86e58fb55b1eca663503f2a585794d0ecdebeb639882494663e0f71
7
- data.tar.gz: 7bb6c2853b64a6986aaf713efca677fe188296f04d437c16235cc6022d9c0f4c00206f1f4e49c15ff1dd2333c5d482d72bc3c7de46722187bedb3306f9aa1cc9
6
+ metadata.gz: 0d9153dced581cae190f0849a1e14bec49fb26ef7dbd83f6a2d501f62ae106b901349a9b7d7038ff32deb9e86e66fa6e05e9d09c5356e2ca386725096cdb64e6
7
+ data.tar.gz: 1f0ef9b03d59840014684d59ae16cbba97e96afe4455b37034392903c321867c4d24432fad62a8314f5dc83ba12a7ee74183817b192ae8361ce4b4e85b641d78
data/bin/sesh CHANGED
@@ -10,8 +10,9 @@ Usage: #{File.basename $0} command [project]
10
10
  Commands:
11
11
 
12
12
  sesh new Create a new tmuxinator configuration.
13
- sesh start [project] Start a Sesh session for a project.
14
- sesh stop [project] Stop a Sesh session for a project.
13
+ sesh edit [project] Edit an existing tmuxinator configuration.
14
+ sesh start [project] Start a Sesh session for a project.
15
+ sesh stop [project] Stop a Sesh session for a project.
15
16
  sesh list List running Sesh sessions on this machine.
16
17
  sesh enslave [project] user@host Connect a slave to a local Sesh session.
17
18
  sesh connect [project] [user@host] Connect as a slave to a Sesh session.
@@ -53,7 +54,8 @@ end
53
54
  @project_name = get_project_name
54
55
 
55
56
 
56
- @socket = "/tmp/#{@project_name}.sock"
57
+ @socket_file = "/tmp/#{@project_name}.sock"
58
+ @pids_file = "/tmp/#{@project_name}.pids.txt"
57
59
 
58
60
  def get_remote_address
59
61
  @options[@options.length>1 ? 1:0] if @options.any?
@@ -65,6 +67,12 @@ def get_term_app
65
67
  output.length > 0 ? 'iTerm' : fatal("iTerm 2 is not installed.") # 'Terminal'
66
68
  end
67
69
 
70
+ def get_editor
71
+ editor = `echo $EDITOR`.strip
72
+ editor = 'vim' unless editor.length > 0
73
+ editor
74
+ end
75
+
68
76
  def project_name_matcher
69
77
  pn = @project_name.gsub '-', '\-'
70
78
  "[t]mux.*[#{pn[0]}]#{pn[1..-1]}"
@@ -79,7 +87,7 @@ def format_command(command) command.gsub(/\ [ ]+/, ' ').strip end
79
87
  def format_and_run_command(command) `#{format_command(command)}`.strip end
80
88
 
81
89
  def issue_server_start_command!
82
- `tmux -S "#{@socket}" new-session -d "env TMUX='' mux start #{@project_name}"`
90
+ `tmux -S "#{@socket_file}" new-session -d "env TMUX='' mux start #{@project_name}"`
83
91
  end
84
92
 
85
93
  def issue_server_stop_command!
@@ -88,7 +96,7 @@ end
88
96
 
89
97
  def connection_command(local=false, addr=nil)
90
98
  addr ||= @local_ssh_addr
91
- local_command = "tmux -S #{@socket} a"
99
+ local_command = "tmux -S #{@socket_file} a"
92
100
  return local_command if local
93
101
  "ssh #{addr} -t '#{local_command}'"
94
102
  end
@@ -127,18 +135,33 @@ def show_progress_until(condition_lambda, timeout=10)
127
135
  return condition_lambda.call
128
136
  end
129
137
 
138
+ def kill_running_processes
139
+ if File.exists? @pids_file
140
+ File.readlines(@pids_file).each{|pid| kill_process! pid }
141
+ File.delete @pids_file
142
+ end
143
+ end
144
+ def kill_process!(pid)
145
+ `kill -9 #{pid}`
146
+ end
147
+
130
148
  if @command
131
149
  case @command
132
150
  when 'start'
133
151
  fatal("Sesh project '#{@project_name}' is already running!") if already_running?
134
152
  debug "Starting Sesh project '#{@project_name}'..."
153
+ kill_running_processes
135
154
  output = issue_server_start_command!
136
155
  success = show_progress_until ->{ already_running? }
137
156
  if success
138
157
  sleep 1
139
158
  if $? && already_running?
159
+ pids = `tmux list-panes -s -F "\#{pane_pid} \#{pane_current_command}" | grep -v tmux | awk '{print $1}'`.strip.lines
160
+ File.open(@pids_file, 'w') {|f| pids.each{|pid| f.puts pid } }
140
161
  debug 'Sesh started successfully.'
141
162
  debug "To connect: #{connection_command}"
163
+ # TODO: show other sesh commands (connect, enslave), specify full
164
+ # command as what is needed for machines without sesh.
142
165
  puts
143
166
  else
144
167
  fatal 'Sesh failed to start!'
@@ -149,6 +172,7 @@ if @command
149
172
  when 'stop'
150
173
  fatal("Sesh project '#{@project_name}' is not running!") unless already_running?
151
174
  debug "Stopping Sesh project '#{@project_name}'..."
175
+ kill_running_processes
152
176
  output = issue_server_stop_command!
153
177
  success = show_progress_until ->{ !already_running? }
154
178
  if success && $?
@@ -172,12 +196,16 @@ if @command
172
196
  File.open(config, "w") { |f| f.write(erb) }
173
197
  end
174
198
 
175
- editor = `echo $EDITOR`.strip
176
- editor = 'vim' unless editor.length > 0
177
- Kernel.system("#{editor} #{config}") || Tmuxinator::Cli.new.doctor
178
- # command = "env EDITOR='vim' tmuxinator new #{@project_name}"
179
- # output = exec command
199
+ Kernel.system("#{get_editor} #{config}") || Tmuxinator::Cli.new.doctor
180
200
  puts
201
+ when 'edit'
202
+ config = Tmuxinator::Config.project(@project_name)
203
+ if Tmuxinator::Config.exists? @project_name
204
+ Kernel.system("#{get_editor} #{config}") || Tmuxinator::Cli.new.doctor
205
+ puts
206
+ else
207
+ fatal "Sesh project '#{@project_name}' does not exist yet!"
208
+ end
181
209
  when 'list'
182
210
  output = format_and_run_command <<-BASH
183
211
  ps aux | grep tmux | grep "env TMUX='' mux start" \
data/lib/sesh/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sesh
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sesh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - MacKinley Smith