diff --git a/.local/bin/tm b/.local/bin/tm index a2de614..02193f5 100755 --- a/.local/bin/tm +++ b/.local/bin/tm @@ -66,25 +66,41 @@ _create_detached_session() { } _load_env_session_file() { - xargs -L1 tmux < ./.tmux.session + if [ -f ./.tmux.session ]; then + xargs -L1 tmux < ./.tmux.session + fi } _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() { + 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 - session_file=${1} - if ! _file_exists "$session_file"; then - echo "$0: can not source configuration file: '${session_file}' does not exist." + if ! _file_exists "$1" && ! _file_exists "${session_dir}${1}"; then + echo "sess dir: ${session_dir}${1}" + echo "$0: can not source configuration file: '${1}' does not exist." exit 1 fi + _set_session_file_path "$1" session_name=${2} elif [ "$#" -eq 1 ]; then - if _file_exists "${1}"; then - session_file=${1} - else + _set_session_file_path "$1" + if ! _file_exists "$session_file"; then session_name=${1} fi fi @@ -124,6 +140,7 @@ _attach_or_create() { _unset_functions() { unset _set_session_vars + unset _set_session_file_path unset _attach_or_create unset _load_session_file unset _create_detached_session