From b2861db4f17bdd5b9db1785ae44737df357a4a28 Mon Sep 17 00:00:00 2001 From: Devin Weaver Date: Sun, 4 Mar 2018 13:39:00 -0500 Subject: [PATCH] Add ability to abort from Vim exit code In many cases where Vim is used as an intermediate step in a series of steps it is helpful to abort when the user explicitly exits vim with a non-zero exit code. What that means in this project is that if the user who is editing the buffer decides that he/she does NOT wish to overwrite the clipboard (maybe they realized they have something important) they would quit Vim with `:cq` instead of the normal ways. This means they can write the file all they want and it will not be copied to the clipboard if they use the `:cq` command. Granted the utility of this is debatable making this change optional. --- bin/run | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/bin/run b/bin/run index 804a137..4e14720 100755 --- a/bin/run +++ b/bin/run @@ -56,8 +56,11 @@ touch $TMPFILE # Linux if [[ $OSTYPE == "linux-gnu" ]]; then chmod o-r $TMPFILE # Make file only readable by you - gvim $VIM_OPTS $TMPFILE - cat $TMPFILE | xclip -selection clipboard + if gvim $VIM_OPTS $TMPFILE; then + cat $TMPFILE | xclip -selection clipboard + else + err "Vim aborted with a non-zero exit code." + fi # OSX elif [[ $OSTYPE == "darwin"* ]]; then @@ -72,13 +75,16 @@ elif [[ $OSTYPE == "darwin"* ]]; then "mvim must have been moved or uninstalled.\nPlease make sure it is" \ "available in your path and then reinstall vim-anywhere." - $mvim_path $VIM_OPTS $TMPFILE # todo, fix invalid file + if $mvim_path $VIM_OPTS $TMPFILE; then + # NOTE + # Here we set LANG explicitly to be UTF-8 compatible when copying text. The only way that was explicitly + # setting this to en_US.UTF-8. This may eventually cause issues with other languages. If so, just remove + # the LANG setting. + LANG=en_US.UTF-8 pbcopy < $TMPFILE + else + err "MacVim aborted with a non-zero exit code." + fi - # NOTE - # Here we set LANG explicitly to be UTF-8 compatible when copying text. The only way that was explicitly - # setting this to en_US.UTF-8. This may eventually cause issues with other languages. If so, just remove - # the LANG setting. - LANG=en_US.UTF-8 pbcopy < $TMPFILE osascript -e "activate application \"$app\"" fi