BINARY="$(which tmux-backup)"
setup_option () {
opt_name=$1
default_value=$2
current_value=$(tmux show-option -gqv @backup-${opt_name})
value=$([[ ! -z "${current_value}" ]] && echo "${current_value}" || echo "${default_value}")
tmux set-option -g @backup-${opt_name} ${value}
}
setup_option "keytable" "tmuxbackup"
setup_option "keyswitch" "b"
keyswitch=$(tmux show-option -gv @backup-keyswitch)
keytable=$(tmux show-option -gv @backup-keytable)
tmux bind-key ${keyswitch} switch-client -T ${keytable}
setup_option "strategy" "-s most-recent -n 10"
strategy=$(tmux show-option -gv @backup-strategy)
setup_binding () {
key=$1
command="$2"
tmux bind-key -T ${keytable} ${key} run-shell "${BINARY} ${command}"
}
setup_binding_w_popup () {
key=$1
command="$2"
tmux bind-key -T ${keytable} ${key} display-popup -E "tmux new-session -A -s tmux-backup '${BINARY} ${command} ; echo Press any key... && read -k1 -s'"
}
setup_binding "b" "save ${strategy} --ignore-last-lines 1 --to-tmux"
setup_binding "s" "save ${strategy} --ignore-last-lines 1 --compact --to-tmux"
setup_binding "r" "restore ${strategy} --to-tmux"
setup_binding_w_popup "l" "catalog ${strategy} list"
setup_binding_w_popup "L" "catalog ${strategy} list --details"