From 8cb5b21e2ffa5944a8b5ec14c458bb938ba9f562 Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Thu, 28 Aug 2014 13:43:04 +0200 Subject: [PATCH] Fix #18: improve vim 'session' strategy --- CHANGELOG.md | 2 ++ strategies/vim_session.sh | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 449e5d0..8d619d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Changelog ### master +- bugfix: with vim 'session' strategy, if the session file does not exist - make + sure wim does not contain `-S` flag ### v0.1.0, 2014-08-28 - refactor checking if saved tmux session exists diff --git a/strategies/vim_session.sh b/strategies/vim_session.sh index 83912b6..26bff51 100755 --- a/strategies/vim_session.sh +++ b/strategies/vim_session.sh @@ -4,7 +4,7 @@ # # Restores a vim session from 'Session.vim' file, if it exists. # If 'Session.vim' does not exist, it falls back to invoking the original -# command. +# command (withouth the `-S` flag). ORIGINAL_COMMAND="$1" DIRECTORY="$2" @@ -13,9 +13,18 @@ vim_session_file_exists() { [ -e "${DIRECTORY}/Session.vim" ] } +original_command_contains_session_flag() { + [[ "$ORIGINAL_COMMAND" =~ "-S" ]] +} + main() { if vim_session_file_exists; then echo "vim -S" + elif original_command_contains_session_flag; then + # Session file does not exist, yet the orignal vim command contains + # session flag `-S`. This will cause an error, so we're falling back to + # starting plain vim. + echo "vim" else echo "$ORIGINAL_COMMAND" fi