Add looking for .tmux.session files in pwd

If no explicit session file is passed in and a new session is being
created tm will look for a .tmux.session file in the pwd and use that to
set up the session.
This commit is contained in:
Marty Oehme 2019-07-10 13:21:44 +02:00
parent 6fcf2a750e
commit 27af1cc7fa

View file

@ -10,7 +10,8 @@ cat <<-EOF
If no session exists which fits the criteria, this will create a new one and
load it up obeying the commands contained in the FILE argument passed in. It
must contain commands which are tmux-command compatible since they will be
passed to tmux unmodified.
passed to tmux unmodified. If a session exists and a valid configuration FILE is
passed, it will attach itself to the session and execute the session setup inside.
It will load the default tmux.conf in the following order:
- XDG_CONFIG_HOME/tmux/tmux.conf (usually ~/.config/tmux/tmux.conf)
@ -23,6 +24,12 @@ cat <<-EOF
If no NAME argument is passed it will automatically create a session name from the
FILE argument passed.
If creating a new session without passing in a FILE argument, and the current directory
contains a .tmux.session file, it will automatically use that to set up the session.
By default, it also looks for valid session files in XDG_CONFIG_HOME/tmux/sessions/
This path can be changed by setting the TM_SESSION_PATH environment variable.
EOF
exit 0
fi
@ -58,6 +65,10 @@ _create_detached_session() {
($start new-session -d -s "$session_name")
}
_load_env_session_file() {
xargs -L1 tmux < ./.tmux.session
}
_load_session_file() {
xargs -L1 tmux < "$session_file"
}
@ -93,6 +104,10 @@ _attach_or_create() {
# first create a new session if one doesn't exist
if ! _session_exists; then
_create_detached_session
# look for .tmux.session file if no file has been explicitly passed in
if ! _file_exists "$session_file"; then
_load_env_session_file
fi
fi
_load_session_file