2014-08-27 22:43:31 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# "vim session strategy"
|
|
|
|
#
|
|
|
|
# Restores a vim session from 'Session.vim' file, if it exists.
|
|
|
|
# If 'Session.vim' does not exist, it falls back to invoking the original
|
2014-08-28 11:43:04 +00:00
|
|
|
# command (withouth the `-S` flag).
|
2014-08-27 22:43:31 +00:00
|
|
|
|
|
|
|
ORIGINAL_COMMAND="$1"
|
|
|
|
DIRECTORY="$2"
|
|
|
|
|
|
|
|
vim_session_file_exists() {
|
|
|
|
[ -e "${DIRECTORY}/Session.vim" ]
|
|
|
|
}
|
|
|
|
|
2014-08-28 11:43:04 +00:00
|
|
|
original_command_contains_session_flag() {
|
|
|
|
[[ "$ORIGINAL_COMMAND" =~ "-S" ]]
|
|
|
|
}
|
|
|
|
|
2014-08-27 22:43:31 +00:00
|
|
|
main() {
|
|
|
|
if vim_session_file_exists; then
|
|
|
|
echo "vim -S"
|
2014-08-28 11:43:04 +00:00
|
|
|
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"
|
2014-08-27 22:43:31 +00:00
|
|
|
else
|
|
|
|
echo "$ORIGINAL_COMMAND"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
main
|