Skip to content

Commit

Permalink
Replaced reload section with proper function.
Browse files Browse the repository at this point in the history
Added completion for reload.
Fixed order in completion
Added unit tests for completion
The variable BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE has to be unset.
  • Loading branch information
dracorp committed Apr 18, 2018
1 parent b1dbf2f commit 89d1661
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 42 deletions.
10 changes: 0 additions & 10 deletions bash_it.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
#!/usr/bin/env bash
# Initialize Bash It

# 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" ];
then
Expand Down
4 changes: 2 additions & 2 deletions completion/available/bash-it.completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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 reload"
opts="disable enable help migrate reload search show update version"
case "${chose_opt}" in
show)
local show_args="aliases completions plugins"
Expand All @@ -82,7 +82,7 @@ _bash-it-comp()
return 0
fi
;;
update | search | migrate | version | reload)
migrate | reload | search | update | version)
return 0
;;
enable | disable)
Expand Down
16 changes: 0 additions & 16 deletions lib/additionals.bash

This file was deleted.

2 changes: 1 addition & 1 deletion lib/composure.bash
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

composure_keywords ()
{
echo "about author example group param version"
echo "about author example group param reload version"
}

letterpress ()
Expand Down
28 changes: 22 additions & 6 deletions lib/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function reload_plugins() {
bash-it ()
{
about 'Bash-it help and maintenance'
param '1: verb [one of: help | show | enable | disable | migrate | update | search | version ] '
param '1: verb [one of: help | show | enable | disable | migrate | update | search | version | reload ] '
param '2: component type [one of: alias(es) | completion(s) | plugin(s) ] or search term(s)'
param '3: specific component [optional]'
example '$ bash-it show plugins'
Expand All @@ -72,6 +72,7 @@ bash-it ()
example '$ bash-it update'
example '$ bash-it search ruby [[-]rake]... [--enable | --disable]'
example '$ bash-it version'
example '$ bash-it reload'
typeset verb=${1:-}
shift
typeset component=${1:-}
Expand All @@ -95,8 +96,11 @@ bash-it ()
func=_bash-it-migrate;;
version)
func=_bash-it-version;;
reload)
func=_bash-it-reload;;
*)
func=_bash-it-additional-$verb $component "$@"
reference bash-it
return;;
esac

# pluralize component if necessary
Expand All @@ -106,10 +110,6 @@ 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
Expand Down Expand Up @@ -256,6 +256,22 @@ _bash-it-version() {
cd - &> /dev/null || return
}

_bash-it-reload() {
_about 'reloads a profile file'
_group 'lib'

cd "${BASH_IT}" || return

case $OSTYPE in
darwin*)
source ~/.bash_profile
;;
*)
source ~/.bashrc
;;
esac
}

_bash-it-describe ()
{
_about 'summarizes available bash_it components'
Expand Down
12 changes: 6 additions & 6 deletions test/completion/bash-it.completion.bats
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,32 @@ function __check_completion () {

@test "completion bash-it: show options" {
run __check_completion 'bash-it '
assert_line -n 0 "disable enable help migrate search show update version"
assert_line -n 0 "disable enable help migrate reload search show update version"
}

@test "completion bash-it: bash-ti - show options" {
run __check_completion 'bash-ti '
assert_line -n 0 "disable enable help migrate search show update version"
assert_line -n 0 "disable enable help migrate reload search show update version"
}

@test "completion bash-it: shit - show options" {
run __check_completion 'shit '
assert_line -n 0 "disable enable help migrate search show update version"
assert_line -n 0 "disable enable help migrate reload search show update version"
}

@test "completion bash-it: bashit - show options" {
run __check_completion 'bashit '
assert_line -n 0 "disable enable help migrate search show update version"
assert_line -n 0 "disable enable help migrate reload search show update version"
}

@test "completion bash-it: batshit - show options" {
run __check_completion 'batshit '
assert_line -n 0 "disable enable help migrate search show update version"
assert_line -n 0 "disable enable help migrate reload search show update version"
}

@test "completion bash-it: bash_it - show options" {
run __check_completion 'bash_it '
assert_line -n 0 "disable enable help migrate search show update version"
assert_line -n 0 "disable enable help migrate reload search show update version"
}

@test "completion bash-it: show - show options" {
Expand Down
2 changes: 1 addition & 1 deletion test/lib/composure.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ load ../../lib/composure

@test "lib composure: composure_keywords()" {
run composure_keywords
assert_output "about author example group param version"
assert_output "about author example group param reload version"
}
1 change: 1 addition & 0 deletions test/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ unset NGINX_PATH
unset IRC_CLIENT
unset TODO
unset SCM_CHECK
unset BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE

BASH_IT_TEST_DIR="${BATS_TMPDIR}/.bash_it"

Expand Down

0 comments on commit 89d1661

Please sign in to comment.