uninstall.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env bash
  2. set -eo pipefail
  3. ARGS_REMOVE_BACKUPS=0
  4. ARGS_REMOVE_CONFIG=0
  5. declare -r XDG_DATA_HOME="${XDG_DATA_HOME:-"$HOME/.local/share"}"
  6. declare -r XDG_CACHE_HOME="${XDG_CACHE_HOME:-"$HOME/.cache"}"
  7. declare -r XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-"$HOME/.config"}"
  8. declare -r LUNARVIM_RUNTIME_DIR="${LUNARVIM_RUNTIME_DIR:-"$XDG_DATA_HOME/lunarvim"}"
  9. declare -r LUNARVIM_CONFIG_DIR="${LUNARVIM_CONFIG_DIR:-"$XDG_CONFIG_HOME/lvim"}"
  10. declare -r LUNARVIM_CACHE_DIR="${LUNARVIM_CACHE_DIR:-"$XDG_CACHE_HOME/lvim"}"
  11. declare -a __lvim_dirs=(
  12. "$LUNARVIM_RUNTIME_DIR"
  13. "$LUNARVIM_CACHE_DIR"
  14. )
  15. __lvim_config_dir="$LUNARVIM_CONFIG_DIR"
  16. function usage() {
  17. echo "Usage: uninstall.sh [<options>]"
  18. echo ""
  19. echo "Options:"
  20. echo " -h, --help Print this help message"
  21. echo " --remove-config Remove user config files as well"
  22. echo " --remove-backups Remove old backup folders as well"
  23. }
  24. function parse_arguments() {
  25. while [ "$#" -gt 0 ]; do
  26. case "$1" in
  27. --remove-backups)
  28. ARGS_REMOVE_BACKUPS=1
  29. ;;
  30. --remove-config)
  31. ARGS_REMOVE_CONFIG=1
  32. ;;
  33. -h | --help)
  34. usage
  35. exit 0
  36. ;;
  37. esac
  38. shift
  39. done
  40. }
  41. function remove_lvim_dirs() {
  42. if [ "$ARGS_REMOVE_CONFIG" -eq 1 ]; then
  43. __lvim_dirs+=($__lvim_config_dir)
  44. fi
  45. for dir in "${__lvim_dirs[@]}"; do
  46. rm -rf "$dir"
  47. if [ "$ARGS_REMOVE_BACKUPS" -eq 1 ]; then
  48. rm -rf "$dir.{bak,old}"
  49. fi
  50. done
  51. }
  52. function remove_lvim_bin() {
  53. local legacy_bin="/usr/local/bin/lvim "
  54. if [ -x "$legacy_bin" ]; then
  55. echo "Error! Unable to remove $legacy_bin without elevation. Please remove manually."
  56. exit 1
  57. fi
  58. lvim_bin="$(command -v lvim 2>/dev/null)"
  59. rm -f "$lvim_bin"
  60. }
  61. function remove_desktop_file() {
  62. OS="$(uname -s)"
  63. # TODO: Any other OSes that use desktop files?
  64. ([ "$OS" != "Linux" ] || ! command -v xdg-desktop-menu &>/dev/null) && return
  65. echo "Removing desktop file..."
  66. find "$XDG_DATA_HOME/icons/hicolor" -name "lvim.svg" -type f -delete
  67. xdg-desktop-menu uninstall lvim.desktop
  68. }
  69. function main() {
  70. parse_arguments "$@"
  71. echo "Removing LunarVim binary..."
  72. remove_lvim_bin
  73. echo "Removing LunarVim directories..."
  74. remove_lvim_dirs
  75. remove_desktop_file
  76. echo "Uninstalled LunarVim!"
  77. }
  78. main "$@"