Merge pull request #588 from crazygit/upstream

add bulk enable or disable function
pull/602/head
Nils Winkler 2015-10-27 10:42:19 +01:00
commit 18836b1a0c
2 changed files with 42 additions and 59 deletions

View File

@ -51,10 +51,10 @@ _bash-it-comp()
COMPREPLY=() COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}" cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}" prev="${COMP_WORDS[COMP_CWORD-1]}"
chose_opt="${COMP_WORDS[1]}"
file_type="${COMP_WORDS[2]}"
opts="help show enable disable" opts="help show enable disable"
case "${chose_opt}" in
case "${prev}" in
show) show)
local show_args="plugins aliases completions" local show_args="plugins aliases completions"
COMPREPLY=( $(compgen -W "${show_args}" -- ${cur}) ) COMPREPLY=( $(compgen -W "${show_args}" -- ${cur}) )
@ -65,13 +65,30 @@ _bash-it-comp()
COMPREPLY=( $(compgen -W "${help_args}" -- ${cur}) ) COMPREPLY=( $(compgen -W "${help_args}" -- ${cur}) )
return 0 return 0
;; ;;
enable) enable | disable)
_bash-it-comp-enable-disable if [ x"${chose_opt}" == x"enable" ];then
return 0 suffix="available-not-enabled"
;; else
disable) suffix="enabled"
_bash-it-comp-enable-disable fi
return 0 case "${file_type}" in
alias)
_bash-it-comp-list-${suffix} aliases
return 0
;;
plugin)
_bash-it-comp-list-${suffix} plugins
return 0
;;
completion)
_bash-it-comp-list-${suffix} completion
return 0
;;
*)
_bash-it-comp-enable-disable
return 0
;;
esac
;; ;;
aliases) aliases)
prevprev="${COMP_WORDS[COMP_CWORD-2]}" prevprev="${COMP_WORDS[COMP_CWORD-2]}"
@ -83,48 +100,6 @@ _bash-it-comp()
;; ;;
esac esac
;; ;;
alias)
prevprev="${COMP_WORDS[COMP_CWORD-2]}"
case "${prevprev}" in
enable)
_bash-it-comp-list-available-not-enabled aliases
return 0
;;
disable)
_bash-it-comp-list-enabled aliases
return 0
;;
esac
;;
plugin)
prevprev="${COMP_WORDS[COMP_CWORD-2]}"
case "${prevprev}" in
enable)
_bash-it-comp-list-available-not-enabled plugins
return 0
;;
disable)
_bash-it-comp-list-enabled plugins
return 0
;;
esac
;;
completion)
prevprev="${COMP_WORDS[COMP_CWORD-2]}"
case "${prevprev}" in
enable)
_bash-it-comp-list-available-not-enabled completion
return 0
;;
disable)
_bash-it-comp-list-enabled completion
return 0
;;
esac
;;
esac esac
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )

View File

@ -37,8 +37,8 @@ bash-it ()
param '3: specific component [optional]' param '3: specific component [optional]'
example '$ bash-it show plugins' example '$ bash-it show plugins'
example '$ bash-it help aliases' example '$ bash-it help aliases'
example '$ bash-it enable plugin git' example '$ bash-it enable plugin git [tmux]...'
example '$ bash-it disable alias hg' example '$ bash-it disable alias hg [tmux]...'
typeset verb=${1:-} typeset verb=${1:-}
shift shift
typeset component=${1:-} typeset component=${1:-}
@ -72,7 +72,15 @@ bash-it ()
fi fi
fi fi
fi fi
$func $*
if [ x"$verb" == x"enable" -o x"$verb" == x"disable" ];then
for arg in "$@"
do
$func $arg
done
else
$func $*
fi
} }
_is_function () _is_function ()
@ -134,9 +142,9 @@ _bash-it-describe ()
printf "%-20s%-10s%s\n" "$(basename $f | cut -d'.' -f1)" " [$enabled]" "$(cat $f | metafor about-$file_type)" printf "%-20s%-10s%s\n" "$(basename $f | cut -d'.' -f1)" " [$enabled]" "$(cat $f | metafor about-$file_type)"
done done
printf '\n%s\n' "to enable $preposition $file_type, do:" printf '\n%s\n' "to enable $preposition $file_type, do:"
printf '%s\n' "$ bash-it enable $file_type <$file_type name> -or- $ bash-it enable $file_type all" printf '%s\n' "$ bash-it enable $file_type <$file_type name> [$file_type name]... -or- $ bash-it enable $file_type all"
printf '\n%s\n' "to disable $preposition $file_type, do:" printf '\n%s\n' "to disable $preposition $file_type, do:"
printf '%s\n' "$ bash-it disable $file_type <$file_type name> -or- $ bash-it disable $file_type all" printf '%s\n' "$ bash-it disable $file_type <$file_type name> [$file_type name]... -or- $ bash-it disable $file_type all"
} }
_disable-plugin () _disable-plugin ()
@ -198,7 +206,7 @@ _disable-thing ()
else else
typeset plugin=$(command ls $BASH_IT/$subdirectory/enabled/$file_entity.*bash 2>/dev/null | head -1) typeset plugin=$(command ls $BASH_IT/$subdirectory/enabled/$file_entity.*bash 2>/dev/null | head -1)
if [ -z "$plugin" ]; then if [ -z "$plugin" ]; then
printf '%s\n' "sorry, that does not appear to be an enabled $file_type." printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type."
return return
fi fi
rm $BASH_IT/$subdirectory/enabled/$(basename $plugin) rm $BASH_IT/$subdirectory/enabled/$(basename $plugin)
@ -267,7 +275,7 @@ _enable-thing ()
else else
typeset plugin=$(command ls $BASH_IT/$subdirectory/available/$file_entity.*bash 2>/dev/null | head -1) typeset plugin=$(command ls $BASH_IT/$subdirectory/available/$file_entity.*bash 2>/dev/null | head -1)
if [ -z "$plugin" ]; then if [ -z "$plugin" ]; then
printf '%s\n' "sorry, that does not appear to be an available $file_type." printf '%s\n' "sorry, $file_entity does not appear to be an available $file_type."
return return
fi fi