From 153a87d84a0580ed81589c68dd6b818d408b33e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20B=C3=B6ttger?= Date: Tue, 20 May 2014 14:17:03 +0200 Subject: [PATCH 1/3] uninstall script --- uninstall | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 uninstall diff --git a/uninstall b/uninstall new file mode 100755 index 0000000..0dddc65 --- /dev/null +++ b/uninstall @@ -0,0 +1,33 @@ +#!/bin/bash + +remove_line() { + echo "Remove from $2:" + echo " - $1" + line=$(grep -nF "$1" "$2" | sed 's/:.*//') + if [ -n "$line" ]; then + echo " - Remove line (line #$line)" + awk -v n=$line 'NR == n {next} {print}' $2 > $2.bak; mv $2.bak $2 + else + echo " - Nothing found" + fi + echo +} + +for shell in bash zsh; do + if [ -f ~/.fzf.${shell} ] + then + rm ~/.fzf.${shell} + fi + remove_line "source ~/.fzf.${shell}" ~/.${shell}rc + bind_file="~/.config/fish/functions/fish_user_key_bindings.fish" + if [ -f $bind_file ] + then + remove_line "fzf_key_bindings" "$bind_file" + fi +done + +if [ -f ~/.config/fish/functions/fzf.fish ] +then + rm ~/.config/fish/functions/fzf.fish +fi +rmdir --ignore-fail-on-non-empty ~/.config/fish/functions From 459c3323516830a7b0e5a3fda1719b820ac5de22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20B=C3=B6ttger?= Date: Tue, 20 May 2014 17:05:02 +0200 Subject: [PATCH 2/3] Some improvements --- uninstall | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/uninstall b/uninstall index 0dddc65..be69e15 100755 --- a/uninstall +++ b/uninstall @@ -3,13 +3,25 @@ remove_line() { echo "Remove from $2:" echo " - $1" - line=$(grep -nF "$1" "$2" | sed 's/:.*//') - if [ -n "$line" ]; then - echo " - Remove line (line #$line)" - awk -v n=$line 'NR == n {next} {print}' $2 > $2.bak; mv $2.bak $2 - else + + i=$(grep -c "$1" "$2") + if [ $i -eq 0 ] + then echo " - Nothing found" fi + + while [ $i -gt 0 ] + do + line=$(grep -m1 -nF "$1" "$2") + lineNumber=$(grep -m1 -nF "$1" "$2" | sed 's/:.*//') + if [ -n "$lineNumber" ]; then + echo " - Remove line ($line)" + awk -v n=$lineNumber 'NR == n {next} {print}' $2 > $2.bak && mv $2.bak $2 + else + echo " - Nothing found" + fi + i=`expr $i - 1` + done echo } @@ -26,8 +38,18 @@ for shell in bash zsh; do fi done -if [ -f ~/.config/fish/functions/fzf.fish ] +if [ -d ~/.config/fish/functions ] then - rm ~/.config/fish/functions/fzf.fish + if [ -f ~/.config/fish/functions/fzf.fish ] + then + rm ~/.config/fish/functions/fzf.fish + fi + + if [ "$(ls -A ~/.config/fish/functions)" ] + then + echo "Can't delete non-empty directory: \"~/.config/fish/functions\"" + else + rmdir ~/.config/fish/functions + fi fi -rmdir --ignore-fail-on-non-empty ~/.config/fish/functions + From f37be006c374392464bd1964fca4f2b227e8e07d Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 21 May 2014 01:14:21 +0900 Subject: [PATCH 3/3] Update uninstall script --- install | 2 +- uninstall | 62 +++++++++++++++++++++++-------------------------------- 2 files changed, 27 insertions(+), 37 deletions(-) diff --git a/install b/install index 7068dd2..ee86892 100755 --- a/install +++ b/install @@ -345,7 +345,7 @@ Finished. Restart your shell or reload config file. EOF [ $has_fish -eq 1 ] && echo " fzf_key_bindings # fish"; cat << EOF -To uninstall fzf, simply remove the added lines. +Use uninstall script to remove fzf. For more information, see: https://github.com/junegunn/fzf EOF diff --git a/uninstall b/uninstall index be69e15..202d8e3 100755 --- a/uninstall +++ b/uninstall @@ -1,52 +1,42 @@ #!/bin/bash remove_line() { - echo "Remove from $2:" - echo " - $1" - - i=$(grep -c "$1" "$2") - if [ $i -eq 0 ] - then - echo " - Nothing found" + src=$(readlink "$2") + if [ $? -eq 0 ]; then + echo "Remove from $2 ($src):" + else + src=$2 + echo "Remove from $2:" fi - - while [ $i -gt 0 ] - do - line=$(grep -m1 -nF "$1" "$2") - lineNumber=$(grep -m1 -nF "$1" "$2" | sed 's/:.*//') - if [ -n "$lineNumber" ]; then - echo " - Remove line ($line)" - awk -v n=$lineNumber 'NR == n {next} {print}' $2 > $2.bak && mv $2.bak $2 - else - echo " - Nothing found" - fi - i=`expr $i - 1` + echo " - $1" + + changed=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 done + [ $changed -eq 0 ] && echo " - Nothing found" echo } for shell in bash zsh; do - if [ -f ~/.fzf.${shell} ] - then - rm ~/.fzf.${shell} - fi + rm -f ~/.fzf.${shell} remove_line "source ~/.fzf.${shell}" ~/.${shell}rc - bind_file="~/.config/fish/functions/fish_user_key_bindings.fish" - if [ -f $bind_file ] - then - remove_line "fzf_key_bindings" "$bind_file" - fi done -if [ -d ~/.config/fish/functions ] -then - if [ -f ~/.config/fish/functions/fzf.fish ] - then - rm ~/.config/fish/functions/fzf.fish - fi +bind_file=~/.config/fish/functions/fish_user_key_bindings.fish +if [ -f "$bind_file" ]; then + remove_line "fzf_key_bindings" "$bind_file" +fi - if [ "$(ls -A ~/.config/fish/functions)" ] - then +if [ -d ~/.config/fish/functions ]; then + rm -f ~/.config/fish/functions/fzf.fish + + if [ "$(ls -A ~/.config/fish/functions)" ]; then echo "Can't delete non-empty directory: \"~/.config/fish/functions\"" else rmdir ~/.config/fish/functions