Change plugin name and all the variables

This commit is contained in:
Bruno Sutic
2014-08-29 18:59:14 +02:00
parent e2e55c6faa
commit bd095e739d
10 changed files with 61 additions and 59 deletions

View File

@ -1,6 +1,5 @@
# configurable constants
default_sessions_dir="$HOME/.tmux/sessions"
sessions_dir_option="@session-saver-dir"
default_resurrect_dir="$HOME/.tmux/resurrect"
resurrect_dir_option="@resurrect-dir"
SUPPORTED_VERSION="1.9"
@ -52,15 +51,15 @@ remove_first_char() {
# path helpers
sessions_dir() {
echo $(get_tmux_option "$sessions_dir_option" "$default_sessions_dir")
resurrect_dir() {
echo $(get_tmux_option "$resurrect_dir_option" "$default_resurrect_dir")
}
session_path() {
resurrect_file_path() {
local timestamp="$(date +"%Y-%m-%dT%H:%M:%S")"
echo "$(sessions_dir)/tmux_session_${timestamp}.txt"
echo "$(resurrect_dir)/tmux_resurrect_${timestamp}.txt"
}
last_session_path() {
echo "$(sessions_dir)/last"
last_resurrect_file() {
echo "$(resurrect_dir)/last"
}

View File

@ -8,7 +8,7 @@ source "$CURRENT_DIR/process_restore_helpers.sh"
source "$CURRENT_DIR/spinner_helpers.sh"
# Global variable.
# Used during the restoration: if a pane already exists from before, it is
# Used during the restore: if a pane already exists from before, it is
# saved in the array in this variable. Later, process running in existing pane
# is also not restored. That makes the restoration process more idempotent.
EXISTING_PANES_VAR=""
@ -21,9 +21,9 @@ is_line_type() {
}
check_saved_session_exists() {
local saved_session="$(last_session_path)"
if [ ! -f $saved_session ]; then
display_message "Saved tmux session not found!"
local resurrect_file="$(last_resurrect_file)"
if [ ! -f $resurrect_file ]; then
display_message "Tmux resurrect file not found!"
return 1
fi
}
@ -137,13 +137,13 @@ restore_all_panes() {
if is_line_type "pane" "$line"; then
restore_pane "$line"
fi
done < $(last_session_path)
done < $(last_resurrect_file)
}
restore_all_pane_processes() {
if restore_pane_processes_enabled; then
local pane_full_command
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $11 !~ "^:$" { print $2, $3, $7, $8, $11; }' $(last_session_path) |
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $11 !~ "^:$" { print $2, $3, $7, $8, $11; }' $(last_resurrect_file) |
while IFS=$'\t' read session_name window_number pane_index dir pane_full_command; do
dir="$(remove_first_char "$dir")"
pane_full_command="$(remove_first_char "$pane_full_command")"
@ -153,14 +153,14 @@ restore_all_pane_processes() {
}
restore_pane_layout_for_each_window() {
\grep '^window' $(last_session_path) |
\grep '^window' $(last_resurrect_file) |
while IFS=$'\t' read line_type session_name window_number window_active window_flags window_layout; do
tmux select-layout -t "${session_name}:${window_number}" "$window_layout"
done
}
restore_active_pane_for_each_window() {
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $9 == 1 { print $2, $3, $7; }' $(last_session_path) |
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $9 == 1 { print $2, $3, $7; }' $(last_resurrect_file) |
while IFS=$'\t' read session_name window_number active_pane; do
tmux switch-client -t "${session_name}:${window_number}"
tmux select-pane -t "$active_pane"
@ -168,14 +168,14 @@ restore_active_pane_for_each_window() {
}
restore_zoomed_windows() {
awk 'BEGIN { FS="\t"; OFS="\t" } /^window/ && $5 ~ /Z/ { print $2, $3; }' $(last_session_path) |
awk 'BEGIN { FS="\t"; OFS="\t" } /^window/ && $5 ~ /Z/ { print $2, $3; }' $(last_resurrect_file) |
while IFS=$'\t' read session_name window_number; do
tmux resize-pane -t "${session_name}:${window_number}" -Z
done
}
restore_active_and_alternate_windows() {
awk 'BEGIN { FS="\t"; OFS="\t" } /^window/ && $5 ~ /[*-]/ { print $2, $4, $3; }' $(last_session_path) |
awk 'BEGIN { FS="\t"; OFS="\t" } /^window/ && $5 ~ /[*-]/ { print $2, $4, $3; }' $(last_resurrect_file) |
sort -u |
while IFS=$'\t' read session_name active_window window_number; do
tmux switch-client -t "${session_name}:${window_number}"
@ -187,7 +187,7 @@ restore_active_and_alternate_sessions() {
if is_line_type "state" "$line"; then
restore_state "$line"
fi
done < $(last_session_path)
done < $(last_resurrect_file)
}
main() {
@ -202,7 +202,7 @@ main() {
restore_active_and_alternate_windows
restore_active_and_alternate_sessions
stop_spinner
display_message "Restored all Tmux sessions!"
display_message "Tmux restore complete!"
fi
}
main

View File

@ -2,6 +2,7 @@
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_DIR/scripts/variables.sh"
source "$CURRENT_DIR/helpers.sh"
pane_format() {
@ -88,19 +89,19 @@ dump_state() {
tmux display-message -p "$(state_format)"
}
save_all_sessions() {
local session_path="$(session_path)"
mkdir -p "$(sessions_dir)"
dump_panes > $session_path
dump_windows >> $session_path
dump_state >> $session_path
ln -fs "$session_path" "$(last_session_path)"
display_message "Saved all Tmux sessions!"
save_all() {
local resurrect_file_path="$(resurrect_file_path)"
mkdir -p "$(resurrect_dir)"
dump_panes > $resurrect_file_path
dump_windows >> $resurrect_file_path
dump_state >> $resurrect_file_path
ln -fs "$resurrect_file_path" "$(last_resurrect_file)"
display_message "Tmux environment saved!"
}
main() {
if supported_tmux_version_ok; then
save_all_sessions
save_all
fi
}
main

View File

@ -1,5 +1,5 @@
start_spinner() {
$CURRENT_DIR/tmux_spinner.sh "Restoring sessions..." "Restored all Tmux sessions!" &
$CURRENT_DIR/tmux_spinner.sh "Restoring tmux..." "Tmux restore complete!" &
export SPINNER_PID=$!
}

View File

@ -1,12 +1,12 @@
# key bindings
default_save_key="M-s"
save_option="@session-saver-save"
save_option="@resurrect-save"
default_restore_key="M-r"
restore_option="@session-saver-restore"
restore_option="@resurrect-restore"
# default processes that are restored
default_proc_list_option="@session-saver-default-processes"
default_proc_list_option="@resurrect-default-processes"
default_proc_list='vi vim emacs man less more tail top htop irssi irb pry "~rails console"'
# User defined processes that are restored
@ -15,9 +15,9 @@ default_proc_list='vi vim emacs man less more tail top htop irssi irb pry "~rail
#
# user defined list of programs that are restored:
# 'my_program foo another_program'
restore_processes_option="@session-saver-processes"
restore_processes_option="@resurrect-processes"
restore_processes=""
# Defines part of the user variable. Example usage:
# set -g @session-saver-strategy-vim "session"
restore_process_strategy_option="@session-saver-strategy-"
# set -g @resurrect-strategy-vim "session"
restore_process_strategy_option="@resurrect-strategy-"