tmux-stare/stare.tmux (view raw)
| 1 | #!/usr/bin/env bash |
| 2 | set -x |
| 3 | |
| 4 | CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 5 | source "$CURRENT_DIR/scripts/helpers.sh" |
| 6 | |
| 7 | add_save_interpolation() { |
| 8 | local status_right_value="$(get_tmux_option "status-right" "")" |
| 9 | local save_interpolation="#($CURRENT_DIR/scripts/_auto_save.sh)" |
| 10 | |
| 11 | if [[ "$status_right_value" != *"$save_interpolation"* ]]; then |
| 12 | set_tmux_option "status-right" "${save_interpolation}${status_right_value}" |
| 13 | fi |
| 14 | } |
| 15 | |
| 16 | main() { |
| 17 | local pick_key="$(get_opt_pick)" |
| 18 | [[ -n "$pick_key" ]] && tmux bind-key "$pick_key" run-shell "bash \"$CURRENT_DIR/scripts/_pick.sh\"" |
| 19 | |
| 20 | local save_key="$(get_opt_save)" |
| 21 | [[ -n "$save_key" ]] && tmux bind-key "$save_key" run-shell "bash \"$CURRENT_DIR/scripts/_save.sh\"" |
| 22 | |
| 23 | local start_action="$(get_opt_start)" |
| 24 | if [[ "$(get_opt_initialized)" == "0" ]]; then |
| 25 | if [[ "$start_action" == "last" ]]; then |
| 26 | tmux run-shell -b "sleep 0.1 && bash \"$CURRENT_DIR/scripts/_restore.sh\"" |
| 27 | elif [[ "$start_action" == "pick" ]]; then |
| 28 | tmux run-shell -b "sleep 0.1 && bash \"$CURRENT_DIR/scripts/_pick.sh\"" |
| 29 | fi |
| 30 | |
| 31 | set_opt_initialized "1" |
| 32 | fi |
| 33 | |
| 34 | # rename hook |
| 35 | tmux set-hook -g session-renamed "run-shell \"bash '$CURRENT_DIR/scripts/_session_renamed.sh' #{q:hook_session} #{q:hook_session_name}\"" |
| 36 | tmux run-shell "bash '$CURRENT_DIR/scripts/_session_renamed.sh' sync" |
| 37 | |
| 38 | add_save_interpolation |
| 39 | } |
| 40 | main |