tvl-depot/usbify/vim/vim_point_to_usb.sh

44 lines
1.1 KiB
Bash
Raw Normal View History

2016-08-01 21:30:21 +02:00
#!/usr/bin/env bash
path_to_ext_device="/Volumes/usb_vim"
2016-08-01 21:36:36 +02:00
# This script toggles between local vim and a version that can be stored on an
# external device like a USB.
2016-08-01 21:30:21 +02:00
if [ -L "$HOME/.vim" ]; then
2016-08-01 21:36:36 +02:00
echo "Pointing to USB. Toggling back to local machine..."
2016-08-01 21:30:21 +02:00
# remove the symlink and .vimrc
rm "$HOME/.vim"
# remove the USB's version of the .vimrc and use the backed-up copy
rm "$HOME/.vimrc"
mv "$HOME/.vimrc.bak" "$HOME/.vimrc"
# rename the .vim.bak directory
mv "$HOME/.vim.bak" "$HOME/.vim"
echo ".vim now points to $HOME/.vim"
else
2016-08-01 21:36:36 +02:00
echo "Pointing to local machine. Toggling to USB..."
2016-08-01 21:30:21 +02:00
2016-08-01 22:02:14 +02:00
# back-up local machine's .vim folder
2016-08-01 21:30:21 +02:00
mv "$HOME/.vim" "$HOME/.vim.bak"
2016-08-01 22:02:14 +02:00
# back-up the local machine's .vimrc
if [ -f "HOME/.vimrc" ]; then
mv "$HOME/.vimrc" "$HOME/.vimrc.bak"
fi
2016-08-01 21:30:21 +02:00
# 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"
2016-08-01 21:30:21 +02:00
echo ".vim now points to ${path_to_ext_device}/.vim"
2016-08-01 21:30:21 +02:00
fi
echo "Done."