From b106d275a784b51ffd2ff03c8ac36d75b74c880f Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:14 +0200 Subject: [PATCH 01/65] Move enable/disable functionality to global enabled directory --- lib/helpers.bash | 27 ++++++++------- test/lib/helpers.bats | 77 +++++++++++++++++++++++++++++++++---------- 2 files changed, 75 insertions(+), 29 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 0184455e..184ee700 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -284,16 +284,21 @@ _disable-thing () fi done else - # Use a glob to search for both possible patterns - # 250---node.plugin.bash - # node.plugin.bash - # Either one will be matched by this glob - typeset plugin=$(command ls $ "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.*bash,$file_entity.*bash} 2>/dev/null | head -1) - if [ -z "$plugin" ]; then - printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type." - return + typeset plugin_global=$(command ls $ "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.*bash 2>/dev/null | head -1) + if [ -z "$plugin_global" ]; then + # Use a glob to search for both possible patterns + # 250---node.plugin.bash + # node.plugin.bash + # Either one will be matched by this glob + typeset plugin=$(command ls $ "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.*bash,$file_entity.*bash} 2>/dev/null | head -1) + if [ -z "$plugin" ]; then + printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type." + return + fi + rm "${BASH_IT}/$subdirectory/enabled/$(basename $plugin)" + else + rm "${BASH_IT}/enabled/$(basename $plugin_global)" fi - rm "${BASH_IT}/$subdirectory/enabled/$(basename $plugin)" fi if [ -n "$BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE" ]; then @@ -375,13 +380,13 @@ _enable-thing () return fi - mkdir -p "${BASH_IT}/$subdirectory/enabled" + mkdir -p "${BASH_IT}/enabled" # Load the priority from the file if it present there local local_file_priority=$(grep -E "^# BASH_IT_LOAD_PRIORITY:" "${BASH_IT}/$subdirectory/available/$to_enable" | awk -F': ' '{ print $2 }') local use_load_priority=${local_file_priority:-$load_priority} - ln -s ../available/$to_enable "${BASH_IT}/$subdirectory/enabled/${use_load_priority}${BASH_IT_LOAD_PRIORITY_SEPARATOR}${to_enable}" + ln -s ../$subdirectory/available/$to_enable "${BASH_IT}/enabled/${use_load_priority}${BASH_IT_LOAD_PRIORITY_SEPARATOR}${to_enable}" fi if [ -n "$BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE" ]; then diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 00b13b3a..d9bf1922 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -9,90 +9,107 @@ cite _about _param _example _group _author _version load ../../lib/helpers function local_setup { - mkdir -p $BASH_IT + mkdir -p "$BASH_IT" lib_directory="$(cd "$(dirname "$0")" && pwd)" - cp -r $lib_directory/../.. $BASH_IT - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/completion/enabled - mkdir -p $BASH_IT/plugins/enabled + cp -r $lib_directory/../.. "$BASH_IT" + + rm -rf "$BASH_IT"/enabled + rm -rf "$BASH_IT"/aliases/enabled + rm -rf "$BASH_IT"/completion/enabled + rm -rf "$BASH_IT"/plugins/enabled + + mkdir -p "$BASH_IT"/enabled + mkdir -p "$BASH_IT"/aliases/enabled + mkdir -p "$BASH_IT"/completion/enabled + mkdir -p "$BASH_IT"/plugins/enabled } @test "bash-it: enable the ansible aliases through the bash-it function" { run bash-it enable alias "ansible" assert_line "0" 'ansible enabled with priority 150.' - assert [ -L "$BASH_IT/aliases/enabled/150---ansible.aliases.bash" ] + assert [ -L "$BASH_IT/enabled/150---ansible.aliases.bash" ] } @test "bash-it: enable the todo.txt-cli aliases through the bash-it function" { run bash-it enable alias "todo.txt-cli" assert_line "0" 'todo.txt-cli enabled with priority 150.' - assert [ -L "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" ] + assert [ -L "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" ] } @test "bash-it: enable the curl aliases" { run _enable-alias "curl" assert_line "0" 'curl enabled with priority 150.' - assert [ -L "$BASH_IT/aliases/enabled/150---curl.aliases.bash" ] + assert [ -L "$BASH_IT/enabled/150---curl.aliases.bash" ] } @test "bash-it: enable the apm completion through the bash-it function" { run bash-it enable completion "apm" assert_line "0" 'apm enabled with priority 350.' - assert [ -L "$BASH_IT/completion/enabled/350---apm.completion.bash" ] + assert [ -L "$BASH_IT/enabled/350---apm.completion.bash" ] } @test "bash-it: enable the brew completion" { run _enable-completion "brew" assert_line "0" 'brew enabled with priority 350.' - assert [ -L "$BASH_IT/completion/enabled/350---brew.completion.bash" ] + assert [ -L "$BASH_IT/enabled/350---brew.completion.bash" ] } @test "bash-it: enable the node plugin" { run _enable-plugin "node" assert_line "0" 'node enabled with priority 250.' - assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] } @test "bash-it: enable the node plugin through the bash-it function" { run bash-it enable plugin "node" assert_line "0" 'node enabled with priority 250.' - assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] } @test "bash-it: enable the node and nvm plugins through the bash-it function" { run bash-it enable plugin "node" "nvm" assert_line "0" 'node enabled with priority 250.' assert_line "1" 'nvm enabled with priority 225.' - assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] - assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } @test "bash-it: enable the foo-unkown and nvm plugins through the bash-it function" { run bash-it enable plugin "foo-unknown" "nvm" assert_line "0" 'sorry, foo-unknown does not appear to be an available plugin.' assert_line "1" 'nvm enabled with priority 225.' - assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } @test "bash-it: enable the nvm plugin" { run _enable-plugin "nvm" assert_line "0" 'nvm enabled with priority 225.' - assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } @test "bash-it: enable an unknown plugin" { run _enable-plugin "unknown-foo" assert_line "0" 'sorry, unknown-foo does not appear to be an available plugin.' + + # Check for both old an new structure assert [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ] assert [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ] + + assert [ ! -L "$BASH_IT/enabled/250---unknown-foo.plugin.bash" ] + assert [ ! -L "$BASH_IT/enabled/unknown-foo.plugin.bash" ] } @test "bash-it: enable an unknown plugin through the bash-it function" { run bash-it enable plugin "unknown-foo" echo "${lines[@]}" assert_line "0" 'sorry, unknown-foo does not appear to be an available plugin.' + + # Check for both old an new structure assert [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ] assert [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ] + + assert [ ! -L "$BASH_IT/enabled/250---unknown-foo.plugin.bash" ] + assert [ ! -L "$BASH_IT/enabled/unknown-foo.plugin.bash" ] } @test "bash-it: disable a plugin that is not enabled" { @@ -103,11 +120,23 @@ function local_setup { @test "bash-it: enable and disable the nvm plugin" { run _enable-plugin "nvm" assert_line "0" 'nvm enabled with priority 225.' + assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + + run _disable-plugin "nvm" + assert_line "0" 'nvm disabled.' + assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] +} + +@test "bash-it: disable the nvm plugin if it was enabled with a priority, but in the component-specific directory" { + ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] run _disable-plugin "nvm" assert_line "0" 'nvm disabled.' assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } @test "bash-it: disable the nvm plugin if it was enabled without a priority" { @@ -127,16 +156,28 @@ function local_setup { assert_line "0" 'nvm is already enabled.' assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] +} + +@test "bash-it: enable the nvm plugin if it was enabled with a priority, but in the component-specific directory" { + ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + + run _enable-plugin "nvm" + assert_line "0" 'nvm is already enabled.' + assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } @test "bash-it: enable the nvm plugin twice" { run _enable-plugin "nvm" assert_line "0" 'nvm enabled with priority 225.' - assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] run _enable-plugin "nvm" assert_line "0" 'nvm is already enabled.' - assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } @test "bash-it: migrate enabled plugins that don't use the new priority-based configuration" { From 5f3627b9b7ddbab83e3fdd2c5f3616a69675cc5f Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:14 +0200 Subject: [PATCH 02/65] Change the enable/disable functions to use the global directory --- lib/helpers.bash | 19 +++++++++++++++++++ test/lib/helpers.bats | 35 ++++++++++++++++++++++++----------- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 184ee700..8fbdaf43 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -273,6 +273,7 @@ _disable-thing () if [ "$file_entity" = "all" ]; then typeset f $file_type + # Disable everything that's using the old structure for f in "${BASH_IT}/$subdirectory/available/"*.bash do plugin=$(basename $f) @@ -283,6 +284,18 @@ _disable-thing () rm "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $plugin) fi done + + local suffix=$(echo "$subdirectory" | sed -e 's/plugins/plugin/g') + + # Disable everything in the global "enabled" directory + for f in "${BASH_IT}/$subdirectory/available/"*.${suffix}.bash + do + plugin=$(basename $f) + + if [ -e "${BASH_IT}/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$plugin ]; then + rm "${BASH_IT}/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $plugin) + fi + done else typeset plugin_global=$(command ls $ "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.*bash 2>/dev/null | head -1) if [ -z "$plugin_global" ]; then @@ -380,6 +393,12 @@ _enable-thing () return fi + typeset enabled_plugin=$(command ls "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable 2>/dev/null | head -1) + if [ ! -z "$enabled_plugin" ] ; then + printf '%s\n' "$file_entity is already enabled." + return + fi + mkdir -p "${BASH_IT}/enabled" # Load the priority from the file if it present there diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index d9bf1922..7ab57ae7 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -11,7 +11,9 @@ load ../../lib/helpers function local_setup { mkdir -p "$BASH_IT" lib_directory="$(cd "$(dirname "$0")" && pwd)" - cp -r $lib_directory/../.. "$BASH_IT" + # Use rsync to copy Bash-it to the temp folder + # rsync is faster than cp, since we can exclude the large ".git" folder + rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../.. "$BASH_IT" rm -rf "$BASH_IT"/enabled rm -rf "$BASH_IT"/aliases/enabled @@ -24,12 +26,6 @@ function local_setup { mkdir -p "$BASH_IT"/plugins/enabled } -@test "bash-it: enable the ansible aliases through the bash-it function" { - run bash-it enable alias "ansible" - assert_line "0" 'ansible enabled with priority 150.' - assert [ -L "$BASH_IT/enabled/150---ansible.aliases.bash" ] -} - @test "bash-it: enable the todo.txt-cli aliases through the bash-it function" { run bash-it enable alias "todo.txt-cli" assert_line "0" 'todo.txt-cli enabled with priority 150.' @@ -58,6 +54,13 @@ function local_setup { run _enable-plugin "node" assert_line "0" 'node enabled with priority 250.' assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] + + # TODO Check for the link target - readlink + # target_path=$HOME/Code/slate/.slate.js + # + # if [ "`readlink $HOME/.slate.js`" -ef "$target_path" ]; then + # rm -rf "$HOME/.slate.js" + # fi } @test "bash-it: enable the node plugin through the bash-it function" { @@ -248,19 +251,29 @@ function local_setup { @test "bash-it: enable all plugins" { run _enable-plugin "all" local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l | xargs) - local enabled=$(find $BASH_IT/plugins/enabled -name [0-9]*.plugin.bash | wc -l | xargs) + local enabled=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) assert_equal "$available" "$enabled" } @test "bash-it: disable all plugins" { run _enable-plugin "all" local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l | xargs) - local enabled=$(find $BASH_IT/plugins/enabled -name [0-9]*.plugin.bash | wc -l | xargs) + local enabled=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) assert_equal "$available" "$enabled" + run _enable-alias "ag" + assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] + run _disable-plugin "all" - local enabled2=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) - assert_equal "$enabled2" "0" + local enabled2=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) + assert_equal "0" "$enabled2" + assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] +} + +@test "bash-it: enable the ansible aliases through the bash-it function" { + run bash-it enable alias "ansible" + assert_line "0" 'ansible enabled with priority 150.' + assert [ -L "$BASH_IT/enabled/150---ansible.aliases.bash" ] } @test "bash-it: describe the nvm plugin without enabling it" { From e705e6c60fdcf30c16ac8dec286fc95f35fffe87 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:14 +0200 Subject: [PATCH 03/65] Check for link target --- test/lib/helpers.bats | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 7ab57ae7..3eb031e4 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -55,12 +55,7 @@ function local_setup { assert_line "0" 'node enabled with priority 250.' assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] - # TODO Check for the link target - readlink - # target_path=$HOME/Code/slate/.slate.js - # - # if [ "`readlink $HOME/.slate.js`" -ef "$target_path" ]; then - # rm -rf "$HOME/.slate.js" - # fi + assert_equal "../plugins/available/node.plugin.bash" "`readlink $BASH_IT/enabled/250---node.plugin.bash`" } @test "bash-it: enable the node plugin through the bash-it function" { From f892269affdf555488ee7f8d4f7db05693bbb5cd Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:14 +0200 Subject: [PATCH 04/65] Fix reload function to use the old and the new directory --- lib/helpers.bash | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/helpers.bash b/lib/helpers.bash index 8fbdaf43..f41f49c8 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -16,6 +16,20 @@ function _load_bash_it_files() { fi done fi + + # In the new structure + if [ -d "${BASH_IT}/enabled" ] + then + local suffix=$(echo "$subdirectory" | sed -e 's/plugins/plugin/g') + + FILES="${BASH_IT}/enabled/*.${suffix}.bash" + for config_file in $FILES + do + if [ -e "${config_file}" ]; then + source $config_file + fi + done + fi } # Function for reloading aliases From 6fa235a82566fa5897a6ab73258f9f269f800e45 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:14 +0200 Subject: [PATCH 05/65] Start work on migration to global directory --- lib/helpers.bash | 3 --- test/lib/helpers.bats | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index f41f49c8..3020014b 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -186,8 +186,6 @@ _bash-it-migrate() { do typeset ff=$(basename $f) - # Only process the ones that don't use the new structure - if ! [[ $ff =~ ^[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR.*\.bash$ ]] ; then # Get the type of component from the extension typeset single_type=$(echo $ff | sed -e 's/.*\.\(.*\)\.bash/\1/g' | sed 's/aliases/alias/g') typeset component_name=$(echo $ff | cut -d'.' -f1) @@ -199,7 +197,6 @@ _bash-it-migrate() { $disable_func $component_name $enable_func $component_name - fi done shopt -u nullglob done diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 3eb031e4..67cdf024 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -207,10 +207,10 @@ function local_setup { @test "bash-it: run the migrate command without anything to migrate" { run _enable-plugin "ssh" - assert [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/250---ssh.plugin.bash" ] run _bash-it-migrate - assert [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/250---ssh.plugin.bash" ] } @test "bash-it: verify that existing components are automatically migrated when something is enabled" { From 2ac08cae0f12743eab7e34496a1b25faa312c6f5 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:14 +0200 Subject: [PATCH 06/65] Fix one migration case --- lib/helpers.bash | 20 ++++++++++---------- test/lib/helpers.bats | 34 +++++++++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 3020014b..4658ab51 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -186,17 +186,17 @@ _bash-it-migrate() { do typeset ff=$(basename $f) - # Get the type of component from the extension - typeset single_type=$(echo $ff | sed -e 's/.*\.\(.*\)\.bash/\1/g' | sed 's/aliases/alias/g') - typeset component_name=$(echo $ff | cut -d'.' -f1) + # Get the type of component from the extension + typeset single_type=$(echo $ff | sed -e 's/.*\.\(.*\)\.bash/\1/g' | sed 's/aliases/alias/g') + typeset component_name=$(echo $ff | cut -d'.' -f1) - echo "Migrating $single_type $component_name." + echo "Migrating $single_type $component_name." - disable_func="_disable-$single_type" - enable_func="_enable-$single_type" + disable_func="_disable-$single_type" + enable_func="_enable-$single_type" - $disable_func $component_name - $enable_func $component_name + $disable_func $component_name + $enable_func $component_name done shopt -u nullglob done @@ -404,8 +404,8 @@ _enable-thing () return fi - typeset enabled_plugin=$(command ls "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable 2>/dev/null | head -1) - if [ ! -z "$enabled_plugin" ] ; then + typeset enabled_plugin_global=$(command ls "${BASH_IT}/enabled/[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable" 2>/dev/null | head -1) + if [ ! -z "$enabled_plugin_global" ] ; then printf '%s\n' "$file_entity is already enabled." return fi diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 67cdf024..ac72634b 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -189,18 +189,42 @@ function local_setup { assert [ -L "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" ] run _enable-plugin "ssh" - assert [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/250---ssh.plugin.bash" ] run _bash-it-migrate - assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] - assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] - assert [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ] - assert [ -L "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" ] + + assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/250---ssh.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" ] assert [ ! -L "$BASH_IT/plugins/enabled/node.plugin.bash" ] assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] assert [ ! -L "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" ] } +@test "bash-it: migrate enabled plugins that use the new priority-based configuration in the individual directories" { + ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + + ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] + + ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/250---todo.txt-cli.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/250---todo.txt-cli.aliases.bash" ] + + run _enable-plugin "ssh" + assert [ -L "$BASH_IT/enabled/250---ssh.plugin.bash" ] + + run _bash-it-migrate + assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/250---ssh.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" ] + assert [ ! -L "$BASH_IT/plugins/enabled/225----node.plugin.bash" ] + assert [ ! -L "$BASH_IT/plugins/enabled/250----nvm.plugin.bash" ] + assert [ ! -L "$BASH_IT/aliases/enabled/250----todo.txt-cli.aliases.bash" ] +} + @test "bash-it: run the migrate command without anything to migrate and nothing enabled" { run _bash-it-migrate } From 7242cc0927897d92962da411f0a0811f330d20ac Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:14 +0200 Subject: [PATCH 07/65] Fix glob expression for finding enabled components --- lib/helpers.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 4658ab51..c275459f 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -398,13 +398,13 @@ _enable-thing () to_enable=$(basename $to_enable) # Check for existence of the file using a wildcard, since we don't know which priority might have been used when enabling it. - typeset enabled_plugin=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable,$to_enable} 2>/dev/null | head -1) + typeset enabled_plugin=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable,$to_enable} 2>/dev/null | head -1) if [ ! -z "$enabled_plugin" ] ; then printf '%s\n' "$file_entity is already enabled." return fi - typeset enabled_plugin_global=$(command ls "${BASH_IT}/enabled/[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable" 2>/dev/null | head -1) + typeset enabled_plugin_global=$(command ls "${BASH_IT}/enabled/"[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable 2>/dev/null | head -1) if [ ! -z "$enabled_plugin_global" ] ; then printf '%s\n' "$file_entity is already enabled." return From 375515cc6e8e6d3439a3f72bfdfdde96b067f3ab Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:14 +0200 Subject: [PATCH 08/65] Use compgen -G instead of ls for finding enabled components Reference: https://stackoverflow.com/a/34195247/1228454 --- lib/helpers.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index c275459f..d736e96d 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -404,7 +404,7 @@ _enable-thing () return fi - typeset enabled_plugin_global=$(command ls "${BASH_IT}/enabled/"[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable 2>/dev/null | head -1) + typeset enabled_plugin_global=$(command compgen -G "${BASH_IT}/enabled/[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable" 2>/dev/null | head -1) if [ ! -z "$enabled_plugin_global" ] ; then printf '%s\n' "$file_entity is already enabled." return From f72691fe85919efa38445d14d4d7032a3f3c3d23 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:14 +0200 Subject: [PATCH 09/65] Fix some more migration test cases --- test/lib/helpers.bats | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index ac72634b..c77d03f6 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -247,8 +247,8 @@ function local_setup { assert_line "2" 'nvm enabled with priority 225.' assert_line "3" 'node enabled with priority 250.' assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] - assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] - assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] } @test "bash-it: verify that existing components are automatically migrated when something is disabled" { @@ -263,8 +263,9 @@ function local_setup { assert_line "2" 'nvm enabled with priority 225.' assert_line "3" 'node disabled.' assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] - assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] assert [ ! -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] } @test "bash-it: enable all plugins" { From fd686cc2ae703bab986a577fd89d2d126da2ae34 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:14 +0200 Subject: [PATCH 10/65] Fix one more path --- test/lib/helpers.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index c77d03f6..6c671a27 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -303,7 +303,7 @@ function local_setup { @test "bash-it: describe the nvm plugin after enabling it" { run _enable-plugin "nvm" assert_line "0" 'nvm enabled with priority 225.' - assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] _bash-it-plugins | grep "nvm" | grep "\[x\]" } From 591c8a67f38661ba3cac641b408045e808efc62e Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:14 +0200 Subject: [PATCH 11/65] Support both enabled formats during migration --- lib/helpers.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index d736e96d..ea37dac3 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -188,7 +188,8 @@ _bash-it-migrate() { # Get the type of component from the extension typeset single_type=$(echo $ff | sed -e 's/.*\.\(.*\)\.bash/\1/g' | sed 's/aliases/alias/g') - typeset component_name=$(echo $ff | cut -d'.' -f1) + # Cut off the optional "250---" prefix and the suffix + typeset component_name=$(echo $ff | sed -e 's/[0-9]*[-]*\(.*\)\..*\.bash/\1/g') echo "Migrating $single_type $component_name." From 2b778ccbbae8a65c8cfacea8bb28d27c452e52fc Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:14 +0200 Subject: [PATCH 12/65] Fix disable/migrate test case --- test/lib/helpers.bats | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 6c671a27..e7f8e237 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -258,14 +258,17 @@ function local_setup { assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] run bash-it disable plugin "node" - assert_line "0" 'Migrating plugin nvm.' - assert_line "1" 'nvm disabled.' - assert_line "2" 'nvm enabled with priority 225.' - assert_line "3" 'node disabled.' + assert_line "0" 'Migrating plugin node.' + assert_line "1" 'node disabled.' + assert_line "2" 'node enabled with priority 250.' + assert_line "3" 'Migrating plugin nvm.' + assert_line "4" 'nvm disabled.' + assert_line "5" 'nvm enabled with priority 225.' + assert_line "6" 'node disabled.' assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] assert [ ! -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] - assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] + assert [ ! -L "$BASH_IT/enabled/250---node.plugin.bash" ] } @test "bash-it: enable all plugins" { From 9080f0e86998b23b3e5b8905b29255b08a927f09 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:15 +0200 Subject: [PATCH 13/65] Add more tests for migration scenario --- test/lib/helpers.bats | 77 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index e7f8e237..14d45b0e 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -26,6 +26,10 @@ function local_setup { mkdir -p "$BASH_IT"/plugins/enabled } +# TODO Create global __is_enabled function +# TODO Create global __get_base_name function +# TODO Create global __get_enabled_name function + @test "bash-it: enable the todo.txt-cli aliases through the bash-it function" { run bash-it enable alias "todo.txt-cli" assert_line "0" 'todo.txt-cli enabled with priority 150.' @@ -237,6 +241,79 @@ function local_setup { assert [ -L "$BASH_IT/enabled/250---ssh.plugin.bash" ] } +function __migrate_all_components() { + subdirectory="$1" + one_type="$2" + priority="$3" + + for f in "${BASH_IT}/$subdirectory/available/"*.bash + do + to_enable=$(basename $f) + if [ -z "$priority" ]; then + ln -s "../available/$to_enable" "${BASH_IT}/${subdirectory}/enabled/$to_enable" + else + ln -s "../available/$to_enable" "${BASH_IT}/${subdirectory}/enabled/$priority---$to_enable" + fi + done + + ls ${BASH_IT}/${subdirectory}/enabled + + all_available=$(compgen -G "${BASH_IT}/${subdirectory}/available/*.$one_type.bash" | wc -l) + all_enabled_old=$(compgen -G "${BASH_IT}/${subdirectory}/enabled/*.$one_type.bash" | wc -l) + + assert_equal "$all_available" "$all_enabled_old" + + run bash-it migrate + + all_enabled_old_after=$(compgen -G "${BASH_IT}/${subdirectory}/enabled/*.$one_type.bash" | wc -l) + assert_equal "0" "$all_enabled_old_after" + + all_enabled_new_after=$(compgen -G "${BASH_IT}/enabled/*.$one_type.bash" | wc -l) + assert_equal "$all_enabled_old" "$all_enabled_new_after" +} + +@test "bash-it: migrate all plugins" { + subdirectory="plugins" + one_type="plugin" + + __migrate_all_components "$subdirectory" "$one_type" +} + +@test "bash-it: migrate all aliases" { + subdirectory="aliases" + one_type="aliases" + + __migrate_all_components "$subdirectory" "$one_type" +} + +@test "bash-it: migrate all completions" { + subdirectory="completion" + one_type="completion" + + __migrate_all_components "$subdirectory" "$one_type" +} + +@test "bash-it: migrate all plugins with previous priority" { + subdirectory="plugins" + one_type="plugin" + + __migrate_all_components "$subdirectory" "$one_type" "100" +} + +@test "bash-it: migrate all aliases with previous priority" { + subdirectory="aliases" + one_type="aliases" + + __migrate_all_components "$subdirectory" "$one_type" "100" +} + +@test "bash-it: migrate all completions with previous priority" { + subdirectory="completion" + one_type="completion" + + __migrate_all_components "$subdirectory" "$one_type" "100" +} + @test "bash-it: verify that existing components are automatically migrated when something is enabled" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] From 9f3ef22538e9dcedaadfb4e66f20d51dde48fdfe Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:15 +0200 Subject: [PATCH 14/65] Describe function supports new directory structure --- lib/helpers.bash | 2 +- test/lib/helpers.bats | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index ea37dac3..16b31946 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -223,7 +223,7 @@ _bash-it-describe () for f in "${BASH_IT}/$subdirectory/available/"*.bash do # Check for both the old format without the load priority, and the extended format with the priority - if [ -e "${BASH_IT}/$subdirectory/enabled/"$(basename $f) ] || [ -e "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ]; then + if [ -e "${BASH_IT}/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ] || [ -e "${BASH_IT}/$subdirectory/enabled/"$(basename $f) ] || [ -e "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ]; then enabled='x' else enabled=' ' diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 14d45b0e..a3900963 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -388,6 +388,20 @@ function __migrate_all_components() { _bash-it-plugins | grep "nvm" | grep "\[x\]" } +@test "bash-it: describe the nvm plugin after enabling it in the old directory" { + ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + + _bash-it-plugins | grep "nvm" | grep "\[x\]" +} + +@test "bash-it: describe the nvm plugin after enabling it in the old directory with priority" { + ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + + _bash-it-plugins | grep "nvm" | grep "\[x\]" +} + @test "bash-it: describe the todo.txt-cli aliases without enabling them" { run _bash-it-aliases assert_line "todo.txt-cli [ ] todo.txt-cli abbreviations" From 2a16a5cd68195809e9d76588c2a5074805a18167 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:15 +0200 Subject: [PATCH 15/65] Change install setup to use rsync instead of cp --- test/install/install.bats | 12 +++++++++--- test/install/uninstall.bats | 11 +++++++++-- test/lib/search.bats | 11 +++++++++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/test/install/install.bats b/test/install/install.bats index ded2689a..dc560760 100644 --- a/test/install/install.bats +++ b/test/install/install.bats @@ -14,10 +14,16 @@ case $OSTYPE in esac function local_setup { - mkdir -p $BASH_IT + mkdir -p "$BASH_IT" lib_directory="$(cd "$(dirname "$0")" && pwd)" - cp -r $lib_directory/../../* $BASH_IT/ - rm -rf "$BASH_IT/aliases/enabled" "$BASH_IT/completion/enabled" "$BASH_IT/plugins/enabled" + # Use rsync to copy Bash-it to the temp folder + # rsync is faster than cp, since we can exclude the large ".git" folder + rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../.. "$BASH_IT" + + rm -rf "$BASH_IT"/enabled + rm -rf "$BASH_IT"/aliases/enabled + rm -rf "$BASH_IT"/completion/enabled + rm -rf "$BASH_IT"/plugins/enabled # Don't pollute the user's actual $HOME directory # Use a test home directory instead diff --git a/test/install/uninstall.bats b/test/install/uninstall.bats index adab216f..6c7ae561 100644 --- a/test/install/uninstall.bats +++ b/test/install/uninstall.bats @@ -14,9 +14,16 @@ case $OSTYPE in esac function local_setup { - mkdir -p $BASH_IT + mkdir -p "$BASH_IT" lib_directory="$(cd "$(dirname "$0")" && pwd)" - cp -r $lib_directory/../../* $BASH_IT/ + # Use rsync to copy Bash-it to the temp folder + # rsync is faster than cp, since we can exclude the large ".git" folder + rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../.. "$BASH_IT" + + rm -rf "$BASH_IT"/enabled + rm -rf "$BASH_IT"/aliases/enabled + rm -rf "$BASH_IT"/completion/enabled + rm -rf "$BASH_IT"/plugins/enabled # Don't pollute the user's actual $HOME directory # Use a test home directory instead diff --git a/test/lib/search.bats b/test/lib/search.bats index 71a176d4..28b25d25 100644 --- a/test/lib/search.bats +++ b/test/lib/search.bats @@ -13,9 +13,16 @@ load ../../lib/search NO_COLOR=true function local_setup { - mkdir -p $BASH_IT + mkdir -p "$BASH_IT" lib_directory="$(cd "$(dirname "$0")" && pwd)" - cp -r $lib_directory/../../* $BASH_IT/ + # Use rsync to copy Bash-it to the temp folder + # rsync is faster than cp, since we can exclude the large ".git" folder + rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../.. "$BASH_IT" + + rm -rf "$BASH_IT"/enabled + rm -rf "$BASH_IT"/aliases/enabled + rm -rf "$BASH_IT"/completion/enabled + rm -rf "$BASH_IT"/plugins/enabled } @test "helpers search plugins" { From 9e99c8cb3d06d399c41efb2b52e24819b25eb01e Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:15 +0200 Subject: [PATCH 16/65] Adjust install test case --- test/install/install.bats | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/install/install.bats b/test/install/install.bats index dc560760..acb41e0a 100644 --- a/test/install/install.bats +++ b/test/install/install.bats @@ -52,11 +52,11 @@ function local_teardown { assert [ -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" ] - assert [ -L "$BASH_IT/aliases/enabled/150---general.aliases.bash" ] - assert [ -L "$BASH_IT/plugins/enabled/250---base.plugin.bash" ] - assert [ -L "$BASH_IT/plugins/enabled/365---alias-completion.plugin.bash" ] - assert [ -L "$BASH_IT/completion/enabled/350---bash-it.completion.bash" ] - assert [ -L "$BASH_IT/completion/enabled/350---system.completion.bash" ] + assert [ -L "$BASH_IT/enabled/150---general.aliases.bash" ] + assert [ -L "$BASH_IT/enabled/250---base.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/365---alias-completion.plugin.bash" ] + assert [ -L "$BASH_IT/enabled/350---bash-it.completion.bash" ] + assert [ -L "$BASH_IT/enabled/350---system.completion.bash" ] } @test "install: verify that a backup file is created" { From e53b5dc96efa2b8b7a7ebba677834fc1393bd032 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:15 +0200 Subject: [PATCH 17/65] Add some TODO items --- bash_it.sh | 3 +++ test/run | 2 ++ 2 files changed, 5 insertions(+) diff --git a/bash_it.sh b/bash_it.sh index 5581dd00..599e0aaf 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -44,7 +44,10 @@ do fi done +# TODO Automatically check for content that needs to be migrated + # Load enabled aliases, completion, plugins +# TODO Add new global directory structure for file_type in "aliases" "plugins" "completion" do _load_bash_it_files $file_type diff --git a/test/run b/test/run index 737f17e2..389a20ae 100755 --- a/test/run +++ b/test/run @@ -9,4 +9,6 @@ if [ -z "${BASH_IT}" ]; then export BASH_IT=$(cd ${test_directory} && dirname $(pwd)) fi +# TODO Add tests for bash-it completion + exec $bats_executable ${CI:+--tap} ${test_directory}/{install,lib,plugins,themes} From d798bb8f068717bc4bd034b0d69822c10e5c85e4 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:15 +0200 Subject: [PATCH 18/65] Change test prefixes to match file name --- test/lib/helpers.bats | 76 +++++++++++++++++++++---------------------- test/lib/search.bats | 10 +++--- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index a3900963..fd38ad69 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -30,31 +30,31 @@ function local_setup { # TODO Create global __get_base_name function # TODO Create global __get_enabled_name function -@test "bash-it: enable the todo.txt-cli aliases through the bash-it function" { +@test "helpers: enable the todo.txt-cli aliases through the bash-it function" { run bash-it enable alias "todo.txt-cli" assert_line "0" 'todo.txt-cli enabled with priority 150.' assert [ -L "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" ] } -@test "bash-it: enable the curl aliases" { +@test "helpers: enable the curl aliases" { run _enable-alias "curl" assert_line "0" 'curl enabled with priority 150.' assert [ -L "$BASH_IT/enabled/150---curl.aliases.bash" ] } -@test "bash-it: enable the apm completion through the bash-it function" { +@test "helpers: enable the apm completion through the bash-it function" { run bash-it enable completion "apm" assert_line "0" 'apm enabled with priority 350.' assert [ -L "$BASH_IT/enabled/350---apm.completion.bash" ] } -@test "bash-it: enable the brew completion" { +@test "helpers: enable the brew completion" { run _enable-completion "brew" assert_line "0" 'brew enabled with priority 350.' assert [ -L "$BASH_IT/enabled/350---brew.completion.bash" ] } -@test "bash-it: enable the node plugin" { +@test "helpers: enable the node plugin" { run _enable-plugin "node" assert_line "0" 'node enabled with priority 250.' assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] @@ -62,13 +62,13 @@ function local_setup { assert_equal "../plugins/available/node.plugin.bash" "`readlink $BASH_IT/enabled/250---node.plugin.bash`" } -@test "bash-it: enable the node plugin through the bash-it function" { +@test "helpers: enable the node plugin through the bash-it function" { run bash-it enable plugin "node" assert_line "0" 'node enabled with priority 250.' assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] } -@test "bash-it: enable the node and nvm plugins through the bash-it function" { +@test "helpers: enable the node and nvm plugins through the bash-it function" { run bash-it enable plugin "node" "nvm" assert_line "0" 'node enabled with priority 250.' assert_line "1" 'nvm enabled with priority 225.' @@ -76,20 +76,20 @@ function local_setup { assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } -@test "bash-it: enable the foo-unkown and nvm plugins through the bash-it function" { +@test "helpers: enable the foo-unkown and nvm plugins through the bash-it function" { run bash-it enable plugin "foo-unknown" "nvm" assert_line "0" 'sorry, foo-unknown does not appear to be an available plugin.' assert_line "1" 'nvm enabled with priority 225.' assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } -@test "bash-it: enable the nvm plugin" { +@test "helpers: enable the nvm plugin" { run _enable-plugin "nvm" assert_line "0" 'nvm enabled with priority 225.' assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } -@test "bash-it: enable an unknown plugin" { +@test "helpers: enable an unknown plugin" { run _enable-plugin "unknown-foo" assert_line "0" 'sorry, unknown-foo does not appear to be an available plugin.' @@ -101,7 +101,7 @@ function local_setup { assert [ ! -L "$BASH_IT/enabled/unknown-foo.plugin.bash" ] } -@test "bash-it: enable an unknown plugin through the bash-it function" { +@test "helpers: enable an unknown plugin through the bash-it function" { run bash-it enable plugin "unknown-foo" echo "${lines[@]}" assert_line "0" 'sorry, unknown-foo does not appear to be an available plugin.' @@ -114,12 +114,12 @@ function local_setup { assert [ ! -L "$BASH_IT/enabled/unknown-foo.plugin.bash" ] } -@test "bash-it: disable a plugin that is not enabled" { +@test "helpers: disable a plugin that is not enabled" { run _disable-plugin "sdkman" assert_line "0" 'sorry, sdkman does not appear to be an enabled plugin.' } -@test "bash-it: enable and disable the nvm plugin" { +@test "helpers: enable and disable the nvm plugin" { run _enable-plugin "nvm" assert_line "0" 'nvm enabled with priority 225.' assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] @@ -130,7 +130,7 @@ function local_setup { assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } -@test "bash-it: disable the nvm plugin if it was enabled with a priority, but in the component-specific directory" { +@test "helpers: disable the nvm plugin if it was enabled with a priority, but in the component-specific directory" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] @@ -141,7 +141,7 @@ function local_setup { assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } -@test "bash-it: disable the nvm plugin if it was enabled without a priority" { +@test "helpers: disable the nvm plugin if it was enabled without a priority" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] @@ -150,7 +150,7 @@ function local_setup { assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] } -@test "bash-it: enable the nvm plugin if it was enabled without a priority" { +@test "helpers: enable the nvm plugin if it was enabled without a priority" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] @@ -161,7 +161,7 @@ function local_setup { assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } -@test "bash-it: enable the nvm plugin if it was enabled with a priority, but in the component-specific directory" { +@test "helpers: enable the nvm plugin if it was enabled with a priority, but in the component-specific directory" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] @@ -172,7 +172,7 @@ function local_setup { assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } -@test "bash-it: enable the nvm plugin twice" { +@test "helpers: enable the nvm plugin twice" { run _enable-plugin "nvm" assert_line "0" 'nvm enabled with priority 225.' assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] @@ -182,7 +182,7 @@ function local_setup { assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } -@test "bash-it: migrate enabled plugins that don't use the new priority-based configuration" { +@test "helpers: migrate enabled plugins that don't use the new priority-based configuration" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] @@ -206,7 +206,7 @@ function local_setup { assert [ ! -L "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" ] } -@test "bash-it: migrate enabled plugins that use the new priority-based configuration in the individual directories" { +@test "helpers: migrate enabled plugins that use the new priority-based configuration in the individual directories" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] @@ -229,11 +229,11 @@ function local_setup { assert [ ! -L "$BASH_IT/aliases/enabled/250----todo.txt-cli.aliases.bash" ] } -@test "bash-it: run the migrate command without anything to migrate and nothing enabled" { +@test "helpers: run the migrate command without anything to migrate and nothing enabled" { run _bash-it-migrate } -@test "bash-it: run the migrate command without anything to migrate" { +@test "helpers: run the migrate command without anything to migrate" { run _enable-plugin "ssh" assert [ -L "$BASH_IT/enabled/250---ssh.plugin.bash" ] @@ -272,49 +272,49 @@ function __migrate_all_components() { assert_equal "$all_enabled_old" "$all_enabled_new_after" } -@test "bash-it: migrate all plugins" { +@test "helpers: migrate all plugins" { subdirectory="plugins" one_type="plugin" __migrate_all_components "$subdirectory" "$one_type" } -@test "bash-it: migrate all aliases" { +@test "helpers: migrate all aliases" { subdirectory="aliases" one_type="aliases" __migrate_all_components "$subdirectory" "$one_type" } -@test "bash-it: migrate all completions" { +@test "helpers: migrate all completions" { subdirectory="completion" one_type="completion" __migrate_all_components "$subdirectory" "$one_type" } -@test "bash-it: migrate all plugins with previous priority" { +@test "helpers: migrate all plugins with previous priority" { subdirectory="plugins" one_type="plugin" __migrate_all_components "$subdirectory" "$one_type" "100" } -@test "bash-it: migrate all aliases with previous priority" { +@test "helpers: migrate all aliases with previous priority" { subdirectory="aliases" one_type="aliases" __migrate_all_components "$subdirectory" "$one_type" "100" } -@test "bash-it: migrate all completions with previous priority" { +@test "helpers: migrate all completions with previous priority" { subdirectory="completion" one_type="completion" __migrate_all_components "$subdirectory" "$one_type" "100" } -@test "bash-it: verify that existing components are automatically migrated when something is enabled" { +@test "helpers: verify that existing components are automatically migrated when something is enabled" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] @@ -328,7 +328,7 @@ function __migrate_all_components() { assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] } -@test "bash-it: verify that existing components are automatically migrated when something is disabled" { +@test "helpers: verify that existing components are automatically migrated when something is disabled" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash @@ -348,14 +348,14 @@ function __migrate_all_components() { assert [ ! -L "$BASH_IT/enabled/250---node.plugin.bash" ] } -@test "bash-it: enable all plugins" { +@test "helpers: enable all plugins" { run _enable-plugin "all" local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l | xargs) local enabled=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) assert_equal "$available" "$enabled" } -@test "bash-it: disable all plugins" { +@test "helpers: disable all plugins" { run _enable-plugin "all" local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l | xargs) local enabled=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) @@ -370,17 +370,17 @@ function __migrate_all_components() { assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] } -@test "bash-it: enable the ansible aliases through the bash-it function" { +@test "helpers: enable the ansible aliases through the bash-it function" { run bash-it enable alias "ansible" assert_line "0" 'ansible enabled with priority 150.' assert [ -L "$BASH_IT/enabled/150---ansible.aliases.bash" ] } -@test "bash-it: describe the nvm plugin without enabling it" { +@test "helpers: describe the nvm plugin without enabling it" { _bash-it-plugins | grep "nvm" | grep "\[ \]" } -@test "bash-it: describe the nvm plugin after enabling it" { +@test "helpers: describe the nvm plugin after enabling it" { run _enable-plugin "nvm" assert_line "0" 'nvm enabled with priority 225.' assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] @@ -388,21 +388,21 @@ function __migrate_all_components() { _bash-it-plugins | grep "nvm" | grep "\[x\]" } -@test "bash-it: describe the nvm plugin after enabling it in the old directory" { +@test "helpers: describe the nvm plugin after enabling it in the old directory" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] _bash-it-plugins | grep "nvm" | grep "\[x\]" } -@test "bash-it: describe the nvm plugin after enabling it in the old directory with priority" { +@test "helpers: describe the nvm plugin after enabling it in the old directory with priority" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] _bash-it-plugins | grep "nvm" | grep "\[x\]" } -@test "bash-it: describe the todo.txt-cli aliases without enabling them" { +@test "helpers: describe the todo.txt-cli aliases without enabling them" { run _bash-it-aliases assert_line "todo.txt-cli [ ] todo.txt-cli abbreviations" } diff --git a/test/lib/search.bats b/test/lib/search.bats index 28b25d25..e00feee5 100644 --- a/test/lib/search.bats +++ b/test/lib/search.bats @@ -25,12 +25,12 @@ function local_setup { rm -rf "$BASH_IT"/plugins/enabled } -@test "helpers search plugins" { +@test "search: plugin base" { run _bash-it-search-component 'plugins' 'base' [[ "${lines[0]}" =~ 'plugins' && "${lines[0]}" =~ 'base' ]] } -@test "helpers search ruby gem bundle rake rails" { +@test "search: ruby gem bundle rake rails" { # first disable them all, so that the output does not appear with a checkbox # and we can compare the result run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' '--disable' @@ -42,7 +42,7 @@ function local_setup { assert [ "${lines[2]/✓/}" == ' completions => bundler gem rake' ] } -@test "search ruby gem bundle -chruby rake rails" { +@test "search: ruby gem bundle -chruby rake rails" { run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' '--disable' run _bash-it-search 'ruby' 'gem' 'bundle' '-chruby' 'rake' 'rails' assert [ "${lines[0]/✓/}" == ' aliases => bundler rails' ] @@ -50,7 +50,7 @@ function local_setup { assert [ "${lines[2]/✓/}" == ' completions => bundler gem rake' ] } -@test "search (rails enabled) ruby gem bundle rake rails" { +@test "search: (rails enabled) ruby gem bundle rake rails" { run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' '--disable' run _enable-alias 'rails' run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' @@ -59,7 +59,7 @@ function local_setup { assert_line "2" ' completions => bundler gem rake' } -@test "search (all enabled) ruby gem bundle rake rails" { +@test "search: (all enabled) ruby gem bundle rake rails" { run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' '-chruby' 'rails' '--enable' run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' '-chruby' 'rails' assert_line "0" ' aliases => ✓bundler ✓rails' From 6981fa091d4b979e2a1ca8457e61f459779008bf Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:15 +0200 Subject: [PATCH 19/65] Add tests for bash_it.sh script --- bash_it.sh | 1 - test/bash_it/bash_it.bats | 85 +++++++++++++++++++++++++++++++++++++++ test/run | 2 +- 3 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 test/bash_it/bash_it.bats diff --git a/bash_it.sh b/bash_it.sh index 599e0aaf..fbb37f62 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -47,7 +47,6 @@ done # TODO Automatically check for content that needs to be migrated # Load enabled aliases, completion, plugins -# TODO Add new global directory structure for file_type in "aliases" "plugins" "completion" do _load_bash_it_files $file_type diff --git a/test/bash_it/bash_it.bats b/test/bash_it/bash_it.bats new file mode 100644 index 00000000..3fc5e808 --- /dev/null +++ b/test/bash_it/bash_it.bats @@ -0,0 +1,85 @@ +#!/usr/bin/env bats + +load ../test_helper +load ../../lib/composure + +function local_setup { + mkdir -p "$BASH_IT" + lib_directory="$(cd "$(dirname "$0")" && pwd)" + # Use rsync to copy Bash-it to the temp folder + # rsync is faster than cp, since we can exclude the large ".git" folder + rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../.. "$BASH_IT" + + rm -rf "$BASH_IT"/enabled + rm -rf "$BASH_IT"/aliases/enabled + rm -rf "$BASH_IT"/completion/enabled + rm -rf "$BASH_IT"/plugins/enabled + + # Don't pollute the user's actual $HOME directory + # Use a test home directory instead + export BASH_IT_TEST_CURRENT_HOME="${HOME}" + export BASH_IT_TEST_HOME="$(cd "${BASH_IT}/.." && pwd)/BASH_IT_TEST_HOME" + mkdir -p "${BASH_IT_TEST_HOME}" + export HOME="${BASH_IT_TEST_HOME}" +} + +function local_teardown { + export HOME="${BASH_IT_TEST_CURRENT_HOME}" + + rm -rf "${BASH_IT_TEST_HOME}" + + assert_equal "${BASH_IT_TEST_CURRENT_HOME}" "${HOME}" +} + +@test "bash-it: load enabled aliases from new structure, priority-based" { + mkdir -p $BASH_IT/enabled + ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/enabled/150---atom.aliases.bash + assert [ -L "$BASH_IT/enabled/150---atom.aliases.bash" ] + ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash + assert [ -L "$BASH_IT/enabled/250---base.plugin.bash" ] + + # The `ah` alias should not exist + run alias ah &> /dev/null + assert_failure + + load "$BASH_IT/bash_it.sh" + + run alias ah &> /dev/null + assert_success +} + +@test "bash-it: load enabled aliases from old structure, priority-based" { + mkdir -p $BASH_IT/aliases/enabled + mkdir -p $BASH_IT/plugins/enabled + ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/150---atom.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/150---atom.aliases.bash" ] + ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/250---base.plugin.bash" ] + + # The `ah` alias should not exist + run alias ah &> /dev/null + assert_failure + + load "$BASH_IT/bash_it.sh" + + run alias ah &> /dev/null + assert_success +} + +@test "bash-it: load enabled aliases from old structure, without priorities" { + mkdir -p $BASH_IT/aliases/enabled + mkdir -p $BASH_IT/plugins/enabled + ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/atom.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/atom.aliases.bash" ] + ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/base.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/base.plugin.bash" ] + + # The `ah` alias should not exist + run alias ah &> /dev/null + assert_failure + + load "$BASH_IT/bash_it.sh" + + run alias ah &> /dev/null + assert_success +} diff --git a/test/run b/test/run index 389a20ae..72d8db4a 100755 --- a/test/run +++ b/test/run @@ -11,4 +11,4 @@ fi # TODO Add tests for bash-it completion -exec $bats_executable ${CI:+--tap} ${test_directory}/{install,lib,plugins,themes} +exec $bats_executable ${CI:+--tap} ${test_directory}/{bash_it,install,lib,plugins,themes} From a4c6a1aaedf8899512d52ae863d77b54c5b5a764 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:15 +0200 Subject: [PATCH 20/65] Added first tests for Bash-it completion script --- test/completion/bash-it.completion.bats | 72 +++++++++++++++++++++++++ test/run | 5 +- 2 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 test/completion/bash-it.completion.bats diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats new file mode 100644 index 00000000..dc528ed9 --- /dev/null +++ b/test/completion/bash-it.completion.bats @@ -0,0 +1,72 @@ +#!/usr/bin/env bats + +load ../test_helper +load ../../lib/composure +load ../../completion/available/bash-it.completion + +function local_setup { + mkdir -p "$BASH_IT" + lib_directory="$(cd "$(dirname "$0")" && pwd)" + # Use rsync to copy Bash-it to the temp folder + # rsync is faster than cp, since we can exclude the large ".git" folder + rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../.. "$BASH_IT" + + rm -rf "$BASH_IT"/enabled + rm -rf "$BASH_IT"/aliases/enabled + rm -rf "$BASH_IT"/completion/enabled + rm -rf "$BASH_IT"/plugins/enabled + + # Don't pollute the user's actual $HOME directory + # Use a test home directory instead + export BASH_IT_TEST_CURRENT_HOME="${HOME}" + export BASH_IT_TEST_HOME="$(cd "${BASH_IT}/.." && pwd)/BASH_IT_TEST_HOME" + mkdir -p "${BASH_IT_TEST_HOME}" + export HOME="${BASH_IT_TEST_HOME}" +} + +function local_teardown { + export HOME="${BASH_IT_TEST_CURRENT_HOME}" + + rm -rf "${BASH_IT_TEST_HOME}" + + assert_equal "${BASH_IT_TEST_CURRENT_HOME}" "${HOME}" +} + +@test "completion bash-it: ensure that the _bash-it-comp function is available" { + type -a _bash-it-comp &> /dev/null + assert_success +} + +@test "completion bash-it: provide the atom aliases when not enabled" { + COMP_WORDS=(bash-it enable alias ato) + + COMP_CWORD=3 + + COMP_LINE='bash-it enable alias ato' + + COMP_POINT=${#COMP_LINE} + + _bash-it-comp + + echo "${COMPREPLY[@]}" + all_results="${COMPREPLY[@]}" + + assert_equal "atom" "$all_results" +} + +@test "completion bash-it: provide the a* aliases when not enabled" { + COMP_WORDS=(bash-it enable alias a) + + COMP_CWORD=3 + + COMP_LINE='bash-it enable alias a' + + COMP_POINT=${#COMP_LINE} + + _bash-it-comp + + echo "${COMPREPLY[@]}" + all_results="${COMPREPLY[@]}" + + assert_equal "all ag ansible apt atom" "$all_results" +} diff --git a/test/run b/test/run index 72d8db4a..9cfa72cd 100755 --- a/test/run +++ b/test/run @@ -9,6 +9,5 @@ if [ -z "${BASH_IT}" ]; then export BASH_IT=$(cd ${test_directory} && dirname $(pwd)) fi -# TODO Add tests for bash-it completion - -exec $bats_executable ${CI:+--tap} ${test_directory}/{bash_it,install,lib,plugins,themes} +#exec $bats_executable ${CI:+--tap} ${test_directory}/completion +exec $bats_executable ${CI:+--tap} ${test_directory}/{bash_it,completion,install,lib,plugins,themes} From 3e9c5655b1280ac024e93a411c2281943cd9eb8b Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:15 +0200 Subject: [PATCH 21/65] Added xargs fix to some more wc -l invocations Calling `xargs` removes any leading whitespace, which is introduced by the macOS version of `wc`. See https://stackoverflow.com/a/12973694/1228454 for more info. --- test/lib/helpers.bats | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index fd38ad69..bf1865fa 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -258,17 +258,17 @@ function __migrate_all_components() { ls ${BASH_IT}/${subdirectory}/enabled - all_available=$(compgen -G "${BASH_IT}/${subdirectory}/available/*.$one_type.bash" | wc -l) - all_enabled_old=$(compgen -G "${BASH_IT}/${subdirectory}/enabled/*.$one_type.bash" | wc -l) + all_available=$(compgen -G "${BASH_IT}/${subdirectory}/available/*.$one_type.bash" | wc -l | xargs) + all_enabled_old=$(compgen -G "${BASH_IT}/${subdirectory}/enabled/*.$one_type.bash" | wc -l | xargs) assert_equal "$all_available" "$all_enabled_old" run bash-it migrate - all_enabled_old_after=$(compgen -G "${BASH_IT}/${subdirectory}/enabled/*.$one_type.bash" | wc -l) + all_enabled_old_after=$(compgen -G "${BASH_IT}/${subdirectory}/enabled/*.$one_type.bash" | wc -l | xargs) assert_equal "0" "$all_enabled_old_after" - all_enabled_new_after=$(compgen -G "${BASH_IT}/enabled/*.$one_type.bash" | wc -l) + all_enabled_new_after=$(compgen -G "${BASH_IT}/enabled/*.$one_type.bash" | wc -l | xargs) assert_equal "$all_enabled_old" "$all_enabled_new_after" } From b31c7a0afa847e8f601c23acaa7679aa319cd11c Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:15 +0200 Subject: [PATCH 22/65] Refactored completion check into a reusable function --- test/completion/bash-it.completion.bats | 39 ++++++++++++------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats index dc528ed9..f33de173 100644 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -37,36 +37,33 @@ function local_teardown { assert_success } -@test "completion bash-it: provide the atom aliases when not enabled" { - COMP_WORDS=(bash-it enable alias ato) +function __check_completion () { + # Get the parameters as an array + eval set -- "$@" + COMP_WORDS=("$@") - COMP_CWORD=3 - - COMP_LINE='bash-it enable alias ato' + # Get the parameters as a single value + COMP_LINE=$* + # Index of the cursor in the line COMP_POINT=${#COMP_LINE} + # Word index of the last word + COMP_CWORD=$(( ${#COMP_WORDS[@]} - 1 )) + + # Run the Bash-it completion function _bash-it-comp + # Return the completion output echo "${COMPREPLY[@]}" - all_results="${COMPREPLY[@]}" +} - assert_equal "atom" "$all_results" +@test "completion bash-it: provide the atom aliases when not enabled" { + run __check_completion 'bash-it enable alias ato' + assert_line "0" "atom" } @test "completion bash-it: provide the a* aliases when not enabled" { - COMP_WORDS=(bash-it enable alias a) - - COMP_CWORD=3 - - COMP_LINE='bash-it enable alias a' - - COMP_POINT=${#COMP_LINE} - - _bash-it-comp - - echo "${COMPREPLY[@]}" - all_results="${COMPREPLY[@]}" - - assert_equal "all ag ansible apt atom" "$all_results" + run __check_completion 'bash-it enable alias a' + assert_line "0" "all ag ansible apt atom" "$all_results" } From adb2f1071ffb069db599cfa732b2ef08c554def0 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:15 +0200 Subject: [PATCH 23/65] Added tests for completion results with various file locations and names --- test/completion/bash-it.completion.bats | 64 +++++++++++++++++++++++-- test/run | 2 +- 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats index f33de173..49042e66 100644 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -16,6 +16,11 @@ function local_setup { rm -rf "$BASH_IT"/completion/enabled rm -rf "$BASH_IT"/plugins/enabled + mkdir -p "$BASH_IT"/enabled + mkdir -p "$BASH_IT"/aliases/enabled + mkdir -p "$BASH_IT"/completion/enabled + mkdir -p "$BASH_IT"/plugins/enabled + # Don't pollute the user's actual $HOME directory # Use a test home directory instead export BASH_IT_TEST_CURRENT_HOME="${HOME}" @@ -58,12 +63,65 @@ function __check_completion () { echo "${COMPREPLY[@]}" } -@test "completion bash-it: provide the atom aliases when not enabled" { +@test "completion bash-it: disable - provide nothing when atom is not enabled" { + run __check_completion 'bash-it disable alias ato' + assert_line "0" "all" +} + +@test "completion bash-it: disable - provide the a* aliases when atom is enabled with the old location and name" { + ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/atom.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/atom.aliases.bash" ] + + run __check_completion 'bash-it disable alias a' + assert_line "0" "all atom" +} + +@test "completion bash-it: disable - provide the a* aliases when atom is enabled with the old location and priority-based name" { + ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/150---atom.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/150---atom.aliases.bash" ] + + run __check_completion 'bash-it disable alias a' + assert_line "0" "all atom" +} + +@test "completion bash-it: disable - provide the a* aliases when atom is enabled with the new location and priority-based name" { + ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/enabled/150---atom.aliases.bash + assert [ -L "$BASH_IT/enabled/150---atom.aliases.bash" ] + + run __check_completion 'bash-it disable alias a' + assert_line "0" "all atom" +} + +@test "completion bash-it: enable - provide the atom aliases when not enabled" { run __check_completion 'bash-it enable alias ato' assert_line "0" "atom" } -@test "completion bash-it: provide the a* aliases when not enabled" { +@test "completion bash-it: enable - provide the a* aliases when not enabled" { run __check_completion 'bash-it enable alias a' - assert_line "0" "all ag ansible apt atom" "$all_results" + assert_line "0" "all ag ansible apt atom" +} + +@test "completion bash-it: enable - provide the a* aliases when atom is enabled with the old location and name" { + ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/atom.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/atom.aliases.bash" ] + + run __check_completion 'bash-it enable alias a' + assert_line "0" "all ag ansible apt" +} + +@test "completion bash-it: enable - provide the a* aliases when atom is enabled with the old location and priority-based name" { + ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/150---atom.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/150---atom.aliases.bash" ] + + run __check_completion 'bash-it enable alias a' + assert_line "0" "all ag ansible apt" +} + +@test "completion bash-it: enable - provide the a* aliases when atom is enabled with the new location and priority-based name" { + ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/enabled/150---atom.aliases.bash + assert [ -L "$BASH_IT/enabled/150---atom.aliases.bash" ] + + run __check_completion 'bash-it enable alias a' + assert_line "0" "all ag ansible apt" } diff --git a/test/run b/test/run index 9cfa72cd..f02f9951 100755 --- a/test/run +++ b/test/run @@ -9,5 +9,5 @@ if [ -z "${BASH_IT}" ]; then export BASH_IT=$(cd ${test_directory} && dirname $(pwd)) fi -#exec $bats_executable ${CI:+--tap} ${test_directory}/completion +# exec $bats_executable ${CI:+--tap} ${test_directory}/completion exec $bats_executable ${CI:+--tap} ${test_directory}/{bash_it,completion,install,lib,plugins,themes} From e7298a530359e5cab034fe356eee4ddbf0f8ca54 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:15 +0200 Subject: [PATCH 24/65] Fixed case where nothing was enabled --- completion/available/bash-it.completion.bash | 4 ++-- test/completion/bash-it.completion.bats | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 5222a484..2ab35879 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -25,7 +25,7 @@ _bash-it-comp-list-enabled() { subdirectory="$1" - local enabled_things=$(for f in `ls -1 "${BASH_IT}/$subdirectory/enabled/"*.bash 2>/dev/null`; + local enabled_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/enabled/*.bash"`; do basename $f | cut -d'.' -f1 | sed -e "s/^[0-9]*---//g" done) @@ -37,7 +37,7 @@ _bash-it-comp-list-available() { subdirectory="$1" - local enabled_things=$(for f in `ls -1 "${BASH_IT}/$subdirectory/available/"*.bash`; + local enabled_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash"`; do basename $f | cut -d'.' -f1 done) diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats index 49042e66..2175c9ce 100644 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -65,6 +65,11 @@ function __check_completion () { @test "completion bash-it: disable - provide nothing when atom is not enabled" { run __check_completion 'bash-it disable alias ato' + assert_line "0" "" +} + +@test "completion bash-it: disable - provide all when atom is not enabled" { + run __check_completion 'bash-it disable alias a' assert_line "0" "all" } From 7a3603f80d70886e75be0372b802d6f8f5fedc37 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:15 +0200 Subject: [PATCH 25/65] Sorting compgen output so that the returned values are in ascending order --- completion/available/bash-it.completion.bash | 6 +++--- test/run | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 2ab35879..c3887dc3 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -10,7 +10,7 @@ _bash-it-comp-list-available-not-enabled() { subdirectory="$1" - local available_things=$(for f in `ls -1 "${BASH_IT}/$subdirectory/available/"*.bash 2>/dev/null`; + local available_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sort`; do if [ ! -e "${BASH_IT}/$subdirectory/enabled/"$(basename $f) ] && [ ! -e "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ] then @@ -25,7 +25,7 @@ _bash-it-comp-list-enabled() { subdirectory="$1" - local enabled_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/enabled/*.bash"`; + local enabled_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/enabled/*.bash" | sort`; do basename $f | cut -d'.' -f1 | sed -e "s/^[0-9]*---//g" done) @@ -37,7 +37,7 @@ _bash-it-comp-list-available() { subdirectory="$1" - local enabled_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash"`; + local enabled_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sort`; do basename $f | cut -d'.' -f1 done) diff --git a/test/run b/test/run index f02f9951..be0df470 100755 --- a/test/run +++ b/test/run @@ -9,5 +9,5 @@ if [ -z "${BASH_IT}" ]; then export BASH_IT=$(cd ${test_directory} && dirname $(pwd)) fi -# exec $bats_executable ${CI:+--tap} ${test_directory}/completion -exec $bats_executable ${CI:+--tap} ${test_directory}/{bash_it,completion,install,lib,plugins,themes} +exec $bats_executable ${CI:+--tap} ${test_directory}/completion +# exec $bats_executable ${CI:+--tap} ${test_directory}/{bash_it,completion,install,lib,plugins,themes} From 752d4afe4149dafee3fa52401a29b9bfdcf3c571 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:15 +0200 Subject: [PATCH 26/65] Tabs to spaces --- completion/available/bash-it.completion.bash | 156 +++++++++---------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index c3887dc3..6bea15a6 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -2,112 +2,112 @@ _bash-it-comp-enable-disable() { - local enable_disable_args="alias plugin completion" - COMPREPLY=( $(compgen -W "${enable_disable_args}" -- ${cur}) ) + local enable_disable_args="alias plugin completion" + COMPREPLY=( $(compgen -W "${enable_disable_args}" -- ${cur}) ) } _bash-it-comp-list-available-not-enabled() { - subdirectory="$1" + subdirectory="$1" - local available_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sort`; - do - if [ ! -e "${BASH_IT}/$subdirectory/enabled/"$(basename $f) ] && [ ! -e "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ] - then - basename $f | cut -d'.' -f1 - fi - done) + local available_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sort`; + do + if [ ! -e "${BASH_IT}/$subdirectory/enabled/"$(basename $f) ] && [ ! -e "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ] + then + basename $f | cut -d'.' -f1 + fi + done) - COMPREPLY=( $(compgen -W "all ${available_things}" -- ${cur}) ) + COMPREPLY=( $(compgen -W "all ${available_things}" -- ${cur}) ) } _bash-it-comp-list-enabled() { - subdirectory="$1" + subdirectory="$1" - local enabled_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/enabled/*.bash" | sort`; - do - basename $f | cut -d'.' -f1 | sed -e "s/^[0-9]*---//g" - done) + local enabled_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/enabled/*.bash" | sort`; + do + basename $f | cut -d'.' -f1 | sed -e "s/^[0-9]*---//g" + done) - COMPREPLY=( $(compgen -W "all ${enabled_things}" -- ${cur}) ) + COMPREPLY=( $(compgen -W "all ${enabled_things}" -- ${cur}) ) } _bash-it-comp-list-available() { - subdirectory="$1" + subdirectory="$1" - local enabled_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sort`; - do - basename $f | cut -d'.' -f1 - done) + local enabled_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sort`; + do + basename $f | cut -d'.' -f1 + done) - COMPREPLY=( $(compgen -W "${enabled_things}" -- ${cur}) ) + COMPREPLY=( $(compgen -W "${enabled_things}" -- ${cur}) ) } _bash-it-comp() { - local cur prev opts prevprev - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" - chose_opt="${COMP_WORDS[1]}" - file_type="${COMP_WORDS[2]}" - opts="help show enable disable update search migrate" - case "${chose_opt}" in - show) - local show_args="plugins aliases completions" - COMPREPLY=( $(compgen -W "${show_args}" -- ${cur}) ) - return 0 - ;; - help) - local help_args="plugins aliases completions migrate update" - COMPREPLY=( $(compgen -W "${help_args}" -- ${cur}) ) - return 0 - ;; + local cur prev opts prevprev + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + chose_opt="${COMP_WORDS[1]}" + file_type="${COMP_WORDS[2]}" + opts="help show enable disable update search migrate" + case "${chose_opt}" in + show) + local show_args="plugins aliases completions" + COMPREPLY=( $(compgen -W "${show_args}" -- ${cur}) ) + return 0 + ;; + help) + local help_args="plugins aliases completions migrate update" + COMPREPLY=( $(compgen -W "${help_args}" -- ${cur}) ) + return 0 + ;; update | search | migrate) return 0 ;; - enable | disable) - if [ x"${chose_opt}" == x"enable" ];then - suffix="available-not-enabled" - else - suffix="enabled" - fi - 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) - prevprev="${COMP_WORDS[COMP_CWORD-2]}" + enable | disable) + if [ x"${chose_opt}" == x"enable" ];then + suffix="available-not-enabled" + else + suffix="enabled" + fi + 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) + prevprev="${COMP_WORDS[COMP_CWORD-2]}" - case "${prevprev}" in - help) - _bash-it-comp-list-available aliases - return 0 - ;; - esac - ;; - esac + case "${prevprev}" in + help) + _bash-it-comp-list-available aliases + return 0 + ;; + esac + ;; + esac - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - return 0 + return 0 } # Activate completion for bash-it and its common misspellings From a925f5d58c18b59df93036c1d672c0b0abbe541f Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:15 +0200 Subject: [PATCH 27/65] Checking for global directory when looking for components that are not enabled --- completion/available/bash-it.completion.bash | 6 +++++- test/run | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 6bea15a6..408c2bf6 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -12,7 +12,10 @@ _bash-it-comp-list-available-not-enabled() local available_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sort`; do - if [ ! -e "${BASH_IT}/$subdirectory/enabled/"$(basename $f) ] && [ ! -e "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ] + # TODO Find a better way to check for these, without using -e + glob + if [ ! -e "${BASH_IT}/$subdirectory/enabled/"$(basename $f) ] \ + && [ ! -e "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ] \ + && [ ! -e "${BASH_IT}/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ] then basename $f | cut -d'.' -f1 fi @@ -25,6 +28,7 @@ _bash-it-comp-list-enabled() { subdirectory="$1" + # TODO Check for global directory as well local enabled_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/enabled/*.bash" | sort`; do basename $f | cut -d'.' -f1 | sed -e "s/^[0-9]*---//g" diff --git a/test/run b/test/run index be0df470..f02f9951 100755 --- a/test/run +++ b/test/run @@ -9,5 +9,5 @@ if [ -z "${BASH_IT}" ]; then export BASH_IT=$(cd ${test_directory} && dirname $(pwd)) fi -exec $bats_executable ${CI:+--tap} ${test_directory}/completion -# exec $bats_executable ${CI:+--tap} ${test_directory}/{bash_it,completion,install,lib,plugins,themes} +# exec $bats_executable ${CI:+--tap} ${test_directory}/completion +exec $bats_executable ${CI:+--tap} ${test_directory}/{bash_it,completion,install,lib,plugins,themes} From 22674ce1e06a00ad110f5f25e7893b7fbdc121c5 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:15 +0200 Subject: [PATCH 28/65] Replaced -e glob-based implementation with ls --- completion/available/bash-it.completion.bash | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 408c2bf6..f7f0495d 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -12,10 +12,12 @@ _bash-it-comp-list-available-not-enabled() local available_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sort`; do - # TODO Find a better way to check for these, without using -e + glob - if [ ! -e "${BASH_IT}/$subdirectory/enabled/"$(basename $f) ] \ - && [ ! -e "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ] \ - && [ ! -e "${BASH_IT}/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ] + file_entity=$(basename $f) + + typeset enabled_component=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity,$file_entity} 2>/dev/null | head -1) + typeset enabled_component_global=$(command ls "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity 2>/dev/null | head -1) + + if [ -z "$enabled_component" ] && [ -z "$enabled_component_global" ] then basename $f | cut -d'.' -f1 fi From 607c9cd049e5fc62d85cd7d11dece9d15ba5c362 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:15 +0200 Subject: [PATCH 29/65] Cleaned up declarations --- completion/available/bash-it.completion.bash | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index f7f0495d..6f622e89 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -10,7 +10,9 @@ _bash-it-comp-list-available-not-enabled() { subdirectory="$1" - local available_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sort`; + local available_things + + available_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sort`; do file_entity=$(basename $f) @@ -28,7 +30,7 @@ _bash-it-comp-list-available-not-enabled() _bash-it-comp-list-enabled() { - subdirectory="$1" + local subdirectory="$1" # TODO Check for global directory as well local enabled_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/enabled/*.bash" | sort`; @@ -43,7 +45,9 @@ _bash-it-comp-list-available() { subdirectory="$1" - local enabled_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sort`; + local enabled_things + + enabled_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sort`; do basename $f | cut -d'.' -f1 done) From ec327486ef3679e2fc29aa9ebdc6824291eaa9bd Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:15 +0200 Subject: [PATCH 30/65] Checking global directory for completions as well --- completion/available/bash-it.completion.bash | 6 ++++-- test/completion/bash-it.completion.bats | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 6f622e89..67a9fdc3 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -31,9 +31,11 @@ _bash-it-comp-list-available-not-enabled() _bash-it-comp-list-enabled() { local subdirectory="$1" + local suffix enabled_things - # TODO Check for global directory as well - local enabled_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/enabled/*.bash" | sort`; + suffix=$(echo "$subdirectory" | sed -e 's/plugins/plugin/g') + + enabled_things=$(for f in `sort <(compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash") <(compgen -G "${BASH_IT}/enabled/*.${suffix}.bash")`; do basename $f | cut -d'.' -f1 | sed -e "s/^[0-9]*---//g" done) diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats index 2175c9ce..7a8e1123 100644 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -77,6 +77,9 @@ function __check_completion () { ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/atom.aliases.bash assert [ -L "$BASH_IT/aliases/enabled/atom.aliases.bash" ] + ln -s $BASH_IT/completion/available/apm.completion.bash $BASH_IT/completion/enabled/apm.completion.bash + assert [ -L "$BASH_IT/completion/enabled/apm.completion.bash" ] + run __check_completion 'bash-it disable alias a' assert_line "0" "all atom" } @@ -85,6 +88,9 @@ function __check_completion () { ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/150---atom.aliases.bash assert [ -L "$BASH_IT/aliases/enabled/150---atom.aliases.bash" ] + ln -s $BASH_IT/completion/available/apm.completion.bash $BASH_IT/completion/enabled/350---apm.completion.bash + assert [ -L "$BASH_IT/completion/enabled/350---apm.completion.bash" ] + run __check_completion 'bash-it disable alias a' assert_line "0" "all atom" } @@ -93,6 +99,9 @@ function __check_completion () { ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/enabled/150---atom.aliases.bash assert [ -L "$BASH_IT/enabled/150---atom.aliases.bash" ] + ln -s $BASH_IT/completion/available/apm.completion.bash $BASH_IT/enabled/350---apm.completion.bash + assert [ -L "$BASH_IT/enabled/350---apm.completion.bash" ] + run __check_completion 'bash-it disable alias a' assert_line "0" "all atom" } From 05696df361b21e1ec2c9d9774dfaa11ffbc40d97 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:15 +0200 Subject: [PATCH 31/65] Additional test cases for completions with dashes and dots --- test/completion/bash-it.completion.bats | 90 +++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats index 7a8e1123..ad6bf374 100644 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -106,6 +106,72 @@ function __check_completion () { assert_line "0" "all atom" } +@test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the old location and name" { + ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/docker-compose.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" ] + + ln -s $BASH_IT/plugins/available/docker-machine.plugin.bash $BASH_IT/plugins/enabled/docker-machine.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/docker-machine.plugin.bash" ] + + run __check_completion 'bash-it disable plugin docker' + assert_line "0" "docker-machine" +} + +@test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the old location and priority-based name" { + ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/150---docker-compose.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" ] + + ln -s $BASH_IT/plugins/available/docker-machine.plugin.bash $BASH_IT/plugins/enabled/350---docker-machine.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash" ] + + run __check_completion 'bash-it disable plugin docker' + assert_line "0" "docker-machine" +} + +@test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the new location and priority-based name" { + ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/enabled/150---docker-compose.aliases.bash + assert [ -L "$BASH_IT/enabled/150---docker-compose.aliases.bash" ] + + ln -s $BASH_IT/plugins/available/docker-machine.plugin.bash $BASH_IT/enabled/350---docker-machine.plugin.bash + assert [ -L "$BASH_IT/enabled/350---docker-machine.plugin.bash" ] + + run __check_completion 'bash-it disable plugin docker' + assert_line "0" "docker-machine" +} + +@test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and name" { + ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" ] + + ln -s $BASH_IT/plugins/available/todo.plugin.bash $BASH_IT/plugins/enabled/todo.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/todo.plugin.bash" ] + + run __check_completion 'bash-it disable alias to' + assert_line "0" "todo.txt-cli" +} + +@test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and priority-based name" { + ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" ] + + ln -s $BASH_IT/plugins/available/todo.plugin.bash $BASH_IT/plugins/enabled/350---todo.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/350---todo.plugin.bash" ] + + run __check_completion 'bash-it disable alias to' + assert_line "0" "todo.txt-cli" +} + +@test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the new location and priority-based name" { + ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/enabled/150---todo.txt-cli.aliases.bash + assert [ -L "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" ] + + ln -s $BASH_IT/plugins/available/todo.plugin.bash $BASH_IT/enabled/350---todo.plugin.bash + assert [ -L "$BASH_IT/enabled/350---todo.plugin.bash" ] + + run __check_completion 'bash-it disable alias to' + assert_line "0" "todo.txt-cli" +} + @test "completion bash-it: enable - provide the atom aliases when not enabled" { run __check_completion 'bash-it enable alias ato' assert_line "0" "atom" @@ -139,3 +205,27 @@ function __check_completion () { run __check_completion 'bash-it enable alias a' assert_line "0" "all ag ansible apt" } + +@test "completion bash-it: enable - provide the docker-* plugins when nothing is enabled with the old location and name" { + ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/docker-compose.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" ] + + run __check_completion 'bash-it enable plugin docker' + assert_line "0" "docker-compose docker-machine docker" +} + +@test "completion bash-it: enable - provide the docker-* plugins when nothing is enabled with the old location and priority-based name" { + ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/150---docker-compose.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" ] + + run __check_completion 'bash-it enable plugin docker' + assert_line "0" "docker-compose docker-machine docker" +} + +@test "completion bash-it: enable - provide the docker-* plugins when nothing is enabled with the new location and priority-based name" { + ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/enabled/150---docker-compose.aliases.bash + assert [ -L "$BASH_IT/enabled/150---docker-compose.aliases.bash" ] + + run __check_completion 'bash-it enable plugin docker' + assert_line "0" "docker-compose docker-machine docker" +} From 688d0cb540f4b4b79e6adf3e9f98f3a658817d47 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:16 +0200 Subject: [PATCH 32/65] Some more test cases --- test/completion/bash-it.completion.bats | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats index ad6bf374..c4c7d2e0 100644 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -229,3 +229,27 @@ function __check_completion () { run __check_completion 'bash-it enable plugin docker' assert_line "0" "docker-compose docker-machine docker" } + +@test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and name" { + ln -s $BASH_IT/plugins/available/todo.plugin.bash $BASH_IT/plugins/enabled/todo.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/todo.plugin.bash" ] + + run __check_completion 'bash-it enable alias to' + assert_line "0" "todo.txt-cli" +} + +@test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and priority-based name" { + ln -s $BASH_IT/plugins/available/todo.plugin.bash $BASH_IT/plugins/enabled/350---todo.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/350---todo.plugin.bash" ] + + run __check_completion 'bash-it enable alias to' + assert_line "0" "todo.txt-cli" +} + +@test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the new location and priority-based name" { + ln -s $BASH_IT/plugins/available/todo.plugin.bash $BASH_IT/enabled/350---todo.plugin.bash + assert [ -L "$BASH_IT/enabled/350---todo.plugin.bash" ] + + run __check_completion 'bash-it enable alias to' + assert_line "0" "todo.txt-cli" +} From e0dc7997c8e95cb0e8910168820c88c09fef2fda Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:16 +0200 Subject: [PATCH 33/65] Fixed handling of components with dashes or dots in the name for completion --- completion/available/bash-it.completion.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 67a9fdc3..28711710 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -21,7 +21,7 @@ _bash-it-comp-list-available-not-enabled() if [ -z "$enabled_component" ] && [ -z "$enabled_component_global" ] then - basename $f | cut -d'.' -f1 + basename $f | sed -e 's/\(.*\)\..*\.bash/\1/g' fi done) @@ -37,7 +37,7 @@ _bash-it-comp-list-enabled() enabled_things=$(for f in `sort <(compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash") <(compgen -G "${BASH_IT}/enabled/*.${suffix}.bash")`; do - basename $f | cut -d'.' -f1 | sed -e "s/^[0-9]*---//g" + basename $f | sed -e 's/\(.*\)\..*\.bash/\1/g' | sed -e "s/^[0-9]*---//g" done) COMPREPLY=( $(compgen -W "all ${enabled_things}" -- ${cur}) ) @@ -51,7 +51,7 @@ _bash-it-comp-list-available() enabled_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sort`; do - basename $f | cut -d'.' -f1 + basename $f | sed -e 's/\(.*\)\..*\.bash/\1/g' done) COMPREPLY=( $(compgen -W "${enabled_things}" -- ${cur}) ) From 298b9c6455832f497be5bb09699d4b73b17d5da0 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:16 +0200 Subject: [PATCH 34/65] Added test case for completion "help aliases v" --- test/completion/bash-it.completion.bats | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats index c4c7d2e0..65984c2b 100644 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -63,6 +63,11 @@ function __check_completion () { echo "${COMPREPLY[@]}" } +@test "completion bash-it: help aliases" { + run __check_completion 'bash-it help aliases v' + assert_line "0" "vagrant vault vim" +} + @test "completion bash-it: disable - provide nothing when atom is not enabled" { run __check_completion 'bash-it disable alias ato' assert_line "0" "" From c786c148595118a2b3d48120a8cbce4da5e44bae Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:16 +0200 Subject: [PATCH 35/65] Fixed "bash-it help aliases" completion - it will now show the available aliases --- completion/available/bash-it.completion.bash | 21 ++++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 28711710..3651e086 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -73,9 +73,14 @@ _bash-it-comp() return 0 ;; help) - local help_args="plugins aliases completions migrate update" - COMPREPLY=( $(compgen -W "${help_args}" -- ${cur}) ) - return 0 + if [ x"${prev}" == x"aliases" ]; then + _bash-it-comp-list-available aliases + return 0 + else + local help_args="plugins aliases completions migrate update" + COMPREPLY=( $(compgen -W "${help_args}" -- ${cur}) ) + return 0 + fi ;; update | search | migrate) return 0 @@ -105,16 +110,6 @@ _bash-it-comp() ;; esac ;; - aliases) - prevprev="${COMP_WORDS[COMP_CWORD-2]}" - - case "${prevprev}" in - help) - _bash-it-comp-list-available aliases - return 0 - ;; - esac - ;; esac COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) From 4caed3d6d51f1658cba0bd3044974b4481b33d05 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:16 +0200 Subject: [PATCH 36/65] Ignoring files in global enabled directory --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index b748d384..191a765c 100755 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ plugins/custom.plugins.bash .*.un~ bats .idea +enabled/* From 757d2b4ed9f1c02bc01df1a2b2da9048e9c8d945 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:16 +0200 Subject: [PATCH 37/65] Removed unused variable --- completion/available/bash-it.completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 3651e086..dc007ec1 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -59,7 +59,7 @@ _bash-it-comp-list-available() _bash-it-comp() { - local cur prev opts prevprev + local cur prev opts COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" From 5ff873e0582dc40c72911cff9f86d1cbb030256b Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:16 +0200 Subject: [PATCH 38/65] Fixed "bash-it help aliases" cases, more to come... --- lib/helpers.bash | 9 ++++++++- test/lib/helpers.bats | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 16b31946..0c292621 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -454,11 +454,18 @@ _help-aliases() cat "${BASH_IT}/aliases/$alias_path" | metafor alias | sed "s/$/'/" else typeset f + shopt -s nullglob + for f in "${BASH_IT}/aliases/enabled/"* do _help-list-aliases $f done - _help-list-aliases "${BASH_IT}/aliases/custom.aliases.bash" + + shopt -u nullglob + + if [ -e "${BASH_IT}/aliases/custom.aliases.bash" ]; then + _help-list-aliases "${BASH_IT}/aliases/custom.aliases.bash" + fi fi } diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index bf1865fa..9a98f8df 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -30,6 +30,17 @@ function local_setup { # TODO Create global __get_base_name function # TODO Create global __get_enabled_name function +@test "helpers: bash-it help aliases ag" { + run bash-it help alias "ag" + assert_line "0" "ag='ag --smart-case --pager=\"less -MIRFX'" +} + +@test "helpers: bash-it help aliases without any aliases enabled" { + run bash-it help alias + echo "${lines[@]}" + assert_line "0" "" +} + @test "helpers: enable the todo.txt-cli aliases through the bash-it function" { run bash-it enable alias "todo.txt-cli" assert_line "0" 'todo.txt-cli enabled with priority 150.' From 4cda9c0a439cc4e1ca87e8487ec874f6129fd800 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:16 +0200 Subject: [PATCH 39/65] Started work on bash-it help aliases --- lib/helpers.bash | 2 +- test/lib/helpers.bats | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 0c292621..75894ee0 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -471,7 +471,7 @@ _help-aliases() _help-list-aliases () { - typeset file=$(basename $1) + typeset file=$(basename $1 | sed -e 's/\(.*\)\..*\.bash/\1/g') printf '\n\n%s:\n' "${file%%.*}" # metafor() strips trailing quotes, restore them with sed.. cat $1 | metafor alias | sed "s/$/'/" diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 9a98f8df..299a4ebb 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -31,16 +31,36 @@ function local_setup { # TODO Create global __get_enabled_name function @test "helpers: bash-it help aliases ag" { - run bash-it help alias "ag" + run bash-it help aliases "ag" assert_line "0" "ag='ag --smart-case --pager=\"less -MIRFX'" } @test "helpers: bash-it help aliases without any aliases enabled" { - run bash-it help alias - echo "${lines[@]}" + run bash-it help aliases assert_line "0" "" } +@test "helpers: bash-it help aliases one alias enabled in the old directory" { + ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/aliases/enabled/150---ag.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/150---ag.aliases.bash" ] + + run bash-it help aliases + + echo "${lines[@]}" + assert_line "0" "ag:" +} + +@test "helpers: bash-it help aliases one alias enabled" { + run bash-it enable alias "ag" + assert_line "0" 'ag enabled with priority 150.' + assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] + + run bash-it help aliases + + echo "${lines[@]}" + assert_line "2" "foo" +} + @test "helpers: enable the todo.txt-cli aliases through the bash-it function" { run bash-it enable alias "todo.txt-cli" assert_line "0" 'todo.txt-cli enabled with priority 150.' From e0554cb512e0cf49b1824a56cf811ccf6bee7a3d Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:16 +0200 Subject: [PATCH 40/65] Test cases and fix for bash-it help aliases foo --- lib/helpers.bash | 2 +- test/lib/helpers.bats | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 75894ee0..8c6c7380 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -471,7 +471,7 @@ _help-aliases() _help-list-aliases () { - typeset file=$(basename $1 | sed -e 's/\(.*\)\..*\.bash/\1/g') + typeset file=$(basename $1 | sed -e 's/[0-9]*[-]*\(.*\)\..*\.bash/\1/g') printf '\n\n%s:\n' "${file%%.*}" # metafor() strips trailing quotes, restore them with sed.. cat $1 | metafor alias | sed "s/$/'/" diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 299a4ebb..076ac59e 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -40,17 +40,36 @@ function local_setup { assert_line "0" "" } +@test "helpers: bash-it help list aliases without any aliases enabled" { + run _help-list-aliases "$BASH_IT/aliases/available/ag.aliases.bash" + assert_line "0" "ag:" +} + +@test "helpers: bash-it help list aliases with ag aliases enabled" { + ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/aliases/enabled/150---ag.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/150---ag.aliases.bash" ] + + run _help-list-aliases "$BASH_IT/aliases/enabled/150---ag.aliases.bash" + assert_line "0" "ag:" +} + +@test "helpers: bash-it help list aliases with ag aliases enabled in global directory" { + ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/enabled/150---ag.aliases.bash + assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] + + run _help-list-aliases "$BASH_IT/enabled/150---ag.aliases.bash" + assert_line "0" "ag:" +} + @test "helpers: bash-it help aliases one alias enabled in the old directory" { ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/aliases/enabled/150---ag.aliases.bash assert [ -L "$BASH_IT/aliases/enabled/150---ag.aliases.bash" ] run bash-it help aliases - - echo "${lines[@]}" assert_line "0" "ag:" } -@test "helpers: bash-it help aliases one alias enabled" { +@test "helpers: bash-it help aliases one alias enabled in global directory" { run bash-it enable alias "ag" assert_line "0" 'ag enabled with priority 150.' assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] From c26476f56ee0515efaf5986bf49d316802718ab1 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:16 +0200 Subject: [PATCH 41/65] Fixed bash-it help aliases for todo.txt-cli --- lib/helpers.bash | 4 ++-- test/lib/helpers.bats | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 8c6c7380..2fbe2af1 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -471,8 +471,8 @@ _help-aliases() _help-list-aliases () { - typeset file=$(basename $1 | sed -e 's/[0-9]*[-]*\(.*\)\..*\.bash/\1/g') - printf '\n\n%s:\n' "${file%%.*}" + typeset file=$(basename $1 | sed -e 's/[0-9]*[-]*\(.*\)\.aliases\.bash/\1/g') + printf '\n\n%s:\n' "${file}" # metafor() strips trailing quotes, restore them with sed.. cat $1 | metafor alias | sed "s/$/'/" } diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 076ac59e..7116aba2 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -53,6 +53,22 @@ function local_setup { assert_line "0" "ag:" } +@test "helpers: bash-it help list aliases with todo.txt-cli aliases enabled" { + ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" ] + + run _help-list-aliases "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" + assert_line "0" "todo.txt-cli:" +} + +@test "helpers: bash-it help list aliases with docker-compose aliases enabled" { + ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/150---docker-compose.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" ] + + run _help-list-aliases "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + assert_line "0" "docker-compose:" +} + @test "helpers: bash-it help list aliases with ag aliases enabled in global directory" { ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/enabled/150---ag.aliases.bash assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] From 729f21c10640d3a9c682d5bf3270335e5782563e Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:16 +0200 Subject: [PATCH 42/65] Reading bash-it help lists aliases from global enabled directory --- lib/helpers.bash | 5 +---- test/lib/helpers.bats | 9 ++++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 2fbe2af1..5c6ecb00 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -454,15 +454,12 @@ _help-aliases() cat "${BASH_IT}/aliases/$alias_path" | metafor alias | sed "s/$/'/" else typeset f - shopt -s nullglob - for f in "${BASH_IT}/aliases/enabled/"* + for f in `sort <(compgen -G "${BASH_IT}/aliases/enabled/*") <(compgen -G "${BASH_IT}/enabled/*.aliases.bash")` do _help-list-aliases $f done - shopt -u nullglob - if [ -e "${BASH_IT}/aliases/custom.aliases.bash" ]; then _help-list-aliases "${BASH_IT}/aliases/custom.aliases.bash" fi diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 7116aba2..c6ac7e3f 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -90,10 +90,13 @@ function local_setup { assert_line "0" 'ag enabled with priority 150.' assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] - run bash-it help aliases + run bash-it enable plugin "aws" + assert_line "0" 'aws enabled with priority 250.' + assert [ -L "$BASH_IT/enabled/250---aws.plugin.bash" ] - echo "${lines[@]}" - assert_line "2" "foo" + run bash-it help aliases + assert_line "0" "ag:" + assert_line "1" "ag='ag --smart-case --pager=\"less -MIRFX'" } @test "helpers: enable the todo.txt-cli aliases through the bash-it function" { From 1810eddaf315114d23b771a4e852cbfbf9b6f1dd Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:16 +0200 Subject: [PATCH 43/65] Using compgen instead of globw --- lib/helpers.bash | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 5c6ecb00..d6f9477f 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -181,8 +181,7 @@ _bash-it-migrate() { for file_type in "aliases" "plugins" "completion" do - shopt -s nullglob - for f in "${BASH_IT}/$file_type/enabled/"*.bash + for f in `compgen -G "${BASH_IT}/$file_type/enabled/*.bash"` do typeset ff=$(basename $f) @@ -199,7 +198,6 @@ _bash-it-migrate() { $disable_func $component_name $enable_func $component_name done - shopt -u nullglob done } From 653437e2e1f694fddf1e6c3c9762255230fb9ea6 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:16 +0200 Subject: [PATCH 44/65] Some more tests for disable all --- test/lib/helpers.bats | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index c6ac7e3f..cd721871 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -439,6 +439,57 @@ function __migrate_all_components() { assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] } +@test "helpers: disable all plugins in the old directory structure" { + ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + + ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/node.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/node.plugin.bash" ] + + local enabled=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) + assert_equal "2" "$enabled" + + run _enable-alias "ag" + assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] + + run _disable-plugin "all" + local enabled2=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) + assert_equal "0" "$enabled2" + assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] +} + +@test "helpers: disable all plugins in the old directory structure with priority" { + ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/250---nvm.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/250---nvm.plugin.bash" ] + + ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] + + local enabled=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) + assert_equal "2" "$enabled" + + run _enable-alias "ag" + assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] + + run _disable-plugin "all" + local enabled2=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) + assert_equal "0" "$enabled2" + assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] +} + +@test "helpers: disable all plugins without anything enabled" { + local enabled=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) + assert_equal "0" "$enabled" + + run _enable-alias "ag" + assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] + + run _disable-plugin "all" + local enabled2=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) + assert_equal "0" "$enabled2" + assert [ -L "$BASH_IT/enabled/150---ag.aliases.bash" ] +} + @test "helpers: enable the ansible aliases through the bash-it function" { run bash-it enable alias "ansible" assert_line "0" 'ansible enabled with priority 150.' From 6e34d4f83789ff92a9cf162fd22de9f4bd8ddf7b Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:16 +0200 Subject: [PATCH 45/65] Simplified disable all --- lib/helpers.bash | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index d6f9477f..35014a67 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -282,29 +282,19 @@ _disable-thing () fi if [ "$file_entity" = "all" ]; then - typeset f $file_type + typeset f $file_type suffix + suffix=$(echo "$subdirectory" | sed -e 's/plugins/plugin/g') + # Disable everything that's using the old structure - for f in "${BASH_IT}/$subdirectory/available/"*.bash + for f in `compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash"` do - plugin=$(basename $f) - if [ -e "${BASH_IT}/$subdirectory/enabled/$plugin" ]; then - rm "${BASH_IT}/$subdirectory/enabled/$(basename $plugin)" - fi - if [ -e "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$plugin ]; then - rm "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $plugin) - fi + rm "$f" done - local suffix=$(echo "$subdirectory" | sed -e 's/plugins/plugin/g') - # Disable everything in the global "enabled" directory - for f in "${BASH_IT}/$subdirectory/available/"*.${suffix}.bash + for f in `compgen -G "${BASH_IT}/enabled/*.${suffix}.bash"` do - plugin=$(basename $f) - - if [ -e "${BASH_IT}/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$plugin ]; then - rm "${BASH_IT}/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $plugin) - fi + rm "$f" done else typeset plugin_global=$(command ls $ "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.*bash 2>/dev/null | head -1) From 88ef16ccc74dfd9813855d9e7a85cbb480289875 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:16 +0200 Subject: [PATCH 46/65] Fixed migration order on macOS --- lib/helpers.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 35014a67..9cf5e3fd 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -181,7 +181,7 @@ _bash-it-migrate() { for file_type in "aliases" "plugins" "completion" do - for f in `compgen -G "${BASH_IT}/$file_type/enabled/*.bash"` + for f in `sort <(compgen -G "${BASH_IT}/$file_type/enabled/*.bash")` do typeset ff=$(basename $f) From 475b0778ddca0392380b6f35cc31fd52fd5d4a3a Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:16 +0200 Subject: [PATCH 47/65] Fixed a couple of shellcheck complaints --- lib/helpers.bash | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 9cf5e3fd..662e2f0d 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -20,7 +20,8 @@ function _load_bash_it_files() { # In the new structure if [ -d "${BASH_IT}/enabled" ] then - local suffix=$(echo "$subdirectory" | sed -e 's/plugins/plugin/g') + declare suffix + suffix=$(echo "$subdirectory" | sed -e 's/plugins/plugin/g') FILES="${BASH_IT}/enabled/*.${suffix}.bash" for config_file in $FILES @@ -75,7 +76,7 @@ bash-it () help) func=_help-$component;; search) - _bash-it-search $component $* + _bash-it-search $component "$@" return;; update) func=_bash-it_update;; @@ -101,7 +102,7 @@ bash-it () fi fi - if [ x"$verb" == x"enable" -o x"$verb" == x"disable" ];then + if [ x"$verb" == x"enable" ] || [ x"$verb" == x"disable" ]; then # Automatically run a migration if required _bash-it-migrate @@ -110,7 +111,7 @@ bash-it () $func $arg done else - $func $* + $func "$@" fi } @@ -150,12 +151,17 @@ _bash-it_update() { _about 'updates Bash-it' _group 'lib' - cd "${BASH_IT}" + cd "${BASH_IT}" || return + if [ -z $BASH_IT_REMOTE ]; then BASH_IT_REMOTE="origin" fi + git fetch &> /dev/null - local status="$(git rev-list master..${BASH_IT_REMOTE}/master 2> /dev/null)" + + declare status + status="$(git rev-list master..${BASH_IT_REMOTE}/master 2> /dev/null)" + if [[ -n "${status}" ]]; then git pull --rebase &> /dev/null if [[ $? -eq 0 ]]; then @@ -172,7 +178,7 @@ _bash-it_update() { else echo "Bash-it is up to date, nothing to do!" fi - cd - &> /dev/null + cd - &> /dev/null || return } _bash-it-migrate() { @@ -402,8 +408,9 @@ _enable-thing () mkdir -p "${BASH_IT}/enabled" # Load the priority from the file if it present there - local local_file_priority=$(grep -E "^# BASH_IT_LOAD_PRIORITY:" "${BASH_IT}/$subdirectory/available/$to_enable" | awk -F': ' '{ print $2 }') - local use_load_priority=${local_file_priority:-$load_priority} + declare local_file_priority use_load_priority + local_file_priority=$(grep -E "^# BASH_IT_LOAD_PRIORITY:" "${BASH_IT}/$subdirectory/available/$to_enable" | awk -F': ' '{ print $2 }') + use_load_priority=${local_file_priority:-$load_priority} ln -s ../$subdirectory/available/$to_enable "${BASH_IT}/enabled/${use_load_priority}${BASH_IT_LOAD_PRIORITY_SEPARATOR}${to_enable}" fi From 0791895236c6ea83a4c54699762d643fc2eb1ea1 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:16 +0200 Subject: [PATCH 48/65] Fixed some more shellcheck complaints --- lib/helpers.bash | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 662e2f0d..3223b524 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + BASH_IT_LOAD_PRIORITY_DEFAULT_ALIAS=${BASH_IT_LOAD_PRIORITY_DEFAULT_ALIAS:-150} BASH_IT_LOAD_PRIORITY_DEFAULT_PLUGIN=${BASH_IT_LOAD_PRIORITY_DEFAULT_PLUGIN:-250} BASH_IT_LOAD_PRIORITY_DEFAULT_COMPLETION=${BASH_IT_LOAD_PRIORITY_DEFAULT_COMPLETION:-350} @@ -227,7 +229,11 @@ _bash-it-describe () for f in "${BASH_IT}/$subdirectory/available/"*.bash do # Check for both the old format without the load priority, and the extended format with the priority - if [ -e "${BASH_IT}/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ] || [ -e "${BASH_IT}/$subdirectory/enabled/"$(basename $f) ] || [ -e "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ]; then + declare enabled_files enabled_file + enabled_file=$(basename $f) + enabled_files=$(sort <(compgen -G "${BASH_IT}/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR${enabled_file}") <(compgen -G "${BASH_IT}/$subdirectory/enabled/${enabled_file}") <(compgen -G "${BASH_IT}/$subdirectory/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR${enabled_file}") | wc -l) + + if [ $enabled_files -gt 0 ]; then enabled='x' else enabled=' ' From 2acb87e882e1f7df19a2d26a5fd19f8fef4e075d Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:16 +0200 Subject: [PATCH 49/65] Fixed some more shellcheck complaints --- bash_it.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bash_it.sh b/bash_it.sh index fbb37f62..ab848974 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -29,6 +29,7 @@ then fi # Load composure first, so we support function metadata +# shellcheck source=./lib/composure.bash source "${BASH_IT}/lib/composure.bash" # support 'plumbing' metadata @@ -40,6 +41,7 @@ APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash" for config_file in $LIB do if [ $config_file != $APPEARANCE_LIB ]; then + # shellcheck disable=SC1090 source $config_file fi done @@ -53,10 +55,13 @@ do done # Load colors first so they can be used in base theme +# shellcheck source=./themes/colors.theme.bash source "${BASH_IT}/themes/colors.theme.bash" +# shellcheck source=./themes/base.theme.bash source "${BASH_IT}/themes/base.theme.bash" # appearance (themes) now, after all dependencies +# shellcheck source=./lib/appearance.bash source $APPEARANCE_LIB # Load custom aliases, completion, plugins @@ -64,6 +69,7 @@ for file_type in "aliases" "completion" "plugins" do if [ -e "${BASH_IT}/${file_type}/custom.${file_type}.bash" ] then + # shellcheck disable=SC1090 source "${BASH_IT}/${file_type}/custom.${file_type}.bash" fi done @@ -73,23 +79,26 @@ CUSTOM="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/*.bash ${BASH_IT_CUSTOM:=${BASH_IT} for config_file in $CUSTOM do if [ -e "${config_file}" ]; then + # shellcheck disable=SC1090 source $config_file fi done unset config_file if [[ $PROMPT ]]; then - export PS1="\["$PROMPT"\]" + export PS1="\[""$PROMPT""\]" fi # Adding Support for other OSes PREVIEW="less" [ -s /usr/bin/gloobus-preview ] && PREVIEW="gloobus-preview" +# shellcheck disable=SC2034 [ -s /Applications/Preview.app ] && PREVIEW="/Applications/Preview.app" # Load all the Jekyll stuff if [ -e "$HOME/.jekyllconfig" ] then + # shellcheck disable=SC1090 . "$HOME/.jekyllconfig" fi From be9b0e71c42cfd2d98551a923a391fed8edc2be1 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:16 +0200 Subject: [PATCH 50/65] Removed test filter --- test/run | 1 - 1 file changed, 1 deletion(-) diff --git a/test/run b/test/run index f02f9951..bd4b1c61 100755 --- a/test/run +++ b/test/run @@ -9,5 +9,4 @@ if [ -z "${BASH_IT}" ]; then export BASH_IT=$(cd ${test_directory} && dirname $(pwd)) fi -# exec $bats_executable ${CI:+--tap} ${test_directory}/completion exec $bats_executable ${CI:+--tap} ${test_directory}/{bash_it,completion,install,lib,plugins,themes} From b37da4e1f0cd641a33e827ae423670092def7292 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:16 +0200 Subject: [PATCH 51/65] Updated documentation for global directory --- DEVELOPMENT.md | 8 +++++--- test/README.md | 13 +++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index d9c0abf6..ba9efe60 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -27,17 +27,19 @@ This order is subject to change. For `aliases`, `plugins` and `completions`, the following rules are applied that influence the load order: -* Each type has its own `enabled` directory, into which the enabled components are linked into. Enabled plugins are symlinked from `$BASH_IT/plugins/available` to `$BASH_IT/plugins/enabled` for example. -* Within each of the `enabled` directories, the files are loaded in alphabetical order. +* There is a global `enabled` directory, which the enabled components are linked into. Enabled plugins are symlinked from `$BASH_IT/plugins/available` to `$BASH_IT/enabled` for example. All component types are linked into the same common `$BASH_IT/enabled` directory. +* Within the common `enabled` directories, the files are loaded in alphabetical order, which is based on the item's load priority (see next item). * When enabling a component, a _load priority_ is assigned to the file. The following default priorities are used: * Aliases: 150 * Plugins: 250 * Completions: 350 -* When symlinking a component into an `enabled` directory, the load priority is used as a prefix for the linked name, separated with three dashes from the name of the component. The `node.plugin.bash` would be symlinked to `250---node.plugin.bash` for example. +* When symlinking a component into the `enabled` directory, the load priority is used as a prefix for the linked name, separated with three dashes from the name of the component. The `node.plugin.bash` would be symlinked to `250---node.plugin.bash` for example. * Each file can override the default load priority by specifying a new value. To do this, the file needs to include a comment in the following form. This example would cause the `node.plugin.bash` (if included in that file) to be linked to `225---node.plugin.bash`: ```bash # BASH_IT_LOAD_PRIORITY: 225 ``` +Having the order based on a numeric priority in a common directory allows for more flexibility. While in general, aliases are loaded first (since their default priority is 150), it's possible to load some aliases after the plugins, or some plugins after completions by setting the items' load priority. This is more flexible than a fixed type-based order or a strict alphabetical order based on name. + These items are subject to change. When making changes to the internal functionality, this page needs to be updated as well. diff --git a/test/README.md b/test/README.md index 281b1b6f..d227e3c1 100644 --- a/test/README.md +++ b/test/README.md @@ -1,4 +1,13 @@ ## Testing with [Bats](https://github.com/sstephenson/bats#installing-bats-from-source) + +To execute the unit tests, please run the `run` script: + +```bash +# If you are in the `test` directory: +./run + +# If you are in the root `.bash_it` directory: +test/run ``` -bats test/{lib,plugins} -``` + +The `run` script will automatically install [Bats](https://github.com/sstephenson/bats#installing-bats-from-source) if it is not already present, and will then run all tests found under the `test` directory, including subdirectories. From cd578f877290dfff4fda48f26ede8bf21523d01e Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:16 +0200 Subject: [PATCH 52/65] More tests for completion --- completion/available/bash-it.completion.bash | 2 +- test/completion/bash-it.completion.bats | 26 +++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index dc007ec1..b61692f3 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -2,7 +2,7 @@ _bash-it-comp-enable-disable() { - local enable_disable_args="alias plugin completion" + local enable_disable_args="alias completion plugin" COMPREPLY=( $(compgen -W "${enable_disable_args}" -- ${cur}) ) } diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats index 65984c2b..35d27312 100644 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -43,16 +43,25 @@ function local_teardown { } function __check_completion () { + # Get the parameters as a single value + COMP_LINE=$* + # Get the parameters as an array eval set -- "$@" COMP_WORDS=("$@") - # Get the parameters as a single value - COMP_LINE=$* - # Index of the cursor in the line COMP_POINT=${#COMP_LINE} + # Get the last character of the line that was entered + COMP_LAST=$((${COMP_POINT} - 1)) + + # If the last character was a space... + if [[ ${COMP_LINE:$COMP_LAST} = ' ' ]]; then + # ...then add an empty array item + COMP_WORDS+=('') + fi + # Word index of the last word COMP_CWORD=$(( ${#COMP_WORDS[@]} - 1 )) @@ -68,6 +77,17 @@ function __check_completion () { assert_line "0" "vagrant vault vim" } +@test "completion bash-it: disable - show options" { + run __check_completion 'bash-it disable ' + assert_line "0" "alias completion plugin" +} + +@test "completion bash-it: disable - show options a" { + run __check_completion 'bash-it disable a' + + assert_line "0" "alias" +} + @test "completion bash-it: disable - provide nothing when atom is not enabled" { run __check_completion 'bash-it disable alias ato' assert_line "0" "" From 5c66f478dd8163120046653ad60c1aa7c52625e6 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:17 +0200 Subject: [PATCH 53/65] Completed test suite for Bash-it completion --- completion/available/bash-it.completion.bash | 6 +- test/completion/bash-it.completion.bats | 92 +++++++++++++++++++- 2 files changed, 93 insertions(+), 5 deletions(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index b61692f3..705edd94 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -65,10 +65,10 @@ _bash-it-comp() prev="${COMP_WORDS[COMP_CWORD-1]}" chose_opt="${COMP_WORDS[1]}" file_type="${COMP_WORDS[2]}" - opts="help show enable disable update search migrate" + opts="disable enable help migrate search show update" case "${chose_opt}" in show) - local show_args="plugins aliases completions" + local show_args="aliases completions plugins" COMPREPLY=( $(compgen -W "${show_args}" -- ${cur}) ) return 0 ;; @@ -77,7 +77,7 @@ _bash-it-comp() _bash-it-comp-list-available aliases return 0 else - local help_args="plugins aliases completions migrate update" + local help_args="aliases completions migrate plugins update" COMPREPLY=( $(compgen -W "${help_args}" -- ${cur}) ) return 0 fi diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats index 35d27312..e2f1f415 100644 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -72,11 +72,76 @@ function __check_completion () { echo "${COMPREPLY[@]}" } -@test "completion bash-it: help aliases" { +@test "completion bash-it: help - show options" { + run __check_completion 'bash-it help ' + assert_line "0" "aliases completions migrate plugins update" +} + +@test "completion bash-it: help - aliases v" { run __check_completion 'bash-it help aliases v' assert_line "0" "vagrant vault vim" } +@test "completion bash-it: update - show no options" { + run __check_completion 'bash-it update ' + assert_line "0" "" +} + +@test "completion bash-it: search - show no options" { + run __check_completion 'bash-it search ' + assert_line "0" "" +} + +@test "completion bash-it: migrate - show no options" { + run __check_completion 'bash-it migrate ' + assert_line "0" "" +} + +@test "completion bash-it: show options" { + run __check_completion 'bash-it ' + assert_line "0" "disable enable help migrate search show update" +} + +@test "completion bash-it: bash-ti - show options" { + run __check_completion 'bash-ti ' + assert_line "0" "disable enable help migrate search show update" +} + +@test "completion bash-it: shit - show options" { + run __check_completion 'shit ' + assert_line "0" "disable enable help migrate search show update" +} + +@test "completion bash-it: bashit - show options" { + run __check_completion 'bashit ' + assert_line "0" "disable enable help migrate search show update" +} + +@test "completion bash-it: batshit - show options" { + run __check_completion 'batshit ' + assert_line "0" "disable enable help migrate search show update" +} + +@test "completion bash-it: bash_it - show options" { + run __check_completion 'bash_it ' + assert_line "0" "disable enable help migrate search show update" +} + +@test "completion bash-it: show - show options" { + run __check_completion 'bash-it show ' + assert_line "0" "aliases completions plugins" +} + +@test "completion bash-it: enable - show options" { + run __check_completion 'bash-it enable ' + assert_line "0" "alias completion plugin" +} + +@test "completion bash-it: enable - show options a" { + run __check_completion 'bash-it enable a' + assert_line "0" "alias" +} + @test "completion bash-it: disable - show options" { run __check_completion 'bash-it disable ' assert_line "0" "alias completion plugin" @@ -84,7 +149,6 @@ function __check_completion () { @test "completion bash-it: disable - show options a" { run __check_completion 'bash-it disable a' - assert_line "0" "alias" } @@ -255,6 +319,30 @@ function __check_completion () { assert_line "0" "docker-compose docker-machine docker" } +@test "completion bash-it: enable - provide the docker-* completions when nothing is enabled with the old location and name" { + ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/docker-compose.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" ] + + run __check_completion 'bash-it enable completion docker' + assert_line "0" "docker docker-compose docker-machine" +} + +@test "completion bash-it: enable - provide the docker-* completions when nothing is enabled with the old location and priority-based name" { + ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/150---docker-compose.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" ] + + run __check_completion 'bash-it enable completion docker' + assert_line "0" "docker docker-compose docker-machine" +} + +@test "completion bash-it: enable - provide the docker-* completions when nothing is enabled with the new location and priority-based name" { + ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/enabled/150---docker-compose.aliases.bash + assert [ -L "$BASH_IT/enabled/150---docker-compose.aliases.bash" ] + + run __check_completion 'bash-it enable completion docker' + assert_line "0" "docker docker-compose docker-machine" +} + @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and name" { ln -s $BASH_IT/plugins/available/todo.plugin.bash $BASH_IT/plugins/enabled/todo.plugin.bash assert [ -L "$BASH_IT/plugins/enabled/todo.plugin.bash" ] From aa9a63a10e25a0382a454416c62c04f79896674a Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:17 +0200 Subject: [PATCH 54/65] Added message after migrating about possible fixes. See #985 for background. --- lib/helpers.bash | 10 ++++++++++ test/lib/helpers.bats | 6 ++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 3223b524..779e500b 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -187,6 +187,9 @@ _bash-it-migrate() { _about 'migrates Bash-it configuration from a previous format to the current one' _group 'lib' + declare migrated_something + migrated_something=false + for file_type in "aliases" "plugins" "completion" do for f in `sort <(compgen -G "${BASH_IT}/$file_type/enabled/*.bash")` @@ -198,6 +201,8 @@ _bash-it-migrate() { # Cut off the optional "250---" prefix and the suffix typeset component_name=$(echo $ff | sed -e 's/[0-9]*[-]*\(.*\)\..*\.bash/\1/g') + migrated_something=true + echo "Migrating $single_type $component_name." disable_func="_disable-$single_type" @@ -207,6 +212,11 @@ _bash-it-migrate() { $enable_func $component_name done done + + if [ "$migrated_something" = "true" ]; then + echo "" + echo "If any migration errors were reported, please try the following: reload && bash-it migrate" + fi } _bash-it-describe () diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index cd721871..4a92d09e 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -391,7 +391,8 @@ function __migrate_all_components() { assert_line "0" 'Migrating plugin nvm.' assert_line "1" 'nvm disabled.' assert_line "2" 'nvm enabled with priority 225.' - assert_line "3" 'node enabled with priority 250.' + assert_line "3" 'If any migration errors were reported, please try the following: reload && bash-it migrate' + assert_line "4" 'node enabled with priority 250.' assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] @@ -410,7 +411,8 @@ function __migrate_all_components() { assert_line "3" 'Migrating plugin nvm.' assert_line "4" 'nvm disabled.' assert_line "5" 'nvm enabled with priority 225.' - assert_line "6" 'node disabled.' + assert_line "6" 'If any migration errors were reported, please try the following: reload && bash-it migrate' + assert_line "7" 'node disabled.' assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] assert [ ! -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] From 1a80d892adf5e1efcee09d551a454e294c6db8ae Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:17 +0200 Subject: [PATCH 55/65] Made sorting of completions consistent across OS --- completion/available/bash-it.completion.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 705edd94..e59b3fb1 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -12,7 +12,7 @@ _bash-it-comp-list-available-not-enabled() local available_things - available_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sort`; + available_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sort -d`; do file_entity=$(basename $f) @@ -35,7 +35,7 @@ _bash-it-comp-list-enabled() suffix=$(echo "$subdirectory" | sed -e 's/plugins/plugin/g') - enabled_things=$(for f in `sort <(compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash") <(compgen -G "${BASH_IT}/enabled/*.${suffix}.bash")`; + enabled_things=$(for f in `sort -d <(compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash") <(compgen -G "${BASH_IT}/enabled/*.${suffix}.bash")`; do basename $f | sed -e 's/\(.*\)\..*\.bash/\1/g' | sed -e "s/^[0-9]*---//g" done) @@ -49,7 +49,7 @@ _bash-it-comp-list-available() local enabled_things - enabled_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sort`; + enabled_things=$(for f in `compgen -G "${BASH_IT}/$subdirectory/available/*.bash" | sort -d`; do basename $f | sed -e 's/\(.*\)\..*\.bash/\1/g' done) From f57bd1e1314080be721567c87d1bb37831055c34 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:17 +0200 Subject: [PATCH 56/65] Fixed issues with migrating components with the same name dirs.plugin.bash was recognized while looking for dirs.completion.bash in the global enabled directory. --- lib/helpers.bash | 10 +++++----- test/lib/helpers.bats | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 779e500b..bd284dd8 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -303,10 +303,10 @@ _disable-thing () return fi - if [ "$file_entity" = "all" ]; then - typeset f $file_type suffix - suffix=$(echo "$subdirectory" | sed -e 's/plugins/plugin/g') + typeset f suffix + suffix=$(echo "$subdirectory" | sed -e 's/plugins/plugin/g') + if [ "$file_entity" = "all" ]; then # Disable everything that's using the old structure for f in `compgen -G "${BASH_IT}/$subdirectory/enabled/*.${suffix}.bash"` do @@ -319,13 +319,13 @@ _disable-thing () rm "$f" done else - typeset plugin_global=$(command ls $ "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.*bash 2>/dev/null | head -1) + typeset plugin_global=$(command ls $ "${BASH_IT}/enabled/"[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash 2>/dev/null | head -1) if [ -z "$plugin_global" ]; then # Use a glob to search for both possible patterns # 250---node.plugin.bash # node.plugin.bash # Either one will be matched by this glob - typeset plugin=$(command ls $ "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.*bash,$file_entity.*bash} 2>/dev/null | head -1) + typeset plugin=$(command ls $ "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.$suffix.bash,$file_entity.$suffix.bash} 2>/dev/null | head -1) if [ -z "$plugin" ]; then printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type." return diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 4a92d09e..99cd2501 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -251,6 +251,28 @@ function local_setup { assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] } +@test "helpers: migrate plugins and completions that share the same name" { + ln -s $BASH_IT/completion/available/dirs.completion.bash $BASH_IT/completion/enabled/350---dirs.completion.bash + assert [ -L "$BASH_IT/completion/enabled/350---dirs.completion.bash" ] + + ln -s $BASH_IT/plugins/available/dirs.plugin.bash $BASH_IT/plugins/enabled/250---dirs.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/250---dirs.plugin.bash" ] + + run _bash-it-migrate + assert_line "0" 'Migrating plugin dirs.' + assert_line "1" 'dirs disabled.' + assert_line "2" 'dirs enabled with priority 250.' + assert_line "3" 'Migrating completion dirs.' + assert_line "4" 'dirs disabled.' + assert_line "5" 'dirs enabled with priority 350.' + assert_line "6" 'If any migration errors were reported, please try the following: reload && bash-it migrate' + + assert [ -L "$BASH_IT/enabled/350---dirs.completion.bash" ] + assert [ -L "$BASH_IT/enabled/250---dirs.plugin.bash" ] + assert [ ! -L "$BASH_IT/completion/enabled/350----dirs.completion.bash" ] + assert [ ! -L "$BASH_IT/plugins/enabled/250----dirs.plugin.bash" ] +} + @test "helpers: migrate enabled plugins that don't use the new priority-based configuration" { ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] @@ -265,6 +287,9 @@ function local_setup { assert [ -L "$BASH_IT/enabled/250---ssh.plugin.bash" ] run _bash-it-migrate + assert_line "0" 'Migrating alias todo.txt-cli.' + assert_line "1" 'todo.txt-cli disabled.' + assert_line "2" 'todo.txt-cli enabled with priority 150.' assert [ -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] assert [ -L "$BASH_IT/enabled/250---node.plugin.bash" ] From fb6fcaeb06a6a3dd4ccbf3684e2868839523b954 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:17 +0200 Subject: [PATCH 57/65] Fixed test case where the bash_it.sh would fail with a non-zero return value This was caused by the way the check for installed preview apps was handled. --- bash_it.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bash_it.sh b/bash_it.sh index ab848974..504e26b0 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -91,9 +91,13 @@ fi # Adding Support for other OSes PREVIEW="less" -[ -s /usr/bin/gloobus-preview ] && PREVIEW="gloobus-preview" -# shellcheck disable=SC2034 -[ -s /Applications/Preview.app ] && PREVIEW="/Applications/Preview.app" + +if [ -s /usr/bin/gloobus-preview ]; then + PREVIEW="gloobus-preview" +elif [ -s /Applications/Preview.app ]; then + # shellcheck disable=SC2034 + PREVIEW="/Applications/Preview.app" +fi # Load all the Jekyll stuff From 5210707da8ab4e6ae0f04a4f4f0a491c9713e285 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:17 +0200 Subject: [PATCH 58/65] Test cases for loading from global directory --- lib/helpers.bash | 15 --- test/bash_it/bash_it.bats | 106 ++++++++++++++++++ .../bash_it/aliases/available/a.aliases.bash | 3 + .../bash_it/aliases/available/b.aliases.bash | 3 + .../bash_it/plugins/available/c.plugin.bash | 3 + 5 files changed, 115 insertions(+), 15 deletions(-) create mode 100644 test/fixtures/bash_it/aliases/available/a.aliases.bash create mode 100644 test/fixtures/bash_it/aliases/available/b.aliases.bash create mode 100644 test/fixtures/bash_it/plugins/available/c.plugin.bash diff --git a/lib/helpers.bash b/lib/helpers.bash index bd284dd8..c08403d8 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -18,21 +18,6 @@ function _load_bash_it_files() { fi done fi - - # In the new structure - if [ -d "${BASH_IT}/enabled" ] - then - declare suffix - suffix=$(echo "$subdirectory" | sed -e 's/plugins/plugin/g') - - FILES="${BASH_IT}/enabled/*.${suffix}.bash" - for config_file in $FILES - do - if [ -e "${config_file}" ]; then - source $config_file - fi - done - fi } # Function for reloading aliases diff --git a/test/bash_it/bash_it.bats b/test/bash_it/bash_it.bats index 3fc5e808..92dda192 100644 --- a/test/bash_it/bash_it.bats +++ b/test/bash_it/bash_it.bats @@ -15,6 +15,9 @@ function local_setup { rm -rf "$BASH_IT"/completion/enabled rm -rf "$BASH_IT"/plugins/enabled + cp -r "$BASH_IT/test/fixtures/bash_it/aliases" "$BASH_IT" + cp -r "$BASH_IT/test/fixtures/bash_it/plugins" "$BASH_IT" + # Don't pollute the user's actual $HOME directory # Use a test home directory instead export BASH_IT_TEST_CURRENT_HOME="${HOME}" @@ -31,6 +34,109 @@ function local_teardown { assert_equal "${BASH_IT_TEST_CURRENT_HOME}" "${HOME}" } +@test "bash-it: verify that the test fixture is available" { + assert [ -e "$BASH_IT/aliases/available/a.aliases.bash" ] + assert [ -e "$BASH_IT/aliases/available/b.aliases.bash" ] +} + +@test "bash-it: load aliases in order" { + mkdir -p $BASH_IT/aliases/enabled + mkdir -p $BASH_IT/plugins/enabled + + ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/250---base.plugin.bash" ] + + ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/150---a.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/150---a.aliases.bash" ] + ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/150---b.aliases.bash" ] + + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure + + load "$BASH_IT/bash_it.sh" + + run alias test_alias &> /dev/null + assert_success + assert_line "0" "alias test_alias='b'" +} + +@test "bash-it: load aliases in priority order" { + mkdir -p $BASH_IT/aliases/enabled + mkdir -p $BASH_IT/plugins/enabled + + ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/250---base.plugin.bash" ] + + ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/175---a.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/175---a.aliases.bash" ] + ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/150---b.aliases.bash" ] + + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure + + load "$BASH_IT/bash_it.sh" + + run alias test_alias &> /dev/null + assert_success + assert_line "0" "alias test_alias='a'" +} + +@test "bash-it: load aliases and plugins in priority order" { + mkdir -p $BASH_IT/aliases/enabled + mkdir -p $BASH_IT/plugins/enabled + + ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/250---base.plugin.bash" ] + + ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/150---a.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/150---a.aliases.bash" ] + ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/150---b.aliases.bash" ] + ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/250---c.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/250---c.plugin.bash" ] + + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure + + load "$BASH_IT/bash_it.sh" + + run alias test_alias &> /dev/null + assert_success + assert_line "0" "alias test_alias='c'" +} + +@test "bash-it: load aliases and plugins in priority order, with one alias higher than plugins" { + mkdir -p $BASH_IT/aliases/enabled + mkdir -p $BASH_IT/plugins/enabled + + ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/250---base.plugin.bash" ] + + ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/350---a.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/350---a.aliases.bash" ] + ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/150---b.aliases.bash" ] + ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/250---c.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/250---c.plugin.bash" ] + + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure + + load "$BASH_IT/bash_it.sh" + + run alias test_alias &> /dev/null + assert_success + # This will be c, loaded from the c plugin, since the individual directories + # are loaded one by one. + assert_line "0" "alias test_alias='c'" +} + @test "bash-it: load enabled aliases from new structure, priority-based" { mkdir -p $BASH_IT/enabled ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/enabled/150---atom.aliases.bash diff --git a/test/fixtures/bash_it/aliases/available/a.aliases.bash b/test/fixtures/bash_it/aliases/available/a.aliases.bash new file mode 100644 index 00000000..9dede3f6 --- /dev/null +++ b/test/fixtures/bash_it/aliases/available/a.aliases.bash @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +alias test_alias="a" diff --git a/test/fixtures/bash_it/aliases/available/b.aliases.bash b/test/fixtures/bash_it/aliases/available/b.aliases.bash new file mode 100644 index 00000000..4f90a7ad --- /dev/null +++ b/test/fixtures/bash_it/aliases/available/b.aliases.bash @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +alias test_alias="b" diff --git a/test/fixtures/bash_it/plugins/available/c.plugin.bash b/test/fixtures/bash_it/plugins/available/c.plugin.bash new file mode 100644 index 00000000..3d17ad7a --- /dev/null +++ b/test/fixtures/bash_it/plugins/available/c.plugin.bash @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +alias test_alias="c" From fd637a3dc6e33dcbb9b78b298dbd78085f1c511b Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:17 +0200 Subject: [PATCH 59/65] Loading components from global enabled directory --- bash_it.sh | 3 ++ lib/helpers.bash | 14 ++++++ test/bash_it/bash_it.bats | 98 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 113 insertions(+), 2 deletions(-) diff --git a/bash_it.sh b/bash_it.sh index 504e26b0..ef2a6d07 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -48,6 +48,9 @@ done # TODO Automatically check for content that needs to be migrated +# Load the global "enabled" directory +_load_global_bash_it_files + # Load enabled aliases, completion, plugins for file_type in "aliases" "plugins" "completion" do diff --git a/lib/helpers.bash b/lib/helpers.bash index c08403d8..1bcf7844 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -20,6 +20,20 @@ function _load_bash_it_files() { fi } +function _load_global_bash_it_files() { + # In the new structure + if [ -d "${BASH_IT}/enabled" ] + then + FILES="${BASH_IT}/enabled/*.bash" + for config_file in $FILES + do + if [ -e "${config_file}" ]; then + source $config_file + fi + done + fi +} + # Function for reloading aliases function reload_aliases() { _load_bash_it_files "aliases" diff --git a/test/bash_it/bash_it.bats b/test/bash_it/bash_it.bats index 92dda192..d41ddbf4 100644 --- a/test/bash_it/bash_it.bats +++ b/test/bash_it/bash_it.bats @@ -15,8 +15,8 @@ function local_setup { rm -rf "$BASH_IT"/completion/enabled rm -rf "$BASH_IT"/plugins/enabled - cp -r "$BASH_IT/test/fixtures/bash_it/aliases" "$BASH_IT" - cp -r "$BASH_IT/test/fixtures/bash_it/plugins" "$BASH_IT" + # Copy the test fixture to the Bash-it folder + rsync -a "$BASH_IT/test/fixtures/bash_it/" "$BASH_IT/" # Don't pollute the user's actual $HOME directory # Use a test home directory instead @@ -137,6 +137,100 @@ function local_teardown { assert_line "0" "alias test_alias='c'" } +@test "bash-it: load global aliases in order" { + mkdir -p $BASH_IT/enabled + + ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash + assert [ -L "$BASH_IT/enabled/250---base.plugin.bash" ] + + ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/150---a.aliases.bash + assert [ -L "$BASH_IT/enabled/150---a.aliases.bash" ] + ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash + assert [ -L "$BASH_IT/enabled/150---b.aliases.bash" ] + + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure + + load "$BASH_IT/bash_it.sh" + + run alias test_alias &> /dev/null + assert_success + assert_line "0" "alias test_alias='b'" +} + +@test "bash-it: load global aliases in priority order" { + mkdir -p $BASH_IT/enabled + + ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash + assert [ -L "$BASH_IT/enabled/250---base.plugin.bash" ] + + ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/175---a.aliases.bash + assert [ -L "$BASH_IT/enabled/175---a.aliases.bash" ] + ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash + assert [ -L "$BASH_IT/enabled/150---b.aliases.bash" ] + + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure + + load "$BASH_IT/bash_it.sh" + + run alias test_alias &> /dev/null + assert_success + assert_line "0" "alias test_alias='a'" +} + +@test "bash-it: load global aliases and plugins in priority order" { + mkdir -p $BASH_IT/enabled + + ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash + assert [ -L "$BASH_IT/enabled/250---base.plugin.bash" ] + + ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/150---a.aliases.bash + assert [ -L "$BASH_IT/enabled/150---a.aliases.bash" ] + ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash + assert [ -L "$BASH_IT/enabled/150---b.aliases.bash" ] + ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/enabled/250---c.plugin.bash + assert [ -L "$BASH_IT/enabled/250---c.plugin.bash" ] + + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure + + load "$BASH_IT/bash_it.sh" + + run alias test_alias &> /dev/null + assert_success + assert_line "0" "alias test_alias='c'" +} + +@test "bash-it: load global aliases and plugins in priority order, with one alias higher than plugins" { + mkdir -p $BASH_IT/enabled + + ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash + assert [ -L "$BASH_IT/enabled/250---base.plugin.bash" ] + + ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/350---a.aliases.bash + assert [ -L "$BASH_IT/enabled/350---a.aliases.bash" ] + ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash + assert [ -L "$BASH_IT/enabled/150---b.aliases.bash" ] + ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/enabled/250---c.plugin.bash + assert [ -L "$BASH_IT/enabled/250---c.plugin.bash" ] + + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure + + load "$BASH_IT/bash_it.sh" + + run alias test_alias &> /dev/null + assert_success + # This will be a, loaded from the a aliases, since the global directory + # loads all component types at once + assert_line "0" "alias test_alias='a'" +} + @test "bash-it: load enabled aliases from new structure, priority-based" { mkdir -p $BASH_IT/enabled ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/enabled/150---atom.aliases.bash From 0fe2710c61b4765c1952d12f08ac899e8aab0591 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:17 +0200 Subject: [PATCH 60/65] More unit tests for loading from global directory structure --- bash_it.sh | 2 - test/bash_it/bash_it.bats | 84 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/bash_it.sh b/bash_it.sh index ef2a6d07..fa6c7b1b 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -46,8 +46,6 @@ do fi done -# TODO Automatically check for content that needs to be migrated - # Load the global "enabled" directory _load_global_bash_it_files diff --git a/test/bash_it/bash_it.bats b/test/bash_it/bash_it.bats index d41ddbf4..ccd0c9a5 100644 --- a/test/bash_it/bash_it.bats +++ b/test/bash_it/bash_it.bats @@ -110,6 +110,60 @@ function local_teardown { assert_line "0" "alias test_alias='c'" } +@test "bash-it: load aliases, plugins and completions in priority order" { + mkdir -p $BASH_IT/aliases/enabled + mkdir -p $BASH_IT/plugins/enabled + mkdir -p $BASH_IT/completion/enabled + + ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/250---base.plugin.bash" ] + + ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/150---a.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/150---a.aliases.bash" ] + ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/completion/enabled/350---b.completion.bash + assert [ -L "$BASH_IT/completion/enabled/350---b.completion.bash" ] + ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/250---c.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/250---c.plugin.bash" ] + + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure + + load "$BASH_IT/bash_it.sh" + + run alias test_alias &> /dev/null + assert_success + # "b" wins since completions are loaded last in the old directory structure + assert_line "0" "alias test_alias='b'" +} + +@test "bash-it: load aliases, plugins and completions in priority order, even if the priority says otherwise" { + mkdir -p $BASH_IT/aliases/enabled + mkdir -p $BASH_IT/plugins/enabled + mkdir -p $BASH_IT/completion/enabled + + ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/250---base.plugin.bash" ] + + ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/450---a.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/450---a.aliases.bash" ] + ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/completion/enabled/350---b.completion.bash + assert [ -L "$BASH_IT/completion/enabled/350---b.completion.bash" ] + ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/950---c.plugin.bash + assert [ -L "$BASH_IT/plugins/enabled/950---c.plugin.bash" ] + + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure + + load "$BASH_IT/bash_it.sh" + + run alias test_alias &> /dev/null + assert_success + # "b" wins since completions are loaded last in the old directory structure + assert_line "0" "alias test_alias='b'" +} + @test "bash-it: load aliases and plugins in priority order, with one alias higher than plugins" { mkdir -p $BASH_IT/aliases/enabled mkdir -p $BASH_IT/plugins/enabled @@ -231,6 +285,36 @@ function local_teardown { assert_line "0" "alias test_alias='a'" } +@test "bash-it: load global aliases and plugins in priority order, individual old directories are loaded later" { + mkdir -p $BASH_IT/enabled + mkdir -p $BASH_IT/aliases/enabled + + ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash + assert [ -L "$BASH_IT/enabled/250---base.plugin.bash" ] + + ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/350---a.aliases.bash + assert [ -L "$BASH_IT/enabled/350---a.aliases.bash" ] + ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash + assert [ -L "$BASH_IT/enabled/150---b.aliases.bash" ] + ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/enabled/250---c.plugin.bash + assert [ -L "$BASH_IT/enabled/250---c.plugin.bash" ] + # Add one file in the old directory structure + ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash + assert [ -L "$BASH_IT/aliases/enabled/150---b.aliases.bash" ] + + # The `test_alias` alias should not exist + run alias test_alias &> /dev/null + assert_failure + + load "$BASH_IT/bash_it.sh" + + run alias test_alias &> /dev/null + assert_success + # This will be "b", loaded from the b aliases in the individual directory, since + # the individual directories are loaded after the global one. + assert_line "0" "alias test_alias='b'" +} + @test "bash-it: load enabled aliases from new structure, priority-based" { mkdir -p $BASH_IT/enabled ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/enabled/150---atom.aliases.bash From 145ec5dfaadfb232d1bf1667a0def72d7b067743 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:17 +0200 Subject: [PATCH 61/65] Copied command_exists function to the helpers lib so that there is no hidden dependency on the base plugin The original command_exists function will stay in the base plugin, but will no longer be used by other plugins or themes. --- lib/helpers.bash | 9 +++++++ plugins/available/battery.plugin.bash | 38 +++++++++++++-------------- test/lib/helpers.bats | 20 ++++++++++++++ test/themes/base.theme.bats | 5 +++- themes/atomic/atomic.theme.bash | 2 +- themes/base.theme.bash | 4 +-- themes/brainy/brainy.theme.bash | 2 +- themes/demula/demula.theme.bash | 2 +- themes/powerline/powerline.base.bash | 4 +-- themes/rana/rana.theme.bash | 2 +- 10 files changed, 60 insertions(+), 28 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 1bcf7844..0405eede 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -5,6 +5,15 @@ BASH_IT_LOAD_PRIORITY_DEFAULT_PLUGIN=${BASH_IT_LOAD_PRIORITY_DEFAULT_PLUGIN:-250 BASH_IT_LOAD_PRIORITY_DEFAULT_COMPLETION=${BASH_IT_LOAD_PRIORITY_DEFAULT_COMPLETION:-350} BASH_IT_LOAD_PRIORITY_SEPARATOR="---" +function _command_exists () +{ + _about 'checks for existence of a command' + _param '1: command to check' + _example '$ _command_exists ls && echo exists' + _group 'lib' + type "$1" &> /dev/null ; +} + # Helper function loading various enable-able files function _load_bash_it_files() { subdirectory="$1" diff --git a/plugins/available/battery.plugin.bash b/plugins/available/battery.plugin.bash index dd941372..0391ca10 100644 --- a/plugins/available/battery.plugin.bash +++ b/plugins/available/battery.plugin.bash @@ -2,23 +2,23 @@ cite about-plugin about-plugin 'display info about your battery charge level' ac_adapter_connected(){ - if command_exists upower; + if _command_exists upower; then upower -i $(upower -e | grep BAT) | grep 'state' | grep -q 'charging\|fully-charged' return $? - elif command_exists acpi; + elif _command_exists acpi; then acpi -a | grep -q "on-line" return $? - elif command_exists pmset; + elif _command_exists pmset; then pmset -g batt | grep -q 'AC Power' return $? - elif command_exists ioreg; + elif _command_exists ioreg; then ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = Yes' return $? - elif command_exists WMIC; + elif _command_exists WMIC; then WMIC Path Win32_Battery Get BatteryStatus /Format:List | grep -q 'BatteryStatus=2' return $? @@ -26,23 +26,23 @@ ac_adapter_connected(){ } ac_adapter_disconnected(){ - if command_exists upower; + if _command_exists upower; then upower -i $(upower -e | grep BAT) | grep 'state' | grep -q 'discharging' return $? - elif command_exists acpi; + elif _command_exists acpi; then acpi -a | grep -q "off-line" return $? - elif command_exists pmset; + elif _command_exists pmset; then pmset -g batt | grep -q 'Battery Power' return $? - elif command_exists ioreg; + elif _command_exists ioreg; then ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = No' return $? - elif command_exists WMIC; + elif _command_exists WMIC; then WMIC Path Win32_Battery Get BatteryStatus /Format:List | grep -q 'BatteryStatus=1' return $? @@ -52,12 +52,12 @@ ac_adapter_disconnected(){ battery_percentage(){ about 'displays battery charge as a percentage of full (100%)' group 'battery' - - if command_exists upower; + + if _command_exists upower; then local UPOWER_OUTPUT=$(upower --show-info $(upower --enumerate | grep BAT) | grep percentage | tail --bytes 5) echo ${UPOWER_OUTPUT: : -1} - elif command_exists acpi; + elif _command_exists acpi; then local ACPI_OUTPUT=$(acpi -b) case $ACPI_OUTPUT in @@ -72,7 +72,7 @@ battery_percentage(){ ;; esac ;; - + *" Charging"* | *" Discharging"*) local PERC_OUTPUT=$(echo $ACPI_OUTPUT | awk -F, '/,/{gsub(/ /, "", $0); gsub(/%/,"", $0); print $2}' ) echo ${PERC_OUTPUT} @@ -84,7 +84,7 @@ battery_percentage(){ echo '-1' ;; esac - elif command_exists pmset; + elif _command_exists pmset; then local PMSET_OUTPUT=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p') case $PMSET_OUTPUT in @@ -95,7 +95,7 @@ battery_percentage(){ echo $PMSET_OUTPUT | head -c 2 ;; esac - elif command_exists ioreg; + elif _command_exists ioreg; then local IOREG_OUTPUT=$(ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%05.2f%%"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}') case $IOREG_OUTPUT in @@ -106,7 +106,7 @@ battery_percentage(){ echo $IOREG_OUTPUT | head -c 2 ;; esac - elif command_exists WMIC; + elif _command_exists WMIC; then local WINPC=$(echo porcent=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List) | grep -o '[0-9]*') case $WINPC in @@ -125,7 +125,7 @@ battery_percentage(){ battery_charge(){ about 'graphical display of your battery charge' group 'battery' - + # Full char local F_C='▸' # Depleted char @@ -136,7 +136,7 @@ battery_charge(){ local DANGER_COLOR="${red}" local BATTERY_OUTPUT="${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${D_C}" local BATTERY_PERC=$(battery_percentage) - + case $BATTERY_PERC in no) echo "" diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 99cd2501..7398e08a 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -30,6 +30,26 @@ function local_setup { # TODO Create global __get_base_name function # TODO Create global __get_enabled_name function +@test "helpers: _command_exists function exists" { + type -a _command_exists &> /dev/null + assert_success +} + +@test "helpers: _command_exists function positive test ls" { + run _command_exists ls + assert_success +} + +@test "helpers: _command_exists function positive test bash-it" { + run _command_exists bash-it + assert_success +} + +@test "helpers: _command_exists function negative test" { + run _command_exists __addfkds_dfdsjdf + assert_failure +} + @test "helpers: bash-it help aliases ag" { run bash-it help aliases "ag" assert_line "0" "ag='ag --smart-case --pager=\"less -MIRFX'" diff --git a/test/themes/base.theme.bats b/test/themes/base.theme.bats index 6bf7efed..ab320c81 100644 --- a/test/themes/base.theme.bats +++ b/test/themes/base.theme.bats @@ -2,7 +2,10 @@ load ../test_helper load ../../lib/composure -load ../../plugins/available/base.plugin + +cite _about _param _example _group _author _version + +load ../../lib/helpers load ../../themes/base.theme @test 'themes base: battery_percentage should not exist' { diff --git a/themes/atomic/atomic.theme.bash b/themes/atomic/atomic.theme.bash index 6dd7ea04..a89aeea3 100644 --- a/themes/atomic/atomic.theme.bash +++ b/themes/atomic/atomic.theme.bash @@ -164,7 +164,7 @@ ___atomic_prompt_clock() { } ___atomic_prompt_battery() { - ! command_exists battery_percentage || + ! _command_exists battery_percentage || [ "${THEME_SHOW_BATTERY}" != "true" ] || [ "$(battery_percentage)" = "no" ] && return diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 58e2d288..66ce7de9 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -474,7 +474,7 @@ function battery_char { fi } -if ! command_exists battery_charge ; then +if ! _command_exists battery_charge ; then # if user has installed battery plugin, skip this... function battery_charge (){ # no op @@ -484,7 +484,7 @@ fi # The battery_char function depends on the presence of the battery_percentage function. # If battery_percentage is not defined, then define battery_char as a no-op. -if ! command_exists battery_percentage ; then +if ! _command_exists battery_percentage ; then function battery_char (){ # no op echo -n diff --git a/themes/brainy/brainy.theme.bash b/themes/brainy/brainy.theme.bash index 54d29f8b..c3aa9b83 100644 --- a/themes/brainy/brainy.theme.bash +++ b/themes/brainy/brainy.theme.bash @@ -152,7 +152,7 @@ ___brainy_prompt_clock() { } ___brainy_prompt_battery() { - ! command_exists battery_percentage || + ! _command_exists battery_percentage || [ "${THEME_SHOW_BATTERY}" != "true" ] || [ "$(battery_percentage)" = "no" ] && return diff --git a/themes/demula/demula.theme.bash b/themes/demula/demula.theme.bash index e698def5..515d096d 100644 --- a/themes/demula/demula.theme.bash +++ b/themes/demula/demula.theme.bash @@ -84,7 +84,7 @@ ${D_BRANCH_COLOR}%b %r ${D_CHANGES_COLOR}%m%u ${D_DEFAULT_COLOR}" # checks if the plugin is installed before calling battery_charge safe_battery_charge() { - if command_exists battery_charge ; + if _command_exists battery_charge ; then battery_charge fi diff --git a/themes/powerline/powerline.base.bash b/themes/powerline/powerline.base.bash index f65e9dd6..6646814a 100644 --- a/themes/powerline/powerline.base.bash +++ b/themes/powerline/powerline.base.bash @@ -43,9 +43,9 @@ function __powerline_user_info_prompt { function __powerline_ruby_prompt { local ruby_version="" - if command_exists rvm; then + if _command_exists rvm; then ruby_version="$(rvm_version_prompt)" - elif command_exists rbenv; then + elif _command_exists rbenv; then ruby_version=$(rbenv_version_prompt) fi diff --git a/themes/rana/rana.theme.bash b/themes/rana/rana.theme.bash index 0aed8348..25530397 100644 --- a/themes/rana/rana.theme.bash +++ b/themes/rana/rana.theme.bash @@ -117,7 +117,7 @@ ${D_BRANCH_COLOR}%b %r ${D_CHANGES_COLOR}%m%u ${D_DEFAULT_COLOR}" # checks if the plugin is installed before calling battery_charge safe_battery_charge() { - if command_exists battery_charge ; + if _command_exists battery_charge ; then battery_charge fi From f4fa9def147c0a1add5c4ff737434d0322c57fe5 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:17 +0200 Subject: [PATCH 62/65] Fixed the ruby path test in cases where someone already has the ruby bin path on their path variable --- test/plugins/ruby.plugin.bats | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/plugins/ruby.plugin.bats b/test/plugins/ruby.plugin.bats index c5f13733..8d0b53e9 100755 --- a/test/plugins/ruby.plugin.bats +++ b/test/plugins/ruby.plugin.bats @@ -15,6 +15,12 @@ load ../../plugins/available/ruby.plugin skip 'ruby not installed' fi - last_path_entry=$(echo $PATH | tr ":" "\n" | tail -1); + # Reset the path for this test to ensure that the ruby directory is not part of the path yet. + PATH="/usr/local/bin:/usr/bin:/bin" + + # Then load the ruby plugin again to ensure that the ruby path is appended at the end of the path + load ../../plugins/available/ruby.plugin + + local last_path_entry=$(echo $PATH | tr ":" "\n" | tail -1) [[ "${last_path_entry}" == "${HOME}"/.gem/ruby/*/bin ]] } From 548563e7aa2e8f0faf0995f542523add28a01202 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:17 +0200 Subject: [PATCH 63/65] Trying to fix path issue --- test/plugins/ruby.plugin.bats | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/plugins/ruby.plugin.bats b/test/plugins/ruby.plugin.bats index 8d0b53e9..17b2f1ea 100755 --- a/test/plugins/ruby.plugin.bats +++ b/test/plugins/ruby.plugin.bats @@ -21,6 +21,8 @@ load ../../plugins/available/ruby.plugin # Then load the ruby plugin again to ensure that the ruby path is appended at the end of the path load ../../plugins/available/ruby.plugin + echo $PATH + local last_path_entry=$(echo $PATH | tr ":" "\n" | tail -1) [[ "${last_path_entry}" == "${HOME}"/.gem/ruby/*/bin ]] } From 310360964055c428247e628d7d1b529ab7421499 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:17 +0200 Subject: [PATCH 64/65] Reverted Ruby path fix --- test/plugins/ruby.plugin.bats | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/plugins/ruby.plugin.bats b/test/plugins/ruby.plugin.bats index 17b2f1ea..4b16bacd 100755 --- a/test/plugins/ruby.plugin.bats +++ b/test/plugins/ruby.plugin.bats @@ -15,14 +15,6 @@ load ../../plugins/available/ruby.plugin skip 'ruby not installed' fi - # Reset the path for this test to ensure that the ruby directory is not part of the path yet. - PATH="/usr/local/bin:/usr/bin:/bin" - - # Then load the ruby plugin again to ensure that the ruby path is appended at the end of the path - load ../../plugins/available/ruby.plugin - - echo $PATH - local last_path_entry=$(echo $PATH | tr ":" "\n" | tail -1) [[ "${last_path_entry}" == "${HOME}"/.gem/ruby/*/bin ]] } From 3f6f1326dc7560cd8c7da453fea3177b2b64f6b2 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 15 Sep 2017 08:10:17 +0200 Subject: [PATCH 65/65] Fixed ruby test for good (hopefully) --- test/plugins/ruby.plugin.bats | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/plugins/ruby.plugin.bats b/test/plugins/ruby.plugin.bats index 4b16bacd..a57e45fc 100755 --- a/test/plugins/ruby.plugin.bats +++ b/test/plugins/ruby.plugin.bats @@ -5,6 +5,32 @@ load ../../lib/helpers load ../../lib/composure load ../../plugins/available/ruby.plugin +function local_setup { + mkdir -p "$BASH_IT" + lib_directory="$(cd "$(dirname "$0")" && pwd)" + # Use rsync to copy Bash-it to the temp folder + # rsync is faster than cp, since we can exclude the large ".git" folder + rsync -qavrKL -d --delete-excluded --exclude=.git $lib_directory/../.. "$BASH_IT" + + rm -rf "$BASH_IT"/enabled + rm -rf "$BASH_IT"/aliases/enabled + rm -rf "$BASH_IT"/completion/enabled + rm -rf "$BASH_IT"/plugins/enabled + + mkdir -p "$BASH_IT"/enabled + mkdir -p "$BASH_IT"/aliases/enabled + mkdir -p "$BASH_IT"/completion/enabled + mkdir -p "$BASH_IT"/plugins/enabled + + export OLD_PATH="$PATH" + export PATH="/usr/bin:/bin:/usr/sbin" +} + +function local_teardown { + export PATH="$OLD_PATH" + unset OLD_PATH +} + @test "plugins ruby: remove_gem is defined" { run type remove_gem assert_line 1 "remove_gem () " @@ -15,6 +41,8 @@ load ../../plugins/available/ruby.plugin skip 'ruby not installed' fi + load ../../plugins/available/ruby.plugin + local last_path_entry=$(echo $PATH | tr ":" "\n" | tail -1) [[ "${last_path_entry}" == "${HOME}"/.gem/ruby/*/bin ]] }