fzf/uninstall

71 lines
1.5 KiB
Plaintext
Raw Normal View History

2014-05-20 12:17:03 +00:00
#!/bin/bash
2014-05-21 17:26:59 +00:00
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"
}
2014-05-20 12:17:03 +00:00
remove_line() {
2014-05-20 16:14:21 +00:00
src=$(readlink "$2")
if [ $? -eq 0 ]; then
echo "Remove from $2 ($src):"
else
src=$2
echo "Remove from $2:"
2014-05-20 12:17:03 +00:00
fi
2014-05-20 16:14:21 +00:00
2014-05-21 17:26:59 +00:00
line_no=1
match=0
2014-05-20 16:14:21 +00:00
while [ 1 ]; do
2014-09-14 04:53:53 +00:00
line=$(sed -n "$line_no,\$p" "$src" | \grep -m1 -nF "$1") || break
2014-05-21 17:26:59 +00:00
line_no=$(( $(sed 's/:.*//' <<< "$line") + line_no - 1 ))
2014-05-21 17:34:20 +00:00
content=$(sed 's/^[0-9]*://' <<< "$line")
match=1
echo " - Line #$line_no: $content"
[ "$content" = "$1" ] || confirm " - Remove (y/n) ? "
2014-05-21 17:26:59 +00:00
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
2014-05-20 15:05:02 +00:00
done
2014-05-21 17:26:59 +00:00
[ $match -eq 0 ] && echo " - Nothing found"
2014-05-20 12:17:03 +00:00
echo
}
for shell in bash zsh; do
2014-05-21 17:26:59 +00:00
remove ~/.fzf.${shell}
# remove_line "source ~/.fzf.${shell}" ~/.${shell}rc
2014-05-20 12:17:03 +00:00
done
2014-05-20 16:14:21 +00:00
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
2014-05-21 17:26:59 +00:00
remove ~/.config/fish/functions/fzf.fish
2014-05-20 15:05:02 +00:00
2014-05-20 16:14:21 +00:00
if [ "$(ls -A ~/.config/fish/functions)" ]; then
2014-05-20 15:05:02 +00:00
echo "Can't delete non-empty directory: \"~/.config/fish/functions\""
else
rmdir ~/.config/fish/functions
fi
2014-05-20 12:17:03 +00:00
fi
2014-05-20 15:05:02 +00:00