load_session: prefer existing session instead of file in cwd

This also adds './' to a file used from the current working dir (in case
there is no session with that name), which is required for Bash's
`source` to use it (and not look for it in `$PATH`).

Fixes https://github.com/jimeh/tmuxifier/issues/69.
This commit is contained in:
Daniel Hahler
2016-04-02 22:28:36 +02:00
parent 5f4dd92d7f
commit a9a87992df

View File

@@ -189,9 +189,17 @@ load_window() {
# - $2: (optional) Override default window name. # - $2: (optional) Override default window name.
# #
load_session() { load_session() {
local file="$1" local file
if [ ! -f "$file" ]; then if [ "${1#*/}" = "$1" ]; then
file="$TMUXIFIER_LAYOUT_PATH/$1.session.sh" # There's no slash in the path.
if [ -f "$TMUXIFIER_LAYOUT_PATH/$1.session.sh" ] || [ ! -f "$1" ]; then
file="$TMUXIFIER_LAYOUT_PATH/$1.session.sh"
else
# bash's 'source' requires an slash in the filename to not use $PATH.
file="./$1"
fi
else
file="$1"
fi fi
if [ -f "$file" ]; then if [ -f "$file" ]; then