geebee / tmux-persistence Goto Github PK
View Code? Open in Web Editor NEWReboot surviving tmux session persistence via standardized shell scripts representing each session
Reboot surviving tmux session persistence via standardized shell scripts representing each session
I don't have the time right now to submit a pull request because this probably no longer works in linux so I would need to add some OS detection and switches. Here is a version that runs in OSX 10.9.2 with ruby 1.9.2-p180.
Issues resolved:
Dir
in one place to FileUtils
..sessions
to .tmux-sessions
because it was too generic.tmux
version has slightly different argument names for its commands.
list-sessions
command fixedlist-panes
command fixedps
command in OSX has different arguments, the current ones caused error.#!/usr/bin/env ruby
require 'fileutils.rb'
# Start - Configuration Variables
sessionDir = ENV['HOME']+"/.tmux-sessions"
maxStoredSessions = 5
filesToRoll = 3
# End - Configuration Variables
FileUtils::makedirs(sessionDir) unless File.exists?(sessionDir)
files = []
Dir.entries(sessionDir).each do |e|
if e !~ /^\./
files << e
end
end
files.sort! unless files.length == 0
if files.length > maxStoredSessions
0.upto(filesToRoll - 1) do |index|
File.delete( sessionDir+ "/" + files[index] )
end
puts "Rotated stored sessions"
end
#%x[rm #{sessionDir}/*-restore]
sessions = %x[tmux list-sessions -F "\#{session_name}"].split("\n")
sessions.each do |sessionName|
rawPaneList = %x[tmux list-panes -t #{sessionName} -s -F "\#{window_index} \#{pane_index} \#{window_width} \#{window_height} \#{pane_width} \#{pane_height} \#{window_name} \#{pane_current_path} \#{pane_pid}"].split("\n")
panes = []
rawPaneList.each do |pane_line|
temp_pane = pane_line.split(" ")
panes.push({
windowIndex: Integer(temp_pane[0]),
paneIndex: Integer(temp_pane[1]),
windowWidth: Integer(temp_pane[2]),
windowHeight: Integer(temp_pane[3]),
paneWidth: Integer(temp_pane[4]),
paneHeight: Integer(temp_pane[5]),
window_name: temp_pane[6],
cwd: temp_pane[7],
pid: temp_pane[8]
})
end
sessionScript = ""
panes.each do |pane|
pane[:cmd] = %x[ps -o command -p #{pane[:pid]} | awk 'NR>1'].delete("\n")
pane[:cmd] = %x[ps -o command #{pane[:pid]} | awk 'NR>1'].delete("\n").gsub(/^-/,"") unless pane[:cmd] != ""
sessionScript += "tmux new-window -t $SESSION -a -n #{pane[:window_name]} \"cd #{pane[:cwd]} && #{pane[:cmd]}\"\n"
if pane[:paneIndex] > 0
if pane[:paneWidth] < pane[:windowWidth]
sessionScript += "tmux join-pane -h -l #{pane[:paneWidth]} -s $SESSION:#{pane[:windowIndex] +1}.0 -t $SESSION:#{pane[:windowIndex]}\n"
else
sessionScript += "tmux join-pane -v -l #{pane[:paneHeight]} -s $SESSION:#{pane[:windowIndex] +1}.0 -t $SESSION:#{pane[:windowIndex]}\n"
end
end
end
restore_file = sessionDir + "/" + sessionName + "-restore"
File.open(restore_file, "w") {
|f| f.write(%Q[#!/usr/bin/env bash
SESSION=#{sessionName}
if [ -z $TMUX ]; then
# if session already exists, attach
tmux has-session -t $SESSION
if [ $? -eq 0 ]; then
echo \"Session $SESSION already exists. Attaching...\"
tmux attach -t $SESSION
exit 0;
fi
# make new session
tmux new-session -d -s $SESSION
#{sessionScript}
# attach to new session
tmux select-window -t $SESSION:1
tmux attach-session -t $SESSION
fi
])
# make script executable
f.chmod( 0744 )
}
end
Hi, I just found about this project.
I made a plugin that does the same thing and would be interested to hear what you think of it: https://github.com/tmux-plugins/tmux-resurrect
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.