Skip to content

Commit

Permalink
[install/uninstall] Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
junegunn committed May 31, 2018
1 parent 4fe03fd commit 6c275d4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
18 changes: 8 additions & 10 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ update_config=2
binary_arch=
allow_legacy=
shells="bash zsh fish"
config_dir=~
config_filename=.fzf
config_prefix='~/.fzf'
prefix='~/.fzf'
prefix_expand=~/.fzf
fish_dir=${XDG_CONFIG_HOME:-$HOME/.config}/fish

help() {
Expand Down Expand Up @@ -49,10 +48,9 @@ for opt in "$@"; do
allow_legacy=1
;;
--xdg)
config_dir=${XDG_CONFIG_HOME:-$HOME/.config}/fzf
config_filename=fzf
config_prefix='"${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf'
mkdir -p "$config_dir"
prefix='"${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf'
prefix_expand=${XDG_CONFIG_HOME:-$HOME/.config}/fzf/fzf
mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/fzf"
;;
--key-bindings) key_bindings=1 ;;
--no-key-bindings) key_bindings=0 ;;
Expand Down Expand Up @@ -251,7 +249,7 @@ fi
echo
for shell in $shells; do
[[ "$shell" = fish ]] && continue
src=${config_dir}/${config_filename}.${shell}
src=${prefix_expand}.${shell}
echo -n "Generate $src ... "

fzf_completion="[[ \$- == *i* ]] && source \"$fzf_base/shell/completion.${shell}\" 2> /dev/null"
Expand Down Expand Up @@ -364,7 +362,7 @@ echo
for shell in $shells; do
[[ "$shell" = fish ]] && continue
[ $shell = zsh ] && dest=${ZDOTDIR:-~}/.zshrc || dest=~/.bashrc
append_line $update_config "[ -f ${config_prefix}.${shell} ] && source ${config_prefix}.${shell}" "$dest" "${config_prefix}.${shell}"
append_line $update_config "[ -f ${prefix}.${shell} ] && source ${prefix}.${shell}" "$dest" "${prefix}.${shell}"
done

if [ $key_bindings -eq 1 ] && [[ "$shells" =~ fish ]]; then
Expand All @@ -381,7 +379,7 @@ fi

if [ $update_config -eq 1 ]; then
echo 'Finished. Restart your shell or reload config file.'
[[ "$shells" =~ bash ]] && echo " source ~/.bashrc # bash"
[[ "$shells" =~ bash ]] && echo ' source ~/.bashrc # bash'
[[ "$shells" =~ zsh ]] && echo " source ${ZDOTDIR:-~}/.zshrc # zsh"
[[ "$shells" =~ fish ]] && [ $key_bindings -eq 1 ] && echo ' fzf_key_bindings # fish'
echo
Expand Down
21 changes: 11 additions & 10 deletions uninstall
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash

config_dir=~
config_filename=.fzf
config_prefix='~/.fzf'
xdg=0
prefix='~/.fzf'
prefix_expand=~/.fzf
fish_dir=${XDG_CONFIG_HOME:-$HOME/.config}/fish

help() {
Expand All @@ -21,9 +21,9 @@ for opt in "$@"; do
exit 0
;;
--xdg)
config_dir=${XDG_CONFIG_HOME:-$HOME/.config}/fzf
config_filename=fzf
config_prefix='"${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf'
xdg=1
prefix='"${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf'
prefix_expand=${XDG_CONFIG_HOME:-$HOME/.config}/fzf/fzf
;;
*)
echo "unknown option: $opt"
Expand Down Expand Up @@ -88,11 +88,11 @@ remove_line() {
}

for shell in bash zsh; do
shell_config=${config_dir}/${config_filename}.${shell}
shell_config=${prefix_expand}.${shell}
remove "${shell_config}"
remove_line ~/.${shell}rc \
"[ -f ${config_prefix}.${shell} ] && source ${config_prefix}.${shell}" \
"source ${config_prefix}.${shell}"
"[ -f ${prefix}.${shell} ] && source ${prefix}.${shell}" \
"source ${prefix}.${shell}"
done

bind_file="${fish_dir}/functions/fish_user_key_bindings.fish"
Expand All @@ -111,6 +111,7 @@ if [ -d "${fish_dir}/functions" ]; then
fi
fi

if [[ "$config_dir" = */fzf ]] && [[ -d "$config_dir" ]]; then
config_dir=$(dirname "$prefix_expand")
if [[ "$xdg" = 1 ]] && [[ "$config_dir" = */fzf ]] && [[ -d "$config_dir" ]]; then
rmdir "$config_dir"
fi

0 comments on commit 6c275d4

Please sign in to comment.