tvl-depot/usbify/vim/vim_point_to_usb.sh

53 lines
1.4 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 23:00:06 +02:00
# 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
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
2016-08-01 23:00:06 +02:00
# USB --> local machine
if [ -L "$HOME/.vim" ] && [ -L "$HOME/.vimrc" ]; 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
2016-08-01 23:00:06 +02:00
# remove the symlinks
2016-08-01 21:30:21 +02:00
rm "$HOME/.vim"
rm "$HOME/.vimrc"
2016-08-01 23:00:06 +02:00
# restore back-ups as active files
[ -d "$HOME/.vim.bak" ] && mv "$HOME/.vim.bak" "$HOME/.vim"
[ -f "$HOME/.vimrc.bak" ] && mv "$HOME/.vimrc.bak" "$HOME/.vimrc"
2016-08-01 21:30:21 +02:00
echo ".vim now points to $HOME/.vim"
2016-08-01 23:00:06 +02:00
echo ".vimrc now points to $HOME/.vimrc"
# local machine --> USB
2016-08-01 21:30:21 +02:00
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 23:00:06 +02:00
# back-up local machine's files
[ -d "$HOME/.vim" ] && mv "$HOME/.vim" "$HOME/.vim.bak"
[ -f "$HOME/.vimrc" ] && mv "$HOME/.vimrc" "$HOME/.vimrc.bak"
2016-08-01 21:30:21 +02:00
2016-08-01 23:00:06 +02:00
# symlink .vim and .vimrc to external device
ln -s "${path_to_ext_device}/vim/.vim" "$HOME/.vim"
ln -s "${path_to_ext_device}/vim/.vimrc" "$HOME/.vimrc"
2016-08-01 21:30:21 +02:00
2016-08-01 23:00:06 +02:00
echo ".vim now points to ${path_to_ext_device}/vim/.vim"
2016-08-01 21:30:21 +02:00
fi
echo "Done."