From a9a87992dfd06e5b9fce6c684651a0f9525ad85d Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 2 Apr 2016 22:28:36 +0200 Subject: [PATCH 1/2] 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. --- lib/layout-helpers.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/layout-helpers.sh b/lib/layout-helpers.sh index 7ac787e..6f7491c 100644 --- a/lib/layout-helpers.sh +++ b/lib/layout-helpers.sh @@ -189,9 +189,17 @@ load_window() { # - $2: (optional) Override default window name. # load_session() { - local file="$1" - if [ ! -f "$file" ]; then - file="$TMUXIFIER_LAYOUT_PATH/$1.session.sh" + local file + if [ "${1#*/}" = "$1" ]; then + # 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 if [ -f "$file" ]; then From 3a8a43ccdcb61d5e35ebf95c3730a4b0c7b922e5 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 2 Apr 2016 22:36:42 +0200 Subject: [PATCH 2/2] style: load_session: move return case up, removing indent --- lib/layout-helpers.sh | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/layout-helpers.sh b/lib/layout-helpers.sh index 6f7491c..52488b4 100644 --- a/lib/layout-helpers.sh +++ b/lib/layout-helpers.sh @@ -202,26 +202,26 @@ load_session() { file="$1" fi - if [ -f "$file" ]; then - if [ $# -gt 1 ]; then - session="$2" - else - session="${1/%.session.sh}" - session="${session/%.sh}" - fi - - set_default_path=true - source "$file" - session= - - # Reset `$session_root`. - if [[ "$session_root" != "$HOME" ]]; then - session_root="$HOME" - fi - else + if ! [ -f "$file" ]; then echo "\"$1\" session layout not found." >&2 return 1 fi + + if [ $# -gt 1 ]; then + session="$2" + else + session="${1/%.session.sh}" + session="${session/%.sh}" + fi + + set_default_path=true + source "$file" + session= + + # Reset `$session_root`. + if [[ "$session_root" != "$HOME" ]]; then + session_root="$HOME" + fi } # Create a new session, returning 0 on success, 1 on failure.