Saving a session does not override the previous one

Close #7
This commit is contained in:
Bruno Sutic 2014-08-26 15:31:47 +02:00
parent 1280e659d5
commit 70d78e8d73
No known key found for this signature in database
GPG Key ID: 66D96E4F2F7EF26C
4 changed files with 19 additions and 3 deletions

View File

@ -1,6 +1,7 @@
# Changelog
### master
- saving a new session does not remove the previous one
### v0.0.1, 2014-08-26
- started a project

View File

@ -1,3 +1,7 @@
# constants
SESSIONS_DIR="$HOME/.tmux/sessions"
# helper functions
get_tmux_option() {
local option="$1"
local default_value="$2"
@ -33,3 +37,12 @@ display_message() {
# restores original 'display-time' value
tmux set-option -gq display-time "$saved_display_time"
}
session_path() {
local timestamp="$(date +"%Y-%m-%dT%H:%M:%S")"
echo "${SESSIONS_DIR}/tmux_session_${timestamp}.txt"
}
last_session_path() {
echo "${SESSIONS_DIR}/last"
}

View File

@ -70,7 +70,7 @@ restore_pane() {
restore_all_sessions() {
while read line; do
restore_pane "$line"
done < $HOME/.tmux/session
done < $(last_session_path)
display_message "Restored all Tmux sessions!"
}

View File

@ -22,8 +22,10 @@ dump() {
}
save_all_sessions() {
mkdir -p $HOME/.tmux
dump > $HOME/.tmux/session
local session_path="$(session_path)"
mkdir -p "$SESSIONS_DIR"
dump > $session_path
ln -fs "$session_path" "$(last_session_path)"
display_message "Saved all Tmux sessions!"
}