From 5c2853a55f4f60cdf8502521b692e781b9db0960 Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Tue, 26 Aug 2014 15:40:50 +0200 Subject: [PATCH] Sessions directory is configurable Close #10 --- CHANGELOG.md | 1 + scripts/helpers.sh | 13 +++++++++---- scripts/session_saver.sh | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 613bd22..31e9eb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### master - saving a new session does not remove the previous one +- make the directory where sessions are stored configurable ### v0.0.1, 2014-08-26 - started a project diff --git a/scripts/helpers.sh b/scripts/helpers.sh index 0b5f1f2..9875a3f 100644 --- a/scripts/helpers.sh +++ b/scripts/helpers.sh @@ -1,5 +1,6 @@ -# constants -SESSIONS_DIR="$HOME/.tmux/sessions" +# configurable constants +default_sessions_dir="$HOME/.tmux/sessions" +sessions_dir_option="@sessions-dir" # helper functions get_tmux_option() { @@ -38,11 +39,15 @@ display_message() { tmux set-option -gq display-time "$saved_display_time" } +sessions_dir() { + echo $(get_tmux_option "$sessions_dir_option" "$default_sessions_dir") +} + session_path() { local timestamp="$(date +"%Y-%m-%dT%H:%M:%S")" - echo "${SESSIONS_DIR}/tmux_session_${timestamp}.txt" + echo "$(sessions_dir)/tmux_session_${timestamp}.txt" } last_session_path() { - echo "${SESSIONS_DIR}/last" + echo "$(sessions_dir)/last" } diff --git a/scripts/session_saver.sh b/scripts/session_saver.sh index 9275599..0a6c299 100755 --- a/scripts/session_saver.sh +++ b/scripts/session_saver.sh @@ -23,7 +23,7 @@ dump() { save_all_sessions() { local session_path="$(session_path)" - mkdir -p "$SESSIONS_DIR" + mkdir -p "$(sessions_dir)" dump > $session_path ln -fs "$session_path" "$(last_session_path)" display_message "Saved all Tmux sessions!"