Skip to content

Commit b2861db

Browse files
committed
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.
1 parent 63cfb33 commit b2861db

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

bin/run

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ touch $TMPFILE
5656
# Linux
5757
if [[ $OSTYPE == "linux-gnu" ]]; then
5858
chmod o-r $TMPFILE # Make file only readable by you
59-
gvim $VIM_OPTS $TMPFILE
60-
cat $TMPFILE | xclip -selection clipboard
59+
if gvim $VIM_OPTS $TMPFILE; then
60+
cat $TMPFILE | xclip -selection clipboard
61+
else
62+
err "Vim aborted with a non-zero exit code."
63+
fi
6164

6265
# OSX
6366
elif [[ $OSTYPE == "darwin"* ]]; then
@@ -72,13 +75,16 @@ elif [[ $OSTYPE == "darwin"* ]]; then
7275
"mvim must have been moved or uninstalled.\nPlease make sure it is" \
7376
"available in your path and then reinstall vim-anywhere."
7477

75-
$mvim_path $VIM_OPTS $TMPFILE
7678
# todo, fix invalid file
79+
if $mvim_path $VIM_OPTS $TMPFILE; then
80+
# NOTE
81+
# Here we set LANG explicitly to be UTF-8 compatible when copying text. The only way that was explicitly
82+
# setting this to en_US.UTF-8. This may eventually cause issues with other languages. If so, just remove
83+
# the LANG setting.
84+
LANG=en_US.UTF-8 pbcopy < $TMPFILE
85+
else
86+
err "MacVim aborted with a non-zero exit code."
87+
fi
7788

78-
# NOTE
79-
# Here we set LANG explicitly to be UTF-8 compatible when copying text. The only way that was explicitly
80-
# setting this to en_US.UTF-8. This may eventually cause issues with other languages. If so, just remove
81-
# the LANG setting.
82-
LANG=en_US.UTF-8 pbcopy < $TMPFILE
8389
osascript -e "activate application \"$app\""
8490
fi

0 commit comments

Comments
 (0)