Adds protection to script

This commit is contained in:
William Carroll 2016-08-01 17:00:06 -04:00
parent 0da48c1290
commit 4014e4ac7e

View file

@ -2,41 +2,50 @@
path_to_ext_device="/Volumes/usb_vim" path_to_ext_device="/Volumes/usb_vim"
# ensure there is an external device connected and that the path to it is
# accurate.
if [ ! -d "$path_to_ext_device" ]; then
echo "No external device found at: $path_to_ext_device"
echo "Ensure that the value set for path_to_ext_device is correct."
echo "path_to_ext_device: $path_to_ext_device"
echo "Exiting."
return 1
fi
# This script toggles between local vim and a version that can be stored on an # This script toggles between local vim and a version that can be stored on an
# external device like a USB. # external device like a USB.
if [ -L "$HOME/.vim" ]; then # USB --> local machine
if [ -L "$HOME/.vim" ] && [ -L "$HOME/.vimrc" ]; then
echo "Pointing to USB. Toggling back to local machine..." echo "Pointing to USB. Toggling back to local machine..."
# remove the symlink and .vimrc # remove the symlinks
rm "$HOME/.vim" rm "$HOME/.vim"
# remove the USB's version of the .vimrc and use the backed-up copy
rm "$HOME/.vimrc" rm "$HOME/.vimrc"
mv "$HOME/.vimrc.bak" "$HOME/.vimrc"
# rename the .vim.bak directory # restore back-ups as active files
mv "$HOME/.vim.bak" "$HOME/.vim" [ -d "$HOME/.vim.bak" ] && mv "$HOME/.vim.bak" "$HOME/.vim"
[ -f "$HOME/.vimrc.bak" ] && mv "$HOME/.vimrc.bak" "$HOME/.vimrc"
echo ".vim now points to $HOME/.vim" echo ".vim now points to $HOME/.vim"
echo ".vimrc now points to $HOME/.vimrc"
# local machine --> USB
else else
echo "Pointing to local machine. Toggling to USB..." echo "Pointing to local machine. Toggling to USB..."
# back-up local machine's .vim folder # back-up local machine's files
mv "$HOME/.vim" "$HOME/.vim.bak" [ -d "$HOME/.vim" ] && mv "$HOME/.vim" "$HOME/.vim.bak"
[ -f "$HOME/.vimrc" ] && mv "$HOME/.vimrc" "$HOME/.vimrc.bak"
# back-up the local machine's .vimrc # symlink .vim and .vimrc to external device
if [ -f "HOME/.vimrc" ]; then ln -s "${path_to_ext_device}/vim/.vim" "$HOME/.vim"
mv "$HOME/.vimrc" "$HOME/.vimrc.bak" ln -s "${path_to_ext_device}/vim/.vimrc" "$HOME/.vimrc"
fi
echo ".vim now points to ${path_to_ext_device}/vim/.vim"
# point the $HOME/.vim name to the USB for source routing
# use the USB drive's copy of .vimrc
ln -s "${path_to_ext_device}/.vim" "$HOME/.vim"
ln -s "${path_to_ext_device}/.vimrc" "$HOME/.vimrc"
echo ".vim now points to ${path_to_ext_device}/.vim"
fi fi
echo "Done." echo "Done."