From fbed36ad0e813d71a3f2751e50c8bfd057f15598 Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Thu, 1 Jun 2017 17:18:39 +0200 Subject: [PATCH] Allow using '$HOSTNAME' in @resurrect-dir Closes #197 --- CHANGELOG.md | 1 + docs/save_dir.md | 9 +++++++++ scripts/helpers.sh | 5 ++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 782c473..4c259d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - added guide for migrating from tmuxinator - fixed a bug for restoring commands on tmux 2.5 (and probably tmux 2.4) - do not create another resurrect file if there are no changes (credit @vburdo) +- allow using '$HOSTNAME' in @resurrect-dir ### v2.4.0, 2015-02-23 - add "tmux-test" diff --git a/docs/save_dir.md b/docs/save_dir.md index dc79b4e..bf724c6 100644 --- a/docs/save_dir.md +++ b/docs/save_dir.md @@ -4,3 +4,12 @@ By default Tmux environment is saved to a file in `~/.tmux/resurrect` dir. Change this with: set -g @resurrect-dir '/some/path' + +Using environment variables or shell interpolation in this option is not +allowed as the string is used literally. So the following won't do what is +expected: + + set -g @resurrect-dir '/path/$MY_VAR/$(some_executable)' + +Only the following variables and special chars are allowed: +`$HOME`, `$HOSTNAME`, and `~`. diff --git a/scripts/helpers.sh b/scripts/helpers.sh index a4caafc..555b779 100644 --- a/scripts/helpers.sh +++ b/scripts/helpers.sh @@ -98,11 +98,13 @@ pane_content_files_restore_from_archive() { resurrect_dir() { if [ -z "$_RESURRECT_DIR" ]; then local path="$(get_tmux_option "$resurrect_dir_option" "$default_resurrect_dir")" - echo "${path/#\~/$HOME}" # expands tilde if used with @resurrect-dir + # expands tilde, $HOME and $HOSTNAME if used in @resurrect-dir + echo "$path" | sed "s,\$HOME,$HOME,g; s,\$HOSTNAME,$(hostname),g; s,\~,$HOME,g" else echo "$_RESURRECT_DIR" fi } +_RESURRECT_DIR="$(resurrect_dir)" resurrect_file_path() { if [ -z "$_RESURRECT_FILE_PATH" ]; then @@ -112,6 +114,7 @@ resurrect_file_path() { echo "$_RESURRECT_FILE_PATH" fi } +_RESURRECT_FILE_PATH="$(resurrect_file_path)" last_resurrect_file() { echo "$(resurrect_dir)/last"