diff options
author | William Carroll <wpcarro@gmail.com> | 2016-08-01T21·00-0400 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2016-08-01T21·00-0400 |
commit | 4014e4ac7e1e112d644267ca27c77220e6c43aca (patch) | |
tree | 67b7e7405d29177563428f53cbf11db5571509d6 /usbify | |
parent | 0da48c129097c871bd6c74778df1383dca68a4ab (diff) |
Adds protection to script
Diffstat (limited to 'usbify')
-rwxr-xr-x | usbify/vim/vim_point_to_usb.sh | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/usbify/vim/vim_point_to_usb.sh b/usbify/vim/vim_point_to_usb.sh index 98369170ffec..7ea24fb0b787 100755 --- a/usbify/vim/vim_point_to_usb.sh +++ b/usbify/vim/vim_point_to_usb.sh @@ -2,41 +2,50 @@ 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 # 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..." - # remove the symlink and .vimrc + # remove the symlinks 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" + # 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" echo ".vim now points to $HOME/.vim" + echo ".vimrc now points to $HOME/.vimrc" + +# local machine --> USB else echo "Pointing to local machine. Toggling to USB..." - # back-up local machine's .vim folder - mv "$HOME/.vim" "$HOME/.vim.bak" - - # back-up the local machine's .vimrc - if [ -f "HOME/.vimrc" ]; then - mv "$HOME/.vimrc" "$HOME/.vimrc.bak" - fi - + # back-up local machine's files + [ -d "$HOME/.vim" ] && mv "$HOME/.vim" "$HOME/.vim.bak" + [ -f "$HOME/.vimrc" ] && mv "$HOME/.vimrc" "$HOME/.vimrc.bak" - # 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" + # 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" - echo ".vim now points to ${path_to_ext_device}/.vim" + echo ".vim now points to ${path_to_ext_device}/vim/.vim" fi echo "Done." |