diff --git a/CHANGELOG.md b/CHANGELOG.md index 0847f38..bc9a353 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ - fix: split `local` declarations from command substitution assignments to preserve tmux exit codes - fix: suppress expected "key not found" errors from unbind calls on fresh plugin load - fix: broken shebang in test_default_options.sh (was missing `!` and indented); quote `$CURRENT_DIR` in source +- refactor: toggle_on.sh and toggle_off.sh now source variables.sh and use named + variables for all option keys rather than hardcoded strings, so renames stay in sync ### v0.1.0, 2018-05-20 - initial work on the plugin diff --git a/scripts/toggle_off.sh b/scripts/toggle_off.sh index aded15d..0b0a77e 100755 --- a/scripts/toggle_off.sh +++ b/scripts/toggle_off.sh @@ -1,14 +1,17 @@ #!/usr/bin/env bash +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source "$CURRENT_DIR/variables.sh" + tmux set -u prefix tmux set -u key-table # Restore the original status-left saved by toggle_on, then clear the saved value so # the next toggle_on cycle saves the current status-left rather than the stale snapshot. -saved="$(tmux show-option -gv @remote-saved-status-left 2>/dev/null)" +saved="$(tmux show-option -gv "$saved_status_left_option" 2>/dev/null)" if [[ -n "$saved" ]]; then tmux set -g status-left "$saved" fi -tmux set -gu @remote-saved-status-left +tmux set -gu "$saved_status_left_option" tmux refresh-client -S diff --git a/scripts/toggle_on.sh b/scripts/toggle_on.sh index 1716257..7ce2187 100755 --- a/scripts/toggle_on.sh +++ b/scripts/toggle_on.sh @@ -1,15 +1,18 @@ #!/usr/bin/env bash +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +source "$CURRENT_DIR/variables.sh" + # Save the current status-left so toggle_off can restore it (only once) -saved="$(tmux show-option -gv @remote-saved-status-left 2>/dev/null)" +saved="$(tmux show-option -gv "$saved_status_left_option" 2>/dev/null)" if [[ -z "$saved" ]]; then - tmux set -g @remote-saved-status-left "$(tmux show-option -gv status-left)" + tmux set -g "$saved_status_left_option" "$(tmux show-option -gv status-left)" fi # Read indicator options -text="$(tmux show-option -gv @remote-indicator-text)" -fg="$(tmux show-option -gv @remote-indicator-fg)" -bg="$(tmux show-option -gv @remote-indicator-bg)" +text="$(tmux show-option -gv "$indicator_text_option")" +fg="$(tmux show-option -gv "$indicator_fg_option")" +bg="$(tmux show-option -gv "$indicator_bg_option")" tmux set prefix None tmux set key-table off diff --git a/scripts/variables.sh b/scripts/variables.sh index 82d3258..5cef4d5 100644 --- a/scripts/variables.sh +++ b/scripts/variables.sh @@ -5,6 +5,7 @@ off_key_option="@remote-off-key" indicator_text_option="@remote-indicator-text" indicator_fg_option="@remote-indicator-fg" indicator_bg_option="@remote-indicator-bg" +saved_status_left_option="@remote-saved-status-left" # default option values default_toggle_key="F12"