summaryrefslogtreecommitdiff
path: root/utils/installer/uninstall.sh
blob: 0ac62e362052d5b8be2298c493e682221d680294 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash
set -eo pipefail

ARGS_REMOVE_BACKUPS=0
ARGS_REMOVE_CONFIG=0

declare -r XDG_DATA_HOME="${XDG_DATA_HOME:-"$HOME/.local/share"}"
declare -r XDG_CACHE_HOME="${XDG_CACHE_HOME:-"$HOME/.cache"}"

declare -xr NVIM_APPNAME="${NVIM_APPNAME:-"lvim"}"

declare LUNARVIM_DATA_DIR="$XDG_DATA_HOME/$NVIM_APPNAME"
declare LUNARVIM_CACHE_DIR="$XDG_CACHE_HOME/$NVIM_APPNAME"

declare -a __lvim_dirs=(
  "$LUNARVIM_DATA_DIR"
  "$LUNARVIM_CACHE_DIR"
)

__lvim_config_dir="$LUNARVIM_CONFIG_DIR"

function usage() {
  echo "Usage: uninstall.sh [<options>]"
  echo ""
  echo "Options:"
  echo "    -h, --help                       Print this help message"
  echo "    --remove-config                  Remove user config files as well"
  echo "    --remove-backups                 Remove old backup folders as well"
}

function parse_arguments() {
  while [ "$#" -gt 0 ]; do
    case "$1" in
      --remove-backups)
        ARGS_REMOVE_BACKUPS=1
        ;;
      --remove-config)
        ARGS_REMOVE_CONFIG=1
        ;;
      -h | --help)
        usage
        exit 0
        ;;
    esac
    shift
  done
}

function remove_lvim_dirs() {
  if [ "$ARGS_REMOVE_CONFIG" -eq 1 ]; then
    __lvim_dirs+=($__lvim_config_dir)
  fi
  for dir in "${__lvim_dirs[@]}"; do
    rm -rf "$dir"
    if [ "$ARGS_REMOVE_BACKUPS" -eq 1 ]; then
      rm -rf "$dir.{bak,old}"
    fi
  done
}

function remove_lvim_bin() {
  local legacy_bin="/usr/local/bin/lvim"
  if [ -x "$legacy_bin" ]; then
    echo "Error! Unable to remove $legacy_bin without elevation. Please remove manually."
    exit 1
  fi

  lvim_bin="$(command -v $NVIM_APPNAME 2>/dev/null)"
  rm -f "$lvim_bin"
}

function remove_desktop_file() {
  OS="$(uname -s)"
  ([ "$OS" != "Linux" ] || ! command -v xdg-desktop-menu &>/dev/null) && return
  echo "Removing desktop file..."

  find "$XDG_DATA_HOME/icons/hicolor" -name "lvim.svg" -type f -delete
  xdg-desktop-menu uninstall lvim.desktop
}

function main() {
  parse_arguments "$@"
  echo "Removing LunarVim binary..."
  remove_lvim_bin
  echo "Removing LunarVim directories..."
  remove_lvim_dirs
  remove_desktop_file
  echo "Uninstalled LunarVim!"
}

main "$@"