Skip to content
Myr

uninstall

This file

Path

uninstall

127 lines · 2.9 KiB

Last changed by

nushell: [uninstall] Query nu for autoload directoryJunegunn Choibefore adoption1b6e17c

History of this file

Take it

1#!/usr/bin/env bash23xdg=04prefix='~/.fzf'5prefix_expand=~/.fzf6fish_dir=${XDG_CONFIG_HOME:-$HOME/.config}/fish78help() {9  cat << EOF10usage: $0 [OPTIONS]1112    --help               Show this message13    --xdg                Remove files generated under \$XDG_CONFIG_HOME/fzf14EOF15}1617for opt in "$@"; do18  case $opt in19    --help)20      help21      exit 022      ;;23    --xdg)24      xdg=125      prefix='"${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf'26      prefix_expand=${XDG_CONFIG_HOME:-$HOME/.config}/fzf/fzf27      ;;28    *)29      echo "unknown option: $opt"30      help31      exit 132      ;;33  esac34done3536cd "$(dirname "${BASH_SOURCE[0]}")"37fzf_base=$(pwd)3839ask() {40  while true; do41    read -p "$1 ([y]/n) " -r42    REPLY=${REPLY:-"y"}43    if [[ $REPLY =~ ^[Yy]$ ]]; then44      return 045    elif [[ $REPLY =~ ^[Nn]$ ]]; then46      return 147    fi48  done49}5051remove() {52  echo "Remove $1"53  rm -f "$1"54}5556remove_line() {57  src=$158  echo "Remove from $1:"5960  shift61  line_no=162  match=063  while [ -n "$1" ]; do64    line=$(sed -n "$line_no,\$p" "$src" | \grep -m1 -nF "$1")65    if [ $? -ne 0 ]; then66      shift67      line_no=168      continue69    fi70    line_no=$(($(sed 's/:.*//' <<< "$line") + line_no - 1))71    content=$(sed 's/^[0-9]*://' <<< "$line")72    match=173    echo "  - Line #$line_no: $content"74    [ "$content" = "$1" ] || ask "    - Remove?"75    if [ $? -eq 0 ]; then76      temp=$(mktemp)77      awk -v n=$line_no 'NR == n {next} {print}' "$src" > "$temp" &&78        cat "$temp" > "$src" && rm -f "$temp" || break79      echo "      - Removed"80    else81      echo "      - Skipped"82      line_no=$((line_no + 1))83    fi84  done85  [ $match -eq 0 ] && echo "  - Nothing found"86  echo87}8889for shell in bash zsh; do90  shell_config=${prefix_expand}.${shell}91  remove "${shell_config}"92  remove_line ~/.${shell}rc \93    "[ -f ${prefix}.${shell} ] && source ${prefix}.${shell}" \94    "source ${prefix}.${shell}"95done9697bind_file="${fish_dir}/functions/fish_user_key_bindings.fish"98if [ -f "$bind_file" ]; then99  remove_line "$bind_file" "fzf_key_bindings"100  remove_line "$bind_file" "fzf_completion_setup"101  remove_line "$bind_file" "fzf --fish | source"102fi103104if [ -d "${fish_dir}/functions" ]; then105  remove "${fish_dir}/functions/fzf.fish"106  remove "${fish_dir}/functions/fzf_key_bindings.fish"107  remove_line "$bind_file" "source \"${fzf_base}/shell/completion.fish\""108  remove_line "$bind_file" "source \"${fzf_base}/shell/key-bindings.fish\""109110  if [ -z "$(ls -A "${fish_dir}/functions")" ]; then111    rmdir "${fish_dir}/functions"112  else113    echo "Can't delete non-empty directory: \"${fish_dir}/functions\""114  fi115fi116117if command -v nu > /dev/null; then118  nushell_autoload_dir=$(nu -c '$nu.user-autoload-dirs | first')119else120  nushell_autoload_dir=${XDG_CONFIG_HOME:-$HOME/.config}/nushell/autoload121fi122remove "${nushell_autoload_dir}/_fzf_integration.nu"123124config_dir=$(dirname "$prefix_expand")125if [[ $xdg == 1 ]] && [[ $config_dir == */fzf ]] && [[ -d $config_dir ]]; then126  rmdir "$config_dir"127fi