You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fzf/uninstall

70 lines
1.5 KiB
Plaintext

10 years ago
#!/bin/bash
confirm() {
while [ 1 ]; do
read -p "$1" -n 1 -r
echo
if [[ "$REPLY" =~ ^[Yy] ]]; then
return 0
elif [[ "$REPLY" =~ ^[Nn] ]]; then
return 1
fi
done
}
remove() {
echo "Remove $1"
rm -f "$1"
}
10 years ago
remove_line() {
src=$(readlink "$2")
if [ $? -eq 0 ]; then
echo "Remove from $2 ($src):"
else
src=$2
echo "Remove from $2:"
10 years ago
fi
line_no=1
match=0
while [ 1 ]; do
line=$(sed -n "$line_no,\$p" "$src" | grep -m1 -nF "$1") || break
match=1
line_no=$(( $(sed 's/:.*//' <<< "$line") + line_no - 1 ))
echo " - Line #$line_no: $(sed 's/^[0-9]*://' <<< "$line")"
confirm " - Remove (y/n) ? "
if [ $? -eq 0 ]; then
awk -v n=$line_no 'NR == n {next} {print}' "$src" > "$src.bak" &&
mv "$src.bak" "$src" || break
echo " - Removed"
else
echo " - Skipped"
line_no=$(( line_no + 1 ))
fi
10 years ago
done
[ $match -eq 0 ] && echo " - Nothing found"
10 years ago
echo
}
for shell in bash zsh; do
remove ~/.fzf.${shell}
10 years ago
remove_line "source ~/.fzf.${shell}" ~/.${shell}rc
done
bind_file=~/.config/fish/functions/fish_user_key_bindings.fish
if [ -f "$bind_file" ]; then
remove_line "fzf_key_bindings" "$bind_file"
fi
if [ -d ~/.config/fish/functions ]; then
remove ~/.config/fish/functions/fzf.fish
10 years ago
if [ "$(ls -A ~/.config/fish/functions)" ]; then
10 years ago
echo "Can't delete non-empty directory: \"~/.config/fish/functions\""
else
rmdir ~/.config/fish/functions
fi
10 years ago
fi
10 years ago