From b1dbf2f7e095fcbbba8cfc712ab1ca9d3402b739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Rogo=C5=BCa?= Date: Sat, 14 Apr 2018 00:49:20 +0200 Subject: [PATCH] Added additional parameter for bash-it: reload Added creating an alias if command does not exist --- bash_it.sh | 18 +++++++++--------- completion/available/bash-it.completion.bash | 4 ++-- lib/additionals.bash | 16 ++++++++++++++++ lib/helpers.bash | 7 +++++-- 4 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 lib/additionals.bash diff --git a/bash_it.sh b/bash_it.sh index 6e87100d..6b4be1b5 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -1,15 +1,15 @@ #!/usr/bin/env bash # Initialize Bash It -# Reload Library -case $OSTYPE in - darwin*) - alias reload='source ~/.bash_profile' - ;; - *) - alias reload='source ~/.bashrc' - ;; -esac +# Reload Library, replaced by lib/additionals.bash +# case $OSTYPE in +# darwin*) +# alias reload='source ~/.bash_profile' +# ;; +# *) +# alias reload='source ~/.bashrc' +# ;; +# esac # Only set $BASH_IT if it's not already set if [ -z "$BASH_IT" ]; diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 20a94e5b..914c81b7 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -65,7 +65,7 @@ _bash-it-comp() prev="${COMP_WORDS[COMP_CWORD-1]}" chose_opt="${COMP_WORDS[1]}" file_type="${COMP_WORDS[2]}" - opts="disable enable help migrate search show update version" + opts="disable enable help migrate search show update version reload" case "${chose_opt}" in show) local show_args="aliases completions plugins" @@ -82,7 +82,7 @@ _bash-it-comp() return 0 fi ;; - update | search | migrate | version) + update | search | migrate | version | reload) return 0 ;; enable | disable) diff --git a/lib/additionals.bash b/lib/additionals.bash new file mode 100644 index 00000000..f44c017a --- /dev/null +++ b/lib/additionals.bash @@ -0,0 +1,16 @@ +_bash-it-additional-reload() { + _about 'reloads ~/.bashrc' + + case $OSTYPE in + darwin*) + source ~/.bash_profile + ;; + *) + source ~/.bashrc + ;; + esac +} + +if ! command -v reload 1>/dev/null; then + alias reload=_bash-it-additional-reload +fi diff --git a/lib/helpers.bash b/lib/helpers.bash index 9693ea1a..658ffd0e 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -96,8 +96,7 @@ bash-it () version) func=_bash-it-version;; *) - reference bash-it - return;; + func=_bash-it-additional-$verb $component "$@" esac # pluralize component if necessary @@ -107,6 +106,10 @@ bash-it () else if _is_function ${func}es; then func=${func}es + elif [[ $func =~ ^_bash-it-additional- ]]; then + echo "oops! $verb is not valid additional command" + reference bash-it + return else echo "oops! $component is not a valid option!" reference bash-it