Add default session root dir to tm

This commit is contained in:
Marty Oehme 2019-07-10 13:48:44 +02:00
parent 27af1cc7fa
commit 4e3cc2342a

View file

@ -66,25 +66,41 @@ _create_detached_session() {
} }
_load_env_session_file() { _load_env_session_file() {
xargs -L1 tmux < ./.tmux.session if [ -f ./.tmux.session ]; then
xargs -L1 tmux < ./.tmux.session
fi
} }
_load_session_file() { _load_session_file() {
xargs -L1 tmux < "$session_file" if [ -f "$session_file" ]; then
xargs -L1 tmux < "$session_file"
fi
}
_set_session_file_path() {
# Prefer local dir if file exists there, fall back to root dir
if _file_exists "${1}"; then
session_file="${1}"
elif _file_exists "${session_dir}${1}"; then
session_file="${session_dir}${1}"
fi
} }
_set_session_vars() { _set_session_vars() {
session_dir=${TM_SESSION_DIR:-"$XDG_CONFIG_HOME/tmux/sessions/"}
# set up session name and config file - if passed in as arguments
if [ "$#" -eq 2 ]; then if [ "$#" -eq 2 ]; then
session_file=${1} if ! _file_exists "$1" && ! _file_exists "${session_dir}${1}"; then
if ! _file_exists "$session_file"; then echo "sess dir: ${session_dir}${1}"
echo "$0: can not source configuration file: '${session_file}' does not exist." echo "$0: can not source configuration file: '${1}' does not exist."
exit 1 exit 1
fi fi
_set_session_file_path "$1"
session_name=${2} session_name=${2}
elif [ "$#" -eq 1 ]; then elif [ "$#" -eq 1 ]; then
if _file_exists "${1}"; then _set_session_file_path "$1"
session_file=${1} if ! _file_exists "$session_file"; then
else
session_name=${1} session_name=${1}
fi fi
fi fi
@ -124,6 +140,7 @@ _attach_or_create() {
_unset_functions() { _unset_functions() {
unset _set_session_vars unset _set_session_vars
unset _set_session_file_path
unset _attach_or_create unset _attach_or_create
unset _load_session_file unset _load_session_file
unset _create_detached_session unset _create_detached_session