summaryrefslogtreecommitdiffstats
path: root/uninstall
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2014-05-22 02:26:59 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2014-05-22 02:26:59 +0900
commitc3827dea109b24b8f01b1d97c335c5349093a311 (patch)
tree2b7d17c1a035cac0bdbb142e82c9f27ab2b584d7 /uninstall
parent6a1b916598b887e307e083ce73382c8059ed616b (diff)
Add linewise user confirmation
Diffstat (limited to 'uninstall')
-rwxr-xr-xuninstall46
1 files changed, 35 insertions, 11 deletions
diff --git a/uninstall b/uninstall
index 202d8e31..faf11b84 100755
--- a/uninstall
+++ b/uninstall
@@ -1,5 +1,22 @@
#!/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"
+}
+
remove_line() {
src=$(readlink "$2")
if [ $? -eq 0 ]; then
@@ -8,23 +25,30 @@ remove_line() {
src=$2
echo "Remove from $2:"
fi
- echo " - $1"
- changed=0
+ line_no=1
+ match=0
while [ 1 ]; do
- line=$(grep -m1 -nF "$1" "$src") || break
- line_no=$(sed 's/:.*//' <<< "$line")
- echo " - Remove line ($line)"
- awk -v n=$line_no 'NR == n {next} {print}' "$src" > "$src.bak" &&
- mv "$src.bak" "$src" || break
- changed=1
+ 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
done
- [ $changed -eq 0 ] && echo " - Nothing found"
+ [ $match -eq 0 ] && echo " - Nothing found"
echo
}
for shell in bash zsh; do
- rm -f ~/.fzf.${shell}
+ remove ~/.fzf.${shell}
remove_line "source ~/.fzf.${shell}" ~/.${shell}rc
done
@@ -34,7 +58,7 @@ if [ -f "$bind_file" ]; then
fi
if [ -d ~/.config/fish/functions ]; then
- rm -f ~/.config/fish/functions/fzf.fish
+ remove ~/.config/fish/functions/fzf.fish
if [ "$(ls -A ~/.config/fish/functions)" ]; then
echo "Can't delete non-empty directory: \"~/.config/fish/functions\""