From 794b1661f6ba00551bac27bba4e4638a840825ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Felipe=20S=C3=A1nchez?= Date: Thu, 15 Jun 2017 15:32:53 -0500 Subject: [PATCH 01/67] Create README.md --- themes/atomic/README.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/themes/atomic/README.md b/themes/atomic/README.md index ddfff4d0..db01a80f 100644 --- a/themes/atomic/README.md +++ b/themes/atomic/README.md @@ -1,6 +1,6 @@ # Atomic theme -Simple colorful terminal prompt theme (inspired by a number of themes and it is based mainly on the theme of @MunifTanjim [`brainy`](themes/brainy/README.md)). +The Best ColorFull terminal prompt theme inspired by a number of themes and based on the theme of @MunifTanjim [`brainy`](../brainy/README.md). Supported on all operating systems. @@ -155,6 +155,15 @@ Three environment variables can be defined to rearrange the segments order. The `___ATOMIC_TOP_LEFT="user_info dir scm"` -`___ATOMIC_TOP_RIGHT="python ruby todo clock battery"` +`___ATOMIC_TOP_RIGHT="exitcode python ruby todo clock battery"` -`___ATOMIC_BOTTOM="exitcode char"` +`___ATOMIC_BOTTOM="char"` + +## Follow me + +I'm on the social media. + +* [@lfelipe1501](https://twitter.com/lfelipe1501) on Twitter. +* [Luis Felipe](https://www.facebook.com/lfelipe1501) on Facebook. + +This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. From d4bc67ffdd9542acad7e11c663fb4c5d6bd87a12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Felipe=20S=C3=A1nchez?= Date: Thu, 15 Jun 2017 15:37:01 -0500 Subject: [PATCH 02/67] Update Theme Minor Fixes --- themes/atomic/atomic.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/atomic/atomic.theme.bash b/themes/atomic/atomic.theme.bash index 8ac18dfd..4e58f014 100644 --- a/themes/atomic/atomic.theme.bash +++ b/themes/atomic/atomic.theme.bash @@ -178,7 +178,7 @@ ___atomic_prompt_battery() { ac_adapter_disconnected && info="-" ac_adapter_connected && info="+" info+=$batp - [ "$info" == "+100" ] && info="AC" + [ "$batp" -eq 100 ] || [ "$batp" -gt 100 ] && info="AC" printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" } From 2d92d9817f85310c7c6b0842a242886320a91cc9 Mon Sep 17 00:00:00 2001 From: shine Date: Sat, 17 Jun 2017 17:36:33 +0530 Subject: [PATCH 03/67] Honor NVM_DIR shell variable set externally --- plugins/available/nvm.plugin.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/available/nvm.plugin.bash b/plugins/available/nvm.plugin.bash index 3959c236..f4ccfdc7 100644 --- a/plugins/available/nvm.plugin.bash +++ b/plugins/available/nvm.plugin.bash @@ -5,7 +5,7 @@ cite about-plugin about-plugin 'node version manager configuration' -export NVM_DIR="$HOME/.nvm" +[ -v $NVM_DIR ] && NVM_DIR="$HOME/.nvm" # This loads nvm if command -v brew &>/dev/null && [ -s $(brew --prefix nvm)/nvm.sh ] then From 76d7dfd8bc5d8373813cbee96e5345f380eb74a8 Mon Sep 17 00:00:00 2001 From: shine Date: Mon, 19 Jun 2017 23:28:12 +0530 Subject: [PATCH 04/67] Resolve https://github.com/Bash-it/bash-it/pull/980#pullrequestreview-44766052 --- plugins/available/nvm.plugin.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/available/nvm.plugin.bash b/plugins/available/nvm.plugin.bash index f4ccfdc7..a36579c2 100644 --- a/plugins/available/nvm.plugin.bash +++ b/plugins/available/nvm.plugin.bash @@ -5,7 +5,7 @@ cite about-plugin about-plugin 'node version manager configuration' -[ -v $NVM_DIR ] && NVM_DIR="$HOME/.nvm" +export NVM_DIR=${NVM_DIR:- $HOME/.nvm} # This loads nvm if command -v brew &>/dev/null && [ -s $(brew --prefix nvm)/nvm.sh ] then From ce5dbbdada3a5fefa91fe86fb919d005f8b87acf Mon Sep 17 00:00:00 2001 From: Andrew Ochsner Date: Tue, 20 Jun 2017 16:40:05 -0500 Subject: [PATCH 05/67] Remove prefixed space --- plugins/available/nvm.plugin.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/available/nvm.plugin.bash b/plugins/available/nvm.plugin.bash index a36579c2..f08fcb61 100644 --- a/plugins/available/nvm.plugin.bash +++ b/plugins/available/nvm.plugin.bash @@ -5,7 +5,7 @@ cite about-plugin about-plugin 'node version manager configuration' -export NVM_DIR=${NVM_DIR:- $HOME/.nvm} +export NVM_DIR=${NVM_DIR:-$HOME/.nvm} # This loads nvm if command -v brew &>/dev/null && [ -s $(brew --prefix nvm)/nvm.sh ] then From ff114660dbc4f229b077db9a41199b861408b4d3 Mon Sep 17 00:00:00 2001 From: Clay Reimann Date: Fri, 23 Jun 2017 09:12:46 -0500 Subject: [PATCH 06/67] Guard against unset COLUMNS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When logging in to a new CentOS 7 machine COLUMNS has not been set before the theme is evaluated, causing the following error: ```shell irongiant-mbp → ssh clayreimann@toren.ddns Last login: Fri Jun 23 10:05:11 2017 from cpe-24-209-155-17.wi.res.rr.com -bash: /1: syntax error: operand expected (error token is "/1") -bash-4.2$ ``` This fix is based on advice from https://stackoverflow.com/a/3601734 --- themes/iterate/iterate.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/iterate/iterate.theme.bash b/themes/iterate/iterate.theme.bash index 2031b7fc..cf682a9f 100644 --- a/themes/iterate/iterate.theme.bash +++ b/themes/iterate/iterate.theme.bash @@ -52,7 +52,7 @@ function prompt_command() { fi local wrap_char="" - [[ ${#new_PS1} -gt $(($COLUMNS/1)) ]] && wrap_char="\n" + [[ $COLUMNS && ${#new_PS1} > $(($COLUMNS/1)) ]] && wrap_char="\n" PS1="${new_PS1}${green}${wrap_char}→${reset_color} " } From 31dd740571c85f21a2aa50aaf4a6e9ae48d8e137 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:04 +0200 Subject: [PATCH 07/67] Added default priority for enable --- lib/helpers.bash | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 1153fc6f..a1045c8f 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -1,3 +1,8 @@ +BASH_IT_LOAD_PRIORITY_DEFAULT_ALIAS=150 +BASH_IT_LOAD_PRIORITY_DEFAULT_PLUGIN=250 +BASH_IT_LOAD_PRIORITY_DEFAULT_COMPLETION=350 +BASH_IT_LOAD_PRIORITY_SEPARATOR="---" + # Helper function loading various enable-able files function _load_bash_it_files() { subdirectory="$1" @@ -256,7 +261,7 @@ _enable-plugin () _example '$ enable-plugin rvm' _group 'lib' - _enable-thing "plugins" "plugin" $1 + _enable-thing "plugins" "plugin" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_PLUGIN } _enable-alias () @@ -266,7 +271,7 @@ _enable-alias () _example '$ enable-alias git' _group 'lib' - _enable-thing "aliases" "alias" $1 + _enable-thing "aliases" "alias" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_ALIAS } _enable-completion () @@ -276,7 +281,7 @@ _enable-completion () _example '$ enable-completion git' _group 'lib' - _enable-thing "completion" "completion" $1 + _enable-thing "completion" "completion" $1 $BASH_IT_LOAD_PRIORITY_DEFAULT_COMPLETION } _enable-thing () @@ -286,11 +291,13 @@ _enable-thing () _param '1: subdirectory' _param '2: file_type' _param '3: file_entity' - _example '$ _enable-thing "plugins" "plugin" "ssh"' + _param '4: load priority' + _example '$ _enable-thing "plugins" "plugin" "ssh" "150"' subdirectory="$1" file_type="$2" file_entity="$3" + load_priority="$4" if [ -z "$file_entity" ]; then reference "enable-$file_type" @@ -303,7 +310,7 @@ _enable-thing () do plugin=$(basename $f) if [ ! -h $BASH_IT/$subdirectory/enabled/$plugin ]; then - ln -s ../available/$plugin $BASH_IT/$subdirectory/enabled/$plugin + ln -s ../available/$plugin $BASH_IT/$subdirectory/enabled/$load_priority$BASH_IT_LOAD_PRIORITY_SEPARATOR$plugin fi done else @@ -314,14 +321,19 @@ _enable-thing () fi plugin=$(basename $plugin) - if [ -e $BASH_IT/$subdirectory/enabled/$plugin ]; then + # Check for existence of the file using a wildcard, since we don't know which priority might have been used when enabling it. + for f in $BASH_IT/$subdirectory/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR$plugin; do + if [ -e "$f" ] ; then printf '%s\n' "$file_entity is already enabled." return - fi + fi + + break + done mkdir -p $BASH_IT/$subdirectory/enabled - ln -s ../available/$plugin $BASH_IT/$subdirectory/enabled/$plugin + ln -s ../available/$plugin $BASH_IT/$subdirectory/enabled/$load_priority$BASH_IT_LOAD_PRIORITY_SEPARATOR$plugin fi if [ -n "$BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE" ]; then From 9a3bd6dc3070e2222800198eb73d655695ebb357 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:04 +0200 Subject: [PATCH 08/67] Added load priority for nvm plugin --- plugins/available/nvm.plugin.bash | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/available/nvm.plugin.bash b/plugins/available/nvm.plugin.bash index f08fcb61..e845d922 100644 --- a/plugins/available/nvm.plugin.bash +++ b/plugins/available/nvm.plugin.bash @@ -1,5 +1,7 @@ # Bash-it no longer bundles nvm, as this was quickly becoming outdated. # +# BASH_IT_LOAD_PRIORITY: 225 +# # Please install nvm from https://github.com/creationix/nvm.git if you want to use it. cite about-plugin From 74b15b638515285884f569452c0a82968d88cb12 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:04 +0200 Subject: [PATCH 09/67] Reading load priority from file --- lib/helpers.bash | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index a1045c8f..0f41488f 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -333,14 +333,18 @@ _enable-thing () mkdir -p $BASH_IT/$subdirectory/enabled - ln -s ../available/$plugin $BASH_IT/$subdirectory/enabled/$load_priority$BASH_IT_LOAD_PRIORITY_SEPARATOR$plugin + # Load the priority from the file if it present there + local local_file_priority=$(grep -E "^# BASH_IT_LOAD_PRIORITY:" $BASH_IT/$subdirectory/available/$plugin | awk -F': ' '{ print $2 }') + local use_load_priority=${local_file_priority:-$load_priority} + + ln -s ../available/$plugin $BASH_IT/$subdirectory/enabled/$use_load_priority$BASH_IT_LOAD_PRIORITY_SEPARATOR$plugin fi if [ -n "$BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE" ]; then exec ${0/-/} fi - printf '%s\n' "$file_entity enabled." + printf '%s\n' "$file_entity enabled with priority $use_load_priority." } _help-completions() From feb05b279be9dcf1ba0e87d2eed50cc9544c8f96 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:04 +0200 Subject: [PATCH 10/67] Changed enable all functionality to call recursive enable --- lib/helpers.bash | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 0f41488f..20186cec 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -308,10 +308,8 @@ _enable-thing () typeset f $file_type for f in $BASH_IT/$subdirectory/available/*.bash do - plugin=$(basename $f) - if [ ! -h $BASH_IT/$subdirectory/enabled/$plugin ]; then - ln -s ../available/$plugin $BASH_IT/$subdirectory/enabled/$load_priority$BASH_IT_LOAD_PRIORITY_SEPARATOR$plugin - fi + plugin=$(basename -s .$file_type.bash $f) + _enable-thing $subdirectory $file_type $plugin $load_priority done else typeset plugin=$(command ls $BASH_IT/$subdirectory/available/$file_entity.*bash 2>/dev/null | head -1) From dce0ac5b34f385741e9015008454153448e45df3 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:05 +0200 Subject: [PATCH 11/67] Adjusted show function to use the new format --- lib/helpers.bash | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 20186cec..b8258f99 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -1,6 +1,6 @@ -BASH_IT_LOAD_PRIORITY_DEFAULT_ALIAS=150 -BASH_IT_LOAD_PRIORITY_DEFAULT_PLUGIN=250 -BASH_IT_LOAD_PRIORITY_DEFAULT_COMPLETION=350 +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} BASH_IT_LOAD_PRIORITY_SEPARATOR="---" # Helper function loading various enable-able files @@ -169,7 +169,8 @@ _bash-it-describe () printf "%-20s%-10s%s\n" "$column_header" 'Enabled?' 'Description' for f in $BASH_IT/$subdirectory/available/*.bash do - if [ -e $BASH_IT/$subdirectory/enabled/$(basename $f) ]; then + # 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 enabled='x' else enabled=' ' From cc8621a88817ba655cc9f0c38afb46fd73736b54 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:05 +0200 Subject: [PATCH 12/67] Disabling a single component will support both patterns The old pattern with just the name (node.plugin.bash) and the new one with the load priority (250---node.plugin.bash). --- lib/helpers.bash | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index b8258f99..f9b8aa7b 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -240,7 +240,11 @@ _disable-thing () fi done else - typeset plugin=$(command ls $BASH_IT/$subdirectory/enabled/$file_entity.*bash 2>/dev/null | head -1) + # 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 From 098186754cff179dd0136b80b5a1ab31be85f786 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:05 +0200 Subject: [PATCH 13/67] Added test suite for enable/disable --- test/lib/helpers.bats | 100 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 4f3e4ffa..3faddc6b 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -1,5 +1,6 @@ #!/usr/bin/env bats +load ../test_helper load ../../lib/composure load ../../plugins/available/base.plugin @@ -7,4 +8,101 @@ cite _about _param _example _group _author _version load ../../lib/helpers -## TODO: write some tests. +function __setup_plugin_tests { + mkdir -p $BASH_IT/plugins + cp -r ../plugins/available $BASH_IT/plugins + mkdir -p $BASH_IT/plugins/enabled +} + +@test "enable the node plugin" { + __setup_plugin_tests + + run _enable-plugin "node" + [ "${lines[0]}" == 'node enabled with priority 250.' ] + [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] +} + +@test "enable the nvm plugin" { + __setup_plugin_tests + + run _enable-plugin "nvm" + [ "${lines[0]}" == 'nvm enabled with priority 225.' ] + [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] +} + +@test "enable an unknown plugin" { + __setup_plugin_tests + + run _enable-plugin "unknown-foo" + [ "${lines[0]}" == 'sorry, unknown-foo does not appear to be an available plugin.' ] + [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ] + [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ] +} + +@test "disable a plugin that is not enabled" { + __setup_plugin_tests + + run _disable-plugin "sdkman" + [ "${lines[0]}" == 'sorry, sdkman does not appear to be an enabled plugin.' ] +} + +@test "enable and disable the nvm plugin" { + __setup_plugin_tests + + run _enable-plugin "nvm" + [ "${lines[0]}" == 'nvm enabled with priority 225.' ] + [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + + run _disable-plugin "nvm" + [ "${lines[0]}" == 'nvm disabled.' ] + [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] +} + +@test "disable the nvm plugin if it was enabled without a priority" { + __setup_plugin_tests + + ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash + [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + + run _disable-plugin "nvm" + [ "${lines[0]}" == 'nvm disabled.' ] + [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] +} + +@test "enable the nvm plugin twice" { + __setup_plugin_tests + + run _enable-plugin "nvm" + [ "${lines[0]}" == 'nvm enabled with priority 225.' ] + [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + + run _enable-plugin "nvm" + [ "${lines[0]}" == 'nvm is already enabled.' ] + [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] +} + +@test "enable all plugins" { + __setup_plugin_tests + + run _enable-plugin "all" + local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l) + local enabled=$(find $BASH_IT/plugins/enabled -name 2*.plugin.bash | wc -l) + echo "Available: $available, Enabled: $enabled" + [ "$available" == "$enabled" ] +} + +@test "describe the nvm plugin without enabling it" { + __setup_plugin_tests + + _bash-it-describe "plugins" "a" "plugin" "Plugin" | grep "nvm" | grep "\[ \]" +} + +@test "describe the nvm plugin after enabling it" { + __setup_plugin_tests + + run _enable-plugin "nvm" + [ "${lines[0]}" == 'nvm enabled with priority 225.' ] + [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + + _bash-it-describe "plugins" "a" "plugin" "Plugin" | grep "nvm" | grep "\[x\]" +} From 65c6e6a1a6c51f5464bd22c9dd2354d5a8c60820 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:05 +0200 Subject: [PATCH 14/67] Disable all command and test case --- lib/helpers.bash | 3 +++ test/lib/helpers.bats | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/helpers.bash b/lib/helpers.bash index f9b8aa7b..11961799 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -238,6 +238,9 @@ _disable-thing () 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 done else # Use a glob to search for both possible patterns diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 3faddc6b..357bfa88 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -91,6 +91,21 @@ function __setup_plugin_tests { [ "$available" == "$enabled" ] } +@test "disable all plugins" { + __setup_plugin_tests + + run _enable-plugin "all" + local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l) + local enabled=$(find $BASH_IT/plugins/enabled -name 2*.plugin.bash | wc -l) + echo "Available: $available, Enabled: $enabled" + [ "$available" == "$enabled" ] + + run _disable-plugin "all" + local enabled2=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l) + echo "Enabled: $enabled2" + [ "$enabled2" -eq 0 ] +} + @test "describe the nvm plugin without enabling it" { __setup_plugin_tests From 11330596b1a66908f43af70a65356bd937016afe Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:06 +0200 Subject: [PATCH 15/67] Simplified describe tests --- test/lib/helpers.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 357bfa88..bfe041f6 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -109,7 +109,7 @@ function __setup_plugin_tests { @test "describe the nvm plugin without enabling it" { __setup_plugin_tests - _bash-it-describe "plugins" "a" "plugin" "Plugin" | grep "nvm" | grep "\[ \]" + _bash-it-plugins | grep "nvm" | grep "\[ \]" } @test "describe the nvm plugin after enabling it" { @@ -119,5 +119,5 @@ function __setup_plugin_tests { [ "${lines[0]}" == 'nvm enabled with priority 225.' ] [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] - _bash-it-describe "plugins" "a" "plugin" "Plugin" | grep "nvm" | grep "\[x\]" + _bash-it-plugins | grep "nvm" | grep "\[x\]" } From 36a87a5f4eeabc2cc53895fa4224077bcd0ae372 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:06 +0200 Subject: [PATCH 16/67] Added some debug output --- test/lib/helpers.bats | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index bfe041f6..437b75a3 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -10,6 +10,9 @@ load ../../lib/helpers function __setup_plugin_tests { mkdir -p $BASH_IT/plugins + pwd + ls -als .. + ls -als ../plugins cp -r ../plugins/available $BASH_IT/plugins mkdir -p $BASH_IT/plugins/enabled } From d34b820cecdcddadbdad47261793ae4f0f6cd3a8 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:06 +0200 Subject: [PATCH 17/67] Added some code to figure out the directory --- test/lib/helpers.bats | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 437b75a3..d29c59b5 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -10,10 +10,12 @@ load ../../lib/helpers function __setup_plugin_tests { mkdir -p $BASH_IT/plugins + + lib_directory="$(cd "$(dirname "$0")" && pwd)" pwd - ls -als .. - ls -als ../plugins - cp -r ../plugins/available $BASH_IT/plugins + echo "$lib_directory" + ls -als "$lib_directory/../.." + cp -r $lib_directory/../../plugins/available $BASH_IT/plugins mkdir -p $BASH_IT/plugins/enabled } From 4e16dfde56aab5f9684a79f7bc1e01444cd1e3be Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:07 +0200 Subject: [PATCH 18/67] Fixed basename usage for enable all --- lib/helpers.bash | 2 +- test/lib/helpers.bats | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 11961799..eea442f6 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -316,7 +316,7 @@ _enable-thing () typeset f $file_type for f in $BASH_IT/$subdirectory/available/*.bash do - plugin=$(basename -s .$file_type.bash $f) + plugin=$(basename $f .$file_type.bash) _enable-thing $subdirectory $file_type $plugin $load_priority done else diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index d29c59b5..934cb261 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -10,11 +10,7 @@ load ../../lib/helpers function __setup_plugin_tests { mkdir -p $BASH_IT/plugins - lib_directory="$(cd "$(dirname "$0")" && pwd)" - pwd - echo "$lib_directory" - ls -als "$lib_directory/../.." cp -r $lib_directory/../../plugins/available $BASH_IT/plugins mkdir -p $BASH_IT/plugins/enabled } From 2e0ceba7764c27dffd13319d5ebc77ba24c5bfa7 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:07 +0200 Subject: [PATCH 19/67] Supporting both old and new link structure for completion --- 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 edcad0ea..3e19a4c1 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -27,7 +27,7 @@ _bash-it-comp-list-enabled() local enabled_things=$(for f in `ls -1 $BASH_IT/$subdirectory/enabled/*.bash`; do - basename $f | cut -d'.' -f1 + basename $f | cut -d'.' -f1 | sed -e "s/^[0-9]*---//g" done) COMPREPLY=( $(compgen -W "all ${enabled_things}" -- ${cur}) ) From 56d0f56714a272b86bf535fcf7a8746eaeb9df76 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:07 +0200 Subject: [PATCH 20/67] Filter out items that are already enabled --- 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 3e19a4c1..25585b8e 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=$(for f in `ls -1 $BASH_IT/$subdirectory/available/*.bash`; do - if [ ! -e $BASH_IT/$subdirectory/enabled/$(basename $f) ] + 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 From b1481038d85e0b57ade737968300d2ce1516e609 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:07 +0200 Subject: [PATCH 21/67] Improved check for components that are already enabled --- lib/helpers.bash | 13 +++++-------- test/lib/helpers.bats | 12 ++++++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index eea442f6..7f12cde9 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -328,14 +328,11 @@ _enable-thing () plugin=$(basename $plugin) # Check for existence of the file using a wildcard, since we don't know which priority might have been used when enabling it. - for f in $BASH_IT/$subdirectory/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR$plugin; do - if [ -e "$f" ] ; then - printf '%s\n' "$file_entity is already enabled." - return - fi - - break - done + typeset enabled_plugin=$(command ls $BASH_IT/$subdirectory/enabled/{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$plugin,$plugin} 2>/dev/null | head -1) + if [ ! -z "$enabled_plugin" ] ; then + printf '%s\n' "$file_entity is already enabled." + return + fi mkdir -p $BASH_IT/$subdirectory/enabled diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 934cb261..c8a7d1ba 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -70,6 +70,18 @@ function __setup_plugin_tests { [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] } +@test "enable the nvm plugin if it was enabled without a priority" { + __setup_plugin_tests + + ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash + [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + + run _enable-plugin "nvm" + [ "${lines[0]}" == 'nvm is already enabled.' ] + [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] +} + @test "enable the nvm plugin twice" { __setup_plugin_tests From c2446c2692b7c4128ac0823901f0a6ab4abde9a4 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:08 +0200 Subject: [PATCH 22/67] Added new "bash-it migrate" command that migrates components from the old syntax to the new one that uses the load priority --- completion/available/bash-it.completion.bash | 4 +-- lib/helpers.bash | 31 +++++++++++++++++++- test/lib/helpers.bats | 20 +++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 25585b8e..6bcd179b 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -53,7 +53,7 @@ _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" + opts="help show enable disable update search migrate" case "${chose_opt}" in show) local show_args="plugins aliases completions" @@ -65,7 +65,7 @@ _bash-it-comp() COMPREPLY=( $(compgen -W "${help_args}" -- ${cur}) ) return 0 ;; - update | search) + update | search | migrate) return 0 ;; enable | disable) diff --git a/lib/helpers.bash b/lib/helpers.bash index 7f12cde9..b1508c1c 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -36,13 +36,14 @@ function reload_plugins() { bash-it () { about 'Bash-it help and maintenance' - param '1: verb [one of: help | show | enable | disable | update | search ] ' + param '1: verb [one of: help | show | enable | disable | migrate | update | search ] ' param '2: component type [one of: alias(es) | completion(s) | plugin(s) ] or search term(s)' param '3: specific component [optional]' example '$ bash-it show plugins' example '$ bash-it help aliases' example '$ bash-it enable plugin git [tmux]...' example '$ bash-it disable alias hg [tmux]...' + example '$ bash-it migrate' example '$ bash-it update' example '$ bash-it search ruby [[-]rake]... [--enable | --disable]' typeset verb=${1:-} @@ -64,6 +65,8 @@ bash-it () return;; update) func=_bash-it_update;; + migrate) + func=_bash-it-migrate;; *) reference bash-it return;; @@ -150,6 +153,32 @@ _bash-it_update() { cd - &> /dev/null } +_bash-it-migrate() { + _about 'migrates Bash-it configuration from a previous format to the current one' + _group 'lib' + + for file_type in "aliases" "plugins" "completion" + do + for f in $BASH_IT/$file_type/enabled/*.bash + 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 | awk -F'.' '{print $2}' | sed 's/aliases/alias/g') + typeset component_name=$(echo $ff | cut -d'.' -f1) + + disable_func="_disable-$single_type" + enable_func="_enable-$single_type" + + $disable_func $component_name + $enable_func $component_name + fi + done + done +} + _bash-it-describe () { _about 'summarizes available bash_it components' diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index c8a7d1ba..3fdeacb8 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -94,6 +94,26 @@ function __setup_plugin_tests { [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] } +@test "migrate enabled plugins that don't use the new priority-based configuration" { + __setup_plugin_tests + + ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash + [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + + ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/node.plugin.bash + [ -L "$BASH_IT/plugins/enabled/node.plugin.bash" ] + + run _enable-plugin "ssh" + [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ] + + run _bash-it-migrate + [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] + [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ] + [ ! -L "$BASH_IT/plugins/enabled/node.plugin.bash" ] + [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] +} + @test "enable all plugins" { __setup_plugin_tests From 402179d87d44ea6f47df9ab31b734abf4b7d2fdb Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:08 +0200 Subject: [PATCH 23/67] Added prefix to bash-it test cases --- test/lib/helpers.bats | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 3fdeacb8..14ec793e 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -15,7 +15,7 @@ function __setup_plugin_tests { mkdir -p $BASH_IT/plugins/enabled } -@test "enable the node plugin" { +@test "bash-it: enable the node plugin" { __setup_plugin_tests run _enable-plugin "node" @@ -23,7 +23,7 @@ function __setup_plugin_tests { [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] } -@test "enable the nvm plugin" { +@test "bash-it: enable the nvm plugin" { __setup_plugin_tests run _enable-plugin "nvm" @@ -31,7 +31,7 @@ function __setup_plugin_tests { [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] } -@test "enable an unknown plugin" { +@test "bash-it: enable an unknown plugin" { __setup_plugin_tests run _enable-plugin "unknown-foo" @@ -40,14 +40,14 @@ function __setup_plugin_tests { [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ] } -@test "disable a plugin that is not enabled" { +@test "bash-it: disable a plugin that is not enabled" { __setup_plugin_tests run _disable-plugin "sdkman" [ "${lines[0]}" == 'sorry, sdkman does not appear to be an enabled plugin.' ] } -@test "enable and disable the nvm plugin" { +@test "bash-it: enable and disable the nvm plugin" { __setup_plugin_tests run _enable-plugin "nvm" @@ -59,7 +59,7 @@ function __setup_plugin_tests { [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] } -@test "disable the nvm plugin if it was enabled without a priority" { +@test "bash-it: disable the nvm plugin if it was enabled without a priority" { __setup_plugin_tests ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash @@ -70,7 +70,7 @@ function __setup_plugin_tests { [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] } -@test "enable the nvm plugin if it was enabled without a priority" { +@test "bash-it: enable the nvm plugin if it was enabled without a priority" { __setup_plugin_tests ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash @@ -82,7 +82,7 @@ function __setup_plugin_tests { [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] } -@test "enable the nvm plugin twice" { +@test "bash-it: enable the nvm plugin twice" { __setup_plugin_tests run _enable-plugin "nvm" @@ -94,7 +94,7 @@ function __setup_plugin_tests { [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] } -@test "migrate enabled plugins that don't use the new priority-based configuration" { +@test "bash-it: migrate enabled plugins that don't use the new priority-based configuration" { __setup_plugin_tests ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash @@ -114,7 +114,7 @@ function __setup_plugin_tests { [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] } -@test "enable all plugins" { +@test "bash-it: enable all plugins" { __setup_plugin_tests run _enable-plugin "all" @@ -124,7 +124,7 @@ function __setup_plugin_tests { [ "$available" == "$enabled" ] } -@test "disable all plugins" { +@test "bash-it: disable all plugins" { __setup_plugin_tests run _enable-plugin "all" @@ -139,13 +139,13 @@ function __setup_plugin_tests { [ "$enabled2" -eq 0 ] } -@test "describe the nvm plugin without enabling it" { +@test "bash-it: describe the nvm plugin without enabling it" { __setup_plugin_tests _bash-it-plugins | grep "nvm" | grep "\[ \]" } -@test "describe the nvm plugin after enabling it" { +@test "bash-it: describe the nvm plugin after enabling it" { __setup_plugin_tests run _enable-plugin "nvm" From 3ecf684eb6d0e93cc154316a25cc8f733ea32fe8 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:08 +0200 Subject: [PATCH 24/67] Switched loading of single components to existing functions --- install.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/install.sh b/install.sh index 4cd7f4d9..180ecdaa 100755 --- a/install.sh +++ b/install.sh @@ -150,6 +150,11 @@ elif [[ $silent ]] && ! [[ $no_modify_config ]]; then backup_new fi +# Load dependencies for enabling components +source "$BASH_IT/lib/composure.bash" +cite _about _param _example _group _author _version +source "$BASH_IT/lib/helpers.bash" + if [[ $interactive ]] && ! [[ $silent ]] ; then for type in "aliases" "plugins" "completion" @@ -160,11 +165,11 @@ then else echo "" echo -e "\033[0;32mEnabling sane defaults\033[0m" - load_one completion bash-it.completion.bash - load_one completion system.completion.bash - load_one plugins base.plugin.bash - load_one plugins alias-completion.plugin.bash - load_one aliases general.aliases.bash + _enable-completion bash-it + _enable-completion system + _enable-plugin base + _enable-plugin alias-completion + _enable-alias general fi echo "" From 54774d4f59e93f0cc1ed225a12f11a4781c6a992 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:08 +0200 Subject: [PATCH 25/67] Using the existing enable function for interactive install --- install.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 180ecdaa..7fa8cacf 100755 --- a/install.sh +++ b/install.sh @@ -30,16 +30,19 @@ function load_one() { # Interactively enable several things function load_some() { file_type=$1 + single_type=$(echo "$file_type" | sed -e "s/aliases$/alias/g" | sed -e "s/plugins$/plugin/g") + enable_func="_enable-$single_type" [ -d "$BASH_IT/$file_type/enabled" ] || mkdir "$BASH_IT/$file_type/enabled" for path in "$BASH_IT/${file_type}/available/"[^_]* do file_name=$(basename "$path") while true do - read -e -n 1 -p "Would you like to enable the ${file_name%%.*} $file_type? [y/N] " RESP + just_the_name="${file_name%%.*}" + read -e -n 1 -p "Would you like to enable the $just_the_name $file_type? [y/N] " RESP case $RESP in [yY]) - ln -s "../available/${file_name}" "$BASH_IT/$file_type/enabled" + $enable_func $just_the_name break ;; [nN]|"") From 9eb10c266b13045df2625081aa5fb49e094c68d0 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:09 +0200 Subject: [PATCH 26/67] Added support for local setup/teardown functions --- test/test_helper.bash | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/test_helper.bash b/test/test_helper.bash index 71b3a16c..08638b54 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -13,11 +13,23 @@ if [ "$BASH_IT_ROOT" != "${BASH_IT_TEST_DIR}/root" ]; then export BASH_IT=$BASH_IT_TEST_DIR fi +local_setup() { + true +} + +local_teardown() { + true +} + setup() { mkdir -p -- "${BASH_IT_ROOT}" + + local_setup } teardown() { + local_teardown + rm -rf "${BASH_IT_TEST_DIR}" } From e112eb43a0ecc9faaf13e0d233a90820a79b6738 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:09 +0200 Subject: [PATCH 27/67] Using local setup/teardown functions --- test/lib/helpers.bats | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 14ec793e..ed79df48 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -8,7 +8,7 @@ cite _about _param _example _group _author _version load ../../lib/helpers -function __setup_plugin_tests { +function local_setup { mkdir -p $BASH_IT/plugins lib_directory="$(cd "$(dirname "$0")" && pwd)" cp -r $lib_directory/../../plugins/available $BASH_IT/plugins @@ -16,24 +16,18 @@ function __setup_plugin_tests { } @test "bash-it: enable the node plugin" { - __setup_plugin_tests - run _enable-plugin "node" [ "${lines[0]}" == 'node enabled with priority 250.' ] [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] } @test "bash-it: enable the nvm plugin" { - __setup_plugin_tests - run _enable-plugin "nvm" [ "${lines[0]}" == 'nvm enabled with priority 225.' ] [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] } @test "bash-it: enable an unknown plugin" { - __setup_plugin_tests - run _enable-plugin "unknown-foo" [ "${lines[0]}" == 'sorry, unknown-foo does not appear to be an available plugin.' ] [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ] @@ -41,15 +35,11 @@ function __setup_plugin_tests { } @test "bash-it: disable a plugin that is not enabled" { - __setup_plugin_tests - run _disable-plugin "sdkman" [ "${lines[0]}" == 'sorry, sdkman does not appear to be an enabled plugin.' ] } @test "bash-it: enable and disable the nvm plugin" { - __setup_plugin_tests - run _enable-plugin "nvm" [ "${lines[0]}" == 'nvm enabled with priority 225.' ] [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] @@ -60,8 +50,6 @@ function __setup_plugin_tests { } @test "bash-it: disable the nvm plugin if it was enabled without a priority" { - __setup_plugin_tests - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] @@ -71,8 +59,6 @@ function __setup_plugin_tests { } @test "bash-it: enable the nvm plugin if it was enabled without a priority" { - __setup_plugin_tests - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] @@ -83,8 +69,6 @@ function __setup_plugin_tests { } @test "bash-it: enable the nvm plugin twice" { - __setup_plugin_tests - run _enable-plugin "nvm" [ "${lines[0]}" == 'nvm enabled with priority 225.' ] [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] @@ -95,8 +79,6 @@ function __setup_plugin_tests { } @test "bash-it: migrate enabled plugins that don't use the new priority-based configuration" { - __setup_plugin_tests - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] @@ -115,8 +97,6 @@ function __setup_plugin_tests { } @test "bash-it: enable all plugins" { - __setup_plugin_tests - run _enable-plugin "all" local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l) local enabled=$(find $BASH_IT/plugins/enabled -name 2*.plugin.bash | wc -l) @@ -125,8 +105,6 @@ function __setup_plugin_tests { } @test "bash-it: disable all plugins" { - __setup_plugin_tests - run _enable-plugin "all" local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l) local enabled=$(find $BASH_IT/plugins/enabled -name 2*.plugin.bash | wc -l) @@ -140,14 +118,10 @@ function __setup_plugin_tests { } @test "bash-it: describe the nvm plugin without enabling it" { - __setup_plugin_tests - _bash-it-plugins | grep "nvm" | grep "\[ \]" } @test "bash-it: describe the nvm plugin after enabling it" { - __setup_plugin_tests - run _enable-plugin "nvm" [ "${lines[0]}" == 'nvm enabled with priority 225.' ] [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] From 6ce9403be0a09e083e246af186e5aa7bf0273e5a Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 10 May 2017 11:12:09 +0200 Subject: [PATCH 28/67] Started writing tests for the install script --- test/install/install.bats | 38 ++++++++++++++++++++++++++++++++++++++ test/run | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 test/install/install.bats diff --git a/test/install/install.bats b/test/install/install.bats new file mode 100644 index 00000000..fcabe691 --- /dev/null +++ b/test/install/install.bats @@ -0,0 +1,38 @@ +#!/usr/bin/env bats + +load ../test_helper +load ../../lib/composure + +function local_setup { + mkdir -p $BASH_IT + lib_directory="$(cd "$(dirname "$0")" && pwd)" + cp -r $lib_directory/../../* $BASH_IT/ + + # 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 "install: verify that the install script exists" { + [ -e "$BASH_IT/install.sh" ] +} + +@test "install: run the install script silently" { + skip "Waiting for test to be implemented" + cd "$BASH_IT" + + ./install.sh --silent + + [ -e "$BASH_IT_TEST_HOME/.bash_profile" ] +} diff --git a/test/run b/test/run index 397aec9c..59150a39 100755 --- a/test/run +++ b/test/run @@ -9,4 +9,4 @@ if [ -z "${BASH_IT}" ]; then export BASH_IT=$(cd ${test_directory} && dirname $(pwd)) fi -exec $bats_executable ${CI:+--tap} ${test_directory}/{lib,plugins} +exec $bats_executable ${CI:+--tap} ${test_directory}/{install,lib,plugins} From b95fd6fdcec58755d7249ba86eec7fbf97eda219 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Mon, 15 May 2017 07:29:06 +0200 Subject: [PATCH 29/67] Checking config file per OS type --- test/install/install.bats | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/install/install.bats b/test/install/install.bats index fcabe691..405519bf 100644 --- a/test/install/install.bats +++ b/test/install/install.bats @@ -3,6 +3,16 @@ load ../test_helper load ../../lib/composure +# Determine which config file to use based on OS. +case $OSTYPE in + darwin*) + BASH_IT_CONFIG_FILE=.bash_profile + ;; + *) + BASH_IT_CONFIG_FILE=.bashrc + ;; +esac + function local_setup { mkdir -p $BASH_IT lib_directory="$(cd "$(dirname "$0")" && pwd)" @@ -29,10 +39,9 @@ function local_teardown { } @test "install: run the install script silently" { - skip "Waiting for test to be implemented" cd "$BASH_IT" ./install.sh --silent - [ -e "$BASH_IT_TEST_HOME/.bash_profile" ] + [ -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" ] } From 12ed1b79d3173bd636a0e6d056a8d5421715a395 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Mon, 15 May 2017 07:40:56 +0200 Subject: [PATCH 30/67] Check for enabled components after install --- test/install/install.bats | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/install/install.bats b/test/install/install.bats index 405519bf..86ed5169 100644 --- a/test/install/install.bats +++ b/test/install/install.bats @@ -6,10 +6,10 @@ load ../../lib/composure # Determine which config file to use based on OS. case $OSTYPE in darwin*) - BASH_IT_CONFIG_FILE=.bash_profile + export BASH_IT_CONFIG_FILE=.bash_profile ;; *) - BASH_IT_CONFIG_FILE=.bashrc + export BASH_IT_CONFIG_FILE=.bashrc ;; esac @@ -35,7 +35,7 @@ function local_teardown { } @test "install: verify that the install script exists" { - [ -e "$BASH_IT/install.sh" ] + assert [ -e "$BASH_IT/install.sh" ] } @test "install: run the install script silently" { @@ -43,5 +43,11 @@ function local_teardown { ./install.sh --silent - [ -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" ] + 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/250---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" ] } From 1ace0b7a89a92bfcefec5444b5716c572d168508 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Mon, 15 May 2017 07:49:26 +0200 Subject: [PATCH 31/67] Checking for backup file creation --- test/install/install.bats | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/install/install.bats b/test/install/install.bats index 86ed5169..70862c2a 100644 --- a/test/install/install.bats +++ b/test/install/install.bats @@ -51,3 +51,20 @@ function local_teardown { assert [ -L "$BASH_IT/completion/enabled/350---bash-it.completion.bash" ] assert [ -L "$BASH_IT/completion/enabled/350---system.completion.bash" ] } + +@test "install: verify that a backup file is created" { + cd "$BASH_IT" + + touch "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" + echo "test file content" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" + local md5_orig=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + + ./install.sh --silent + + assert [ -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" ] + assert [ -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" ] + + local md5_bak=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') + + assert_equal "$md5_orig" "$md5_bak" +} From 99ad1bc3e6a05055408815a713524dc88febf8eb Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Mon, 15 May 2017 08:09:10 +0200 Subject: [PATCH 32/67] Running tests on Linux and macOS (as OS X) --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 34c38fe7..b3fa2728 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,6 @@ sudo: false script: test/run language: c +os: + - linux + - osx From 43b62b344ad3587ed7d608f6b9f8f16648ff81df Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Mon, 15 May 2017 17:24:14 +0200 Subject: [PATCH 33/67] Added test case for silent/interactive combo --- test/install/install.bats | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/install/install.bats b/test/install/install.bats index 70862c2a..2d0b21e6 100644 --- a/test/install/install.bats +++ b/test/install/install.bats @@ -68,3 +68,11 @@ function local_teardown { assert_equal "$md5_orig" "$md5_bak" } + +@test "install: verify that silent and interactive can not be used at the same time" { + cd "$BASH_IT" + + run ./install.sh --silent --interactive + + assert_failure +} From eb9a15f435cbbee71a92e0339972fb28b82af1ef Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Tue, 16 May 2017 07:36:06 +0200 Subject: [PATCH 34/67] Added test cases for uninstall script --- test/install/uninstall.bats | 78 +++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 test/install/uninstall.bats diff --git a/test/install/uninstall.bats b/test/install/uninstall.bats new file mode 100644 index 00000000..adab216f --- /dev/null +++ b/test/install/uninstall.bats @@ -0,0 +1,78 @@ +#!/usr/bin/env bats + +load ../test_helper +load ../../lib/composure + +# Determine which config file to use based on OS. +case $OSTYPE in + darwin*) + export BASH_IT_CONFIG_FILE=.bash_profile + ;; + *) + export BASH_IT_CONFIG_FILE=.bashrc + ;; +esac + +function local_setup { + mkdir -p $BASH_IT + lib_directory="$(cd "$(dirname "$0")" && pwd)" + cp -r $lib_directory/../../* $BASH_IT/ + + # 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 "uninstall: verify that the uninstall script exists" { + assert [ -e "$BASH_IT/uninstall.sh" ] +} + +@test "uninstall: run the uninstall script with an existing backup file" { + cd "$BASH_IT" + + echo "test file content for backup" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" + echo "test file content for original file" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" + local md5_bak=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') + + ./uninstall.sh + + assert_success + + assert [ ! -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall" ] + assert [ ! -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" ] + assert [ -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" ] + + local md5_conf=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + + assert_equal "$md5_bak" "$md5_conf" +} + +@test "uninstall: run the uninstall script without an existing backup file" { + cd "$BASH_IT" + + echo "test file content for original file" > "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" + local md5_orig=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + + ./uninstall.sh + + assert_success + + assert [ -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall" ] + assert [ ! -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.bak" ] + assert [ ! -e "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE" ] + + local md5_uninstall=$(md5sum "$BASH_IT_TEST_HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}') + + assert_equal "$md5_orig" "$md5_uninstall" +} From bf632e19fc5d49117b5f349e70eb7a84db648780 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Tue, 16 May 2017 07:47:38 +0200 Subject: [PATCH 35/67] Refactored tests to use helper assert functions --- test/lib/helpers.bats | 75 +++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index ed79df48..28b0f1b0 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -17,104 +17,101 @@ function local_setup { @test "bash-it: enable the node plugin" { run _enable-plugin "node" - [ "${lines[0]}" == 'node enabled with priority 250.' ] - [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] + assert_line "0" 'node enabled with priority 250.' + assert [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] } @test "bash-it: enable the nvm plugin" { run _enable-plugin "nvm" - [ "${lines[0]}" == 'nvm enabled with priority 225.' ] - [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert_line "0" 'nvm enabled with priority 225.' + assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] } @test "bash-it: enable an unknown plugin" { run _enable-plugin "unknown-foo" - [ "${lines[0]}" == 'sorry, unknown-foo does not appear to be an available plugin.' ] - [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ] - [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ] + assert_line "0" 'sorry, unknown-foo does not appear to be an available plugin.' + assert [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ] + assert [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ] } @test "bash-it: disable a plugin that is not enabled" { run _disable-plugin "sdkman" - [ "${lines[0]}" == 'sorry, sdkman does not appear to be an enabled plugin.' ] + assert_line "0" 'sorry, sdkman does not appear to be an enabled plugin.' } @test "bash-it: enable and disable the nvm plugin" { run _enable-plugin "nvm" - [ "${lines[0]}" == 'nvm enabled with priority 225.' ] - [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert_line "0" 'nvm enabled with priority 225.' + assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] run _disable-plugin "nvm" - [ "${lines[0]}" == 'nvm disabled.' ] - [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert_line "0" 'nvm disabled.' + assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] } @test "bash-it: 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 - [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] run _disable-plugin "nvm" - [ "${lines[0]}" == 'nvm disabled.' ] - [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + assert_line "0" 'nvm disabled.' + assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] } @test "bash-it: 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 - [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + assert [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] run _enable-plugin "nvm" - [ "${lines[0]}" == 'nvm is already enabled.' ] - [ -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] - [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + 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" ] } @test "bash-it: enable the nvm plugin twice" { run _enable-plugin "nvm" - [ "${lines[0]}" == 'nvm enabled with priority 225.' ] - [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert_line "0" 'nvm enabled with priority 225.' + assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] run _enable-plugin "nvm" - [ "${lines[0]}" == 'nvm is already enabled.' ] - [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert_line "0" 'nvm is already enabled.' + assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] } @test "bash-it: 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 - [ -L "$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 - [ -L "$BASH_IT/plugins/enabled/node.plugin.bash" ] + assert [ -L "$BASH_IT/plugins/enabled/node.plugin.bash" ] run _enable-plugin "ssh" - [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ] + assert [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ] run _bash-it-migrate - [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] - [ -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] - [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ] - [ ! -L "$BASH_IT/plugins/enabled/node.plugin.bash" ] - [ ! -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/plugins/enabled/250---ssh.plugin.bash" ] + assert [ ! -L "$BASH_IT/plugins/enabled/node.plugin.bash" ] + assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] } @test "bash-it: enable all plugins" { run _enable-plugin "all" local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l) local enabled=$(find $BASH_IT/plugins/enabled -name 2*.plugin.bash | wc -l) - echo "Available: $available, Enabled: $enabled" - [ "$available" == "$enabled" ] + 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) local enabled=$(find $BASH_IT/plugins/enabled -name 2*.plugin.bash | wc -l) - echo "Available: $available, Enabled: $enabled" - [ "$available" == "$enabled" ] + assert_equal "$available" "$enabled" run _disable-plugin "all" local enabled2=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l) - echo "Enabled: $enabled2" - [ "$enabled2" -eq 0 ] + assert_equal "$enabled2" "0" } @test "bash-it: describe the nvm plugin without enabling it" { @@ -123,8 +120,8 @@ function local_setup { @test "bash-it: describe the nvm plugin after enabling it" { run _enable-plugin "nvm" - [ "${lines[0]}" == 'nvm enabled with priority 225.' ] - [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert_line "0" 'nvm enabled with priority 225.' + assert [ -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] _bash-it-plugins | grep "nvm" | grep "\[x\]" } From dc7173b7ef1daa529b17266fe141098d1de95ec8 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Tue, 16 May 2017 09:00:36 +0200 Subject: [PATCH 36/67] Using xargs to remove leading spaces Found here: http://stackoverflow.com/a/12973694/1228454 --- test/lib/helpers.bats | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 28b0f1b0..b3de62c4 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -98,19 +98,19 @@ 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) - local enabled=$(find $BASH_IT/plugins/enabled -name 2*.plugin.bash | wc -l) + local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l | xargs) + local enabled=$(find $BASH_IT/plugins/enabled -name 2*.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) - local enabled=$(find $BASH_IT/plugins/enabled -name 2*.plugin.bash | wc -l) + local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l | xargs) + local enabled=$(find $BASH_IT/plugins/enabled -name 2*.plugin.bash | wc -l | xargs) assert_equal "$available" "$enabled" run _disable-plugin "all" - local enabled2=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l) + local enabled2=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) assert_equal "$enabled2" "0" } From 9ebbf6e6e5796fb9679022ae5428b7e4eba378b3 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Tue, 16 May 2017 17:27:02 +0200 Subject: [PATCH 37/67] Updated some load priorities These will not work yet, since they are used across component types, but this will start working once everything is loaded from the same "enabled" directory. --- plugins/available/alias-completion.plugin.bash | 3 +++ plugins/available/fzf.plugin.bash | 3 +++ 2 files changed, 6 insertions(+) diff --git a/plugins/available/alias-completion.plugin.bash b/plugins/available/alias-completion.plugin.bash index c045c359..368d9f47 100644 --- a/plugins/available/alias-completion.plugin.bash +++ b/plugins/available/alias-completion.plugin.bash @@ -1,3 +1,6 @@ +# Load after the other completions to understand what needs to be completed +# BASH_IT_LOAD_PRIORITY: 365 + cite about-plugin about-plugin 'Automatic completion of aliases' diff --git a/plugins/available/fzf.plugin.bash b/plugins/available/fzf.plugin.bash index d96be3c9..aff89ea5 100644 --- a/plugins/available/fzf.plugin.bash +++ b/plugins/available/fzf.plugin.bash @@ -1,3 +1,6 @@ +# Load after the system completion to make sure that the fzf completions are working +# BASH_IT_LOAD_PRIORITY: 375 + cite about-plugin about-plugin 'load fzf, if you are using it' From 6ff4071646e2a0852ecea0291ba75536be57ba1d Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Tue, 16 May 2017 17:42:04 +0200 Subject: [PATCH 38/67] Fixed test execution that only checked for plugins starting with 2 --- test/lib/helpers.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index b3de62c4..c6f53c0a 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -99,14 +99,14 @@ 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 2*.plugin.bash | wc -l | xargs) + local enabled=$(find $BASH_IT/plugins/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 2*.plugin.bash | wc -l | xargs) + local enabled=$(find $BASH_IT/plugins/enabled -name [0-9]*.plugin.bash | wc -l | xargs) assert_equal "$available" "$enabled" run _disable-plugin "all" From 2607bb815a5a46249e03096eca97de060713e8f0 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Tue, 16 May 2017 17:49:21 +0200 Subject: [PATCH 39/67] Avoid polluting the user's Bash-it installation All of the install steps are done in a test directory --- test/lib/search.bats | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/lib/search.bats b/test/lib/search.bats index ae9e9a89..5c2873da 100644 --- a/test/lib/search.bats +++ b/test/lib/search.bats @@ -1,5 +1,7 @@ #!/usr/bin/env bats +load ../test_helper + load ../../lib/composure load ../../plugins/available/base.plugin @@ -10,6 +12,12 @@ load ../../lib/search NO_COLOR=true +function local_setup { + mkdir -p $BASH_IT + lib_directory="$(cd "$(dirname "$0")" && pwd)" + cp -r $lib_directory/../../* $BASH_IT/ +} + @test "helpers search aliases" { run _bash-it-search-component 'plugins' 'base' [[ "${lines[0]}" =~ 'plugins' && "${lines[0]}" =~ 'base' ]] From cb469607177790b02f257fdb8a18a35fb2e278c2 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 17 May 2017 07:36:03 +0200 Subject: [PATCH 40/67] Removing enabled components before running tests --- test/install/install.bats | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/install/install.bats b/test/install/install.bats index 2d0b21e6..ded2689a 100644 --- a/test/install/install.bats +++ b/test/install/install.bats @@ -17,6 +17,7 @@ function local_setup { 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" # Don't pollute the user's actual $HOME directory # Use a test home directory instead @@ -47,7 +48,7 @@ function local_teardown { 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/250---alias-completion.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" ] } From 1e624113a75abbbf9f0ec30f7954d55e4583b5d5 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 17 May 2017 08:11:02 +0200 Subject: [PATCH 41/67] Refactored search test cases to use the assert functions --- test/lib/search.bats | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/lib/search.bats b/test/lib/search.bats index 5c2873da..71a176d4 100644 --- a/test/lib/search.bats +++ b/test/lib/search.bats @@ -18,44 +18,44 @@ function local_setup { cp -r $lib_directory/../../* $BASH_IT/ } -@test "helpers search aliases" { +@test "helpers search plugins" { run _bash-it-search-component 'plugins' 'base' [[ "${lines[0]}" =~ 'plugins' && "${lines[0]}" =~ 'base' ]] } @test "helpers search ruby gem bundle rake rails" { # first disable them all, so that the output does not appear with a checkbox - # and we can compoare the result + # and we can compare the result run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' '--disable' # Now perform the search run _bash-it-search 'ruby' 'gem' 'bundle' 'rake' 'rails' # And verify - [[ "${lines[0]/✓/}" == ' aliases => bundler rails' ]] && \ - [[ "${lines[1]/✓/}" == ' plugins => chruby chruby-auto rails ruby' ]] && \ - [[ "${lines[2]/✓/}" == ' completions => bundler gem rake' ]] + assert [ "${lines[0]/✓/}" == ' aliases => bundler rails' ] + assert [ "${lines[1]/✓/}" == ' plugins => chruby chruby-auto rails ruby' ] + assert [ "${lines[2]/✓/}" == ' completions => bundler gem rake' ] } @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' - [[ "${lines[0]/✓/}" == ' aliases => bundler rails' ]] && \ - [[ "${lines[1]/✓/}" == ' plugins => rails ruby' ]] && \ - [[ "${lines[2]/✓/}" == ' completions => bundler gem rake' ]] + assert [ "${lines[0]/✓/}" == ' aliases => bundler rails' ] + assert [ "${lines[1]/✓/}" == ' plugins => rails ruby' ] + assert [ "${lines[2]/✓/}" == ' completions => bundler gem rake' ] } @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' - [[ "${lines[0]}" == ' aliases => bundler ✓rails' ]] && \ - [[ "${lines[1]}" == ' plugins => chruby chruby-auto rails ruby' ]] && \ - [[ "${lines[2]}" == ' completions => bundler gem rake' ]] + assert_line "0" ' aliases => bundler ✓rails' + assert_line "1" ' plugins => chruby chruby-auto rails ruby' + assert_line "2" ' completions => bundler gem rake' } @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' - [[ "${lines[0]}" == ' aliases => ✓bundler ✓rails' ]] && \ - [[ "${lines[1]}" == ' plugins => ✓rails ✓ruby' ]] && \ - [[ "${lines[2]}" == ' completions => ✓bundler ✓gem ✓rake' ]] + assert_line "0" ' aliases => ✓bundler ✓rails' + assert_line "1" ' plugins => ✓rails ✓ruby' + assert_line "2" ' completions => ✓bundler ✓gem ✓rake' } From b686c0dc7f75f191f8e893d7e9e3d991484684f3 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Mon, 22 May 2017 07:31:43 +0200 Subject: [PATCH 42/67] Added a note about theme screenshots --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b9bd7d91..3c5a802d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -30,5 +30,5 @@ When contributing a new feature, a bug fix, a new theme, or any other change to ## Themes -* When adding a new theme, please include a screenshot and a short description about what makes this theme unique in the Pull Request. +* When adding a new theme, please include a screenshot and a short description about what makes this theme unique in the Pull Request's description field. Please do not add theme screenshots to the repo itself, as they will add unnecessary bloat to the repo. The project's Wiki has a _Themes_ page where you can add a screenshot if you want. * Ideally, each theme's folder should contain a `README.md` file describing the theme and its configuration options. From 959dd097132e08ee7e24f54c364855a0ddd8d101 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Mon, 22 May 2017 07:56:58 +0200 Subject: [PATCH 43/67] Added development file --- DEVELOPMENT.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 DEVELOPMENT.md diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md new file mode 100644 index 00000000..c2291c66 --- /dev/null +++ b/DEVELOPMENT.md @@ -0,0 +1,41 @@ +# Bash-it Development + +This page summarizes a couple of rules to keep in mind when developing features or making changes in Bash-it. + +## Load Order + +### General Load Order + +The main `bash_it.sh` script loads the frameworks individual components in the following order: + +* `lib/composure.bash` +* `themes/colors.theme.bash` +* `themes/base.theme.bash` +* Files in `lib` with the exception of `appearance.bash` - this means that `composure.bash` is loaded again here (possible improvement?) +* Enabled `aliases` +* Enabled `plugins` +* Enabled `completions` +* `lib/appearance.bash`, which loads the selected theme +* Custom `aliases` +* Custom `plugins` +* Custom `completions` +* Additional custom files from either `$BASH_IT/custom` or `$BASH_IT_CUSTOM` + +This order is subject to change. + +### Individual Component Load Order + +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. +* 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. +* 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 +``` From 51c8970eb8e22829a7ff051efee712aa76f8b75c Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Mon, 22 May 2017 07:58:33 +0200 Subject: [PATCH 44/67] Fixed indentation --- DEVELOPMENT.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index c2291c66..7c2c16fe 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -36,6 +36,6 @@ For `aliases`, `plugins` and `completions`, the following rules are applied that * 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. * 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 -``` + ```bash + # BASH_IT_LOAD_PRIORITY: 225 + ``` From 095ee3bb91151790c46891f2f75afceee4768514 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 24 May 2017 07:38:47 +0200 Subject: [PATCH 45/67] Added a note about unit testing --- CONTRIBUTING.md | 18 ++++++++++++++++++ DEVELOPMENT.md | 2 ++ 2 files changed, 20 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3c5a802d..aa4a65b5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,6 +24,24 @@ When contributing a new feature, a bug fix, a new theme, or any other change to * Use the provided meta functions to document your code, e.g. `about-plugin`, `about`, `group`, `param`, `example`. This will make it easier for other people to use your new functionality. Take a look at the existing code for an example (e.g. [the base plugin](plugins/available/base.plugin.bash)). * When adding files, please use the existing file naming conventions, e.g. plugin files need to end in `.plugin.bash`. This is important for the installation functionality. +## Unit Tests + +When adding features or making changes/fixes, please run our growing unit test suite to ensure that you did not break existing functionality. The test suite does not cover all aspects of Bash-it, but please run it anyway to verify that you did not introduce any regression issues. + +Any code pushed to GitHub as part of a Pull Request will automatically trigger a continuous integration build on [Travis CI](https://travis-ci.org/Bash-it/bash-it), where the test suite is run on both Linux and macOS. The Pull Request will then show the result of the Travis build, indicating whether all tests ran fine, or whether there were issues. Please pay attention to this, Pull Requests with build issues will not be merged. + +Adding new functionality or changing existing functionality is a good opportunity to increase Bash-it's test coverage. When you're changing the Bash-it codebase, please consider adding some unit tests that cover the new or changed functionality. Ideally, when fixing a bug, a matching unit test that verifies that the bug is no longer present, is added at the same time. + +To run the test suite, simply execute the following in the directory where you cloned Bash-it: + +```bash +test/run +``` + +This command will clone the [Bats Test Framework](https://github.com/sstephenson/bats) to a local directory and then run the test suite found in the [test](test) folder. The test script will execute each test in turn, and will print a status for each test case. + +When adding new test cases, please take a look at the existing test cases for examples. + ## Features * When adding new completions or plugins, please don't simply copy existing tools into the Bash-it codebase, try to load/integrate the tools instead. An example is using `nvm`: Instead of copying the existing `nvm` script into Bash-it, the `nvm.plugin.bash` file tries to load an existing installation of `nvm`. This means an additional step for the user (installing `nvm` from its own repo, or through a package manager), but it will also ensure that `nvm` can be upgraded in an easy way. diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 7c2c16fe..5dde8b9b 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -39,3 +39,5 @@ For `aliases`, `plugins` and `completions`, the following rules are applied that ```bash # BASH_IT_LOAD_PRIORITY: 225 ``` + +These items are subject to change. When making changes to the internal functionality, this page needs to be updated as well. From 15868b1b616ceb26e53f83951ad3faea36385a85 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 24 May 2017 07:39:39 +0200 Subject: [PATCH 46/67] Moved the contribution guidelines to a more prominent position at the top of the page Hoping that more people will take a look at these guidelines before contributing. --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6219d636..9b2cec18 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,12 @@ Includes autocompletion, themes, aliases, custom functions, a few stolen pieces Bash-it provides a solid framework for using, developing and maintaining shell scripts and custom commands for your daily work. If you're using the _Bourne Again Shell_ (Bash) on a regular basis and have been looking for an easy way on how to keep all of these nice little scripts and aliases under control, then Bash-it is for you! Stop polluting your `~/bin` directory and your `.bashrc` file, fork/clone Bash-it and start hacking away. +## Contributing + +Please take a look at the [Contribution Guidelines](CONTRIBUTING.md) before reporting a bug or providing a new feature. + +The [Development Guidelines](DEVELOPMENT.md) have more information on some of the internal workings of Bash-it, please feel free to read through this page if you're interested in how Bash-it loads its components. + ## Install 1. Check out a clone of this repo to a location of your choice, such as: `git clone --depth=1 https://github.com/Bash-it/bash-it.git ~/.bash_it` @@ -174,10 +180,6 @@ cd $BASH_IT This will restore your previous Bash profile. After the uninstall script finishes, remove the Bash-it directory from your machine (`rm -rf $BASH_IT`) and start a new shell. -## Contributing - -Please take a look at the [Contribution Guidelines](CONTRIBUTING.md) before reporting a bug or providing a new feature. - ## Misc ### Bash Profile Aliases From 00395345174a30feae97321d37199c8c513b6b7d Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 26 May 2017 08:42:21 +0200 Subject: [PATCH 47/67] Renamed a couple of variables --- lib/helpers.bash | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index b1508c1c..38e5b6be 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -345,19 +345,19 @@ _enable-thing () typeset f $file_type for f in $BASH_IT/$subdirectory/available/*.bash do - plugin=$(basename $f .$file_type.bash) - _enable-thing $subdirectory $file_type $plugin $load_priority + to_enable=$(basename $f .$file_type.bash) + _enable-thing $subdirectory $file_type $to_enable $load_priority done else - typeset plugin=$(command ls $BASH_IT/$subdirectory/available/$file_entity.*bash 2>/dev/null | head -1) - if [ -z "$plugin" ]; then + typeset to_enable=$(command ls $BASH_IT/$subdirectory/available/$file_entity.*bash 2>/dev/null | head -1) + if [ -z "$to_enable" ]; then printf '%s\n' "sorry, $file_entity does not appear to be an available $file_type." return fi - plugin=$(basename $plugin) + 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$plugin,$plugin} 2>/dev/null | head -1) + 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) if [ ! -z "$enabled_plugin" ] ; then printf '%s\n' "$file_entity is already enabled." return @@ -366,10 +366,10 @@ _enable-thing () mkdir -p $BASH_IT/$subdirectory/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/$plugin | awk -F': ' '{ print $2 }') + 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/$plugin $BASH_IT/$subdirectory/enabled/$use_load_priority$BASH_IT_LOAD_PRIORITY_SEPARATOR$plugin + ln -s ../available/$to_enable $BASH_IT/$subdirectory/enabled/$use_load_priority$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable fi if [ -n "$BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE" ]; then From 951fe918c028c3315838bb0ff9546541dbee8699 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Fri, 26 May 2017 08:43:31 +0200 Subject: [PATCH 48/67] Automatically running migration command when enabling/disabling components --- lib/helpers.bash | 7 ++++++ test/lib/helpers.bats | 56 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/lib/helpers.bash b/lib/helpers.bash index 38e5b6be..bb53513f 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -88,6 +88,9 @@ bash-it () fi if [ x"$verb" == x"enable" -o x"$verb" == x"disable" ];then + # Automatically run a migration if required + _bash-it-migrate + for arg in "$@" do $func $arg @@ -159,6 +162,7 @@ _bash-it-migrate() { for file_type in "aliases" "plugins" "completion" do + shopt -s nullglob for f in $BASH_IT/$file_type/enabled/*.bash do typeset ff=$(basename $f) @@ -169,6 +173,8 @@ _bash-it-migrate() { typeset single_type=$(echo $ff | awk -F'.' '{print $2}' | sed 's/aliases/alias/g') typeset component_name=$(echo $ff | cut -d'.' -f1) + echo "Migrating $single_type $component_name." + disable_func="_disable-$single_type" enable_func="_enable-$single_type" @@ -176,6 +182,7 @@ _bash-it-migrate() { $enable_func $component_name fi done + shopt -u nullglob done } diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index c6f53c0a..47fdb229 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -21,6 +21,12 @@ function local_setup { assert [ -L "$BASH_IT/plugins/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" ] +} + @test "bash-it: enable the nvm plugin" { run _enable-plugin "nvm" assert_line "0" 'nvm enabled with priority 225.' @@ -34,6 +40,14 @@ function local_setup { assert [ ! -L "$BASH_IT/plugins/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.' + assert [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ] + assert [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ] +} + @test "bash-it: disable a plugin that is not enabled" { run _disable-plugin "sdkman" assert_line "0" 'sorry, sdkman does not appear to be an enabled plugin.' @@ -96,6 +110,48 @@ function local_setup { assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] } +@test "bash-it: 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" { + run _enable-plugin "ssh" + assert [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ] + + run _bash-it-migrate + assert [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ] +} + +@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" ] + + run bash-it enable 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 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" ] +} + +@test "bash-it: 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 + 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 [ ! -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" ] +} + @test "bash-it: enable all plugins" { run _enable-plugin "all" local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l | xargs) From 6f26f92c973415774615dfe338d565c8b190c561 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Mon, 29 May 2017 07:33:52 +0200 Subject: [PATCH 49/67] Fixed checks for enabled files in existing plugins --- plugins/available/base.plugin.bash | 6 +++--- plugins/available/z.plugin.bash | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/available/base.plugin.bash b/plugins/available/base.plugin.bash index c93ed4e7..74ca2087 100644 --- a/plugins/available/base.plugin.bash +++ b/plugins/available/base.plugin.bash @@ -136,7 +136,7 @@ function usage () fi } -if [ ! -e $BASH_IT/plugins/enabled/todo.plugin.bash ]; then +if [ ! -e "${BASH_IT}/plugins/enabled/todo.plugin.bash" ] && [ ! -e "${BASH_IT}/plugins/enabled/*${BASH_IT_LOAD_PRIORITY_SEPARATOR}todo.plugin.bash" ]; then # if user has installed todo plugin, skip this... function t () { @@ -197,10 +197,10 @@ function buf () cp -a "${filename}" "${filename}_${filetime}" } -function del() { +function del() { about 'move files to hidden folder in tmp, that gets cleared on each reboot' param 'file or folder to be deleted' example 'del ./file.txt' group 'base' - mkdir -p /tmp/.trash && mv "$@" /tmp/.trash; + mkdir -p /tmp/.trash && mv "$@" /tmp/.trash; } diff --git a/plugins/available/z.plugin.bash b/plugins/available/z.plugin.bash index 66535756..7cfb7932 100644 --- a/plugins/available/z.plugin.bash +++ b/plugins/available/z.plugin.bash @@ -15,7 +15,7 @@ about-plugin ' z is DEPRECATED, use fasd instead' # * z -t foo # goes to most recently accessed dir matching foo # * z -l foo # list all dirs matching foo (by frecency) -if [ -e $BASH_IT/plugins/enabled/fasd.plugin.bash ]; then +if [ -e "${BASH_IT}/plugins/enabled/fasd.plugin.bash" ] || [ -e "${BASH_IT}/plugins/enabled/*${BASH_IT_LOAD_PRIORITY_SEPARATOR}fasd.plugin.bash" ]; then printf '%s\n' 'sorry, the z plugin is incompatible with the fasd plugin. you may use either, but not both.' return fi From 0d9a0987d939f78349b9707f11544a7be75f369b Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Mon, 29 May 2017 07:47:17 +0200 Subject: [PATCH 50/67] Fixed missing quotes around $BASH_IT variable This should fix most issues where Bash-it is installed in a directory containing spaces. --- aliases/available/general.aliases.bash | 2 +- completion/available/bash-it.completion.bash | 8 ++--- lib/helpers.bash | 38 ++++++++++---------- lib/preview.bash | 2 +- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/aliases/available/general.aliases.bash b/aliases/available/general.aliases.bash index a4cf4ee2..7f3dbd4d 100644 --- a/aliases/available/general.aliases.bash +++ b/aliases/available/general.aliases.bash @@ -21,7 +21,7 @@ alias _="sudo" # colored grep # Need to check an existing file for a pattern that will be found to ensure # that the check works when on an OS that supports the color option -if grep --color=auto "a" $BASH_IT/*.md &> /dev/null +if grep --color=auto "a" "${BASH_IT}/"*.md &> /dev/null then alias grep='grep --color=auto' export GREP_COLOR='1;33' diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 6bcd179b..4d28723d 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -10,9 +10,9 @@ _bash-it-comp-list-available-not-enabled() { subdirectory="$1" - local available_things=$(for f in `ls -1 $BASH_IT/$subdirectory/available/*.bash`; + local available_things=$(for f in `ls -1 "${BASH_IT}/$subdirectory/available/"*.bash`; do - if [ ! -e $BASH_IT/$subdirectory/enabled/$(basename $f) ] && [ ! -e $BASH_IT/$subdirectory/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ] + 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 @@ -25,7 +25,7 @@ _bash-it-comp-list-enabled() { subdirectory="$1" - local enabled_things=$(for f in `ls -1 $BASH_IT/$subdirectory/enabled/*.bash`; + local enabled_things=$(for f in `ls -1 "${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 `ls -1 "${BASH_IT}/$subdirectory/available/"*.bash`; do basename $f | cut -d'.' -f1 done) diff --git a/lib/helpers.bash b/lib/helpers.bash index bb53513f..138d8392 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -163,7 +163,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 "${BASH_IT}/$file_type/enabled/"*.bash do typeset ff=$(basename $f) @@ -203,10 +203,10 @@ _bash-it-describe () typeset f typeset enabled printf "%-20s%-10s%s\n" "$column_header" 'Enabled?' 'Description' - for f in $BASH_IT/$subdirectory/available/*.bash + 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}/$subdirectory/enabled/"$(basename $f) ] || [ -e "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ]; then enabled='x' else enabled=' ' @@ -268,14 +268,14 @@ _disable-thing () if [ "$file_entity" = "all" ]; then typeset f $file_type - for f in $BASH_IT/$subdirectory/available/*.bash + for f in "${BASH_IT}/$subdirectory/available/"*.bash do plugin=$(basename $f) - if [ -e $BASH_IT/$subdirectory/enabled/$plugin ]; then - rm $BASH_IT/$subdirectory/enabled/$(basename $plugin) + 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) + 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 done else @@ -283,12 +283,12 @@ _disable-thing () # 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.*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) + rm "${BASH_IT}/$subdirectory/enabled/$(basename $plugin)" fi if [ -n "$BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE" ]; then @@ -350,13 +350,13 @@ _enable-thing () if [ "$file_entity" = "all" ]; then typeset f $file_type - for f in $BASH_IT/$subdirectory/available/*.bash + for f in "${BASH_IT}/$subdirectory/available/"*.bash do to_enable=$(basename $f .$file_type.bash) _enable-thing $subdirectory $file_type $to_enable $load_priority done else - typeset to_enable=$(command ls $BASH_IT/$subdirectory/available/$file_entity.*bash 2>/dev/null | head -1) + typeset to_enable=$(command ls "${BASH_IT}/$subdirectory/available/"$file_entity.*bash 2>/dev/null | head -1) if [ -z "$to_enable" ]; then printf '%s\n' "sorry, $file_entity does not appear to be an available $file_type." return @@ -364,19 +364,19 @@ _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]*$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 - mkdir -p $BASH_IT/$subdirectory/enabled + mkdir -p "${BASH_IT}/$subdirectory/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 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 ../available/$to_enable "${BASH_IT}/$subdirectory/enabled/${use_load_priority}${BASH_IT_LOAD_PRIORITY_SEPARATOR}${to_enable}" fi if [ -n "$BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE" ]; then @@ -410,14 +410,14 @@ _help-aliases() alias_path="available/$1.aliases.bash" ;; esac - cat $BASH_IT/aliases/$alias_path | metafor alias | sed "s/$/'/" + cat "${BASH_IT}/aliases/$alias_path" | metafor alias | sed "s/$/'/" else typeset f - for f in $BASH_IT/aliases/enabled/* + for f in "${BASH_IT}/aliases/enabled/"* do _help-list-aliases $f done - _help-list-aliases $BASH_IT/aliases/custom.aliases.bash + _help-list-aliases "${BASH_IT}/aliases/custom.aliases.bash" fi } diff --git a/lib/preview.bash b/lib/preview.bash index 306b475a..d0fb0623 100644 --- a/lib/preview.bash +++ b/lib/preview.bash @@ -14,6 +14,6 @@ then BASH_IT_THEME=${BASH_IT_THEME##*/} echo " $BASH_IT_THEME" - echo "" | bash --init-file $BASH_IT/bash_it.sh -i + echo "" | bash --init-file "${BASH_IT}/bash_it.sh" -i done fi From c598487303c2073b336a2c0943f4fd5bdf4c9d79 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Mon, 29 May 2017 07:52:17 +0200 Subject: [PATCH 51/67] Added note about quoting $BASH_IT variable --- CONTRIBUTING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index aa4a65b5..9c365a75 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -23,6 +23,7 @@ When contributing a new feature, a bug fix, a new theme, or any other change to * Internal functions that aren't to be used by the end user should start with an underscore, e.g. `_my-new-internal-function`. * Use the provided meta functions to document your code, e.g. `about-plugin`, `about`, `group`, `param`, `example`. This will make it easier for other people to use your new functionality. Take a look at the existing code for an example (e.g. [the base plugin](plugins/available/base.plugin.bash)). * When adding files, please use the existing file naming conventions, e.g. plugin files need to end in `.plugin.bash`. This is important for the installation functionality. +* When using the `$BASH_IT` variable, please always enclose it in double quotes to ensure that the code also works when Bash-it is installed in a directory that contains spaces in its name: `for f in "${BASH_IT}/plugins/available"/*.bash ; do echo "$f" ; done` ## Unit Tests From 3fac1c7ea5b3ce4d0a270f8bea0e516278bc7473 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Mon, 29 May 2017 17:29:06 +0200 Subject: [PATCH 52/67] Fix checks for battery plugin These now check for the presence of the required function instead of checking for the battery file in the enabled directory. --- themes/base.theme.bash | 4 +++- themes/brainy/brainy.theme.bash | 2 +- themes/demula/demula.theme.bash | 11 +++++------ themes/rana/rana.theme.bash | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 84928acd..89c01e3b 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -474,13 +474,15 @@ function battery_char { fi } -if [ ! -e "$BASH_IT"/plugins/enabled/battery.plugin.bash ]; then +if ! command_exists battery_charge ; then # if user has installed battery plugin, skip this... function battery_charge (){ # no op echo -n } +fi +if ! command_exists battery_char ; then function battery_char (){ # no op echo -n diff --git a/themes/brainy/brainy.theme.bash b/themes/brainy/brainy.theme.bash index e840c004..d689332e 100644 --- a/themes/brainy/brainy.theme.bash +++ b/themes/brainy/brainy.theme.bash @@ -152,7 +152,7 @@ ___brainy_prompt_clock() { } ___brainy_prompt_battery() { - [ ! -e $BASH_IT/plugins/enabled/battery.plugin.bash ] || + ! command_exists battery_percentage || [ "${THEME_SHOW_BATTERY}" != "true" ] && return info=$(battery_percentage) color=$bold_green diff --git a/themes/demula/demula.theme.bash b/themes/demula/demula.theme.bash index ed03a708..e698def5 100644 --- a/themes/demula/demula.theme.bash +++ b/themes/demula/demula.theme.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env bash # Theme inspired on: # - Ronacher's dotfiles (mitsuhikos) - http://github.com/mitsuhiko/dotfiles/tree/master/bash/ @@ -10,7 +10,7 @@ # Screenshot: http://goo.gl/VCmX5 # by Jesus de Mula -# For the real Monokai colors you should add these to your .XDefaults or +# For the real Monokai colors you should add these to your .XDefaults or # terminal configuration: #! ----------------------------------------------------------- TERMINAL COLORS #! monokai - http://www.monokai.nl/blog/2006/07/15/textmate-color-theme/ @@ -68,7 +68,7 @@ mitsuhikos_lastcommandfailed() { if [ $code != 0 ]; then echo "${D_INTERMEDIATE_COLOR}exited ${D_CMDFAIL_COLOR}\ -$code ${D_DEFAULT_COLOR}" +$code ${D_DEFAULT_COLOR}" fi } @@ -78,13 +78,13 @@ demula_vcprompt() { then local D_VCPROMPT_FORMAT="on ${D_SCM_COLOR}%s${D_INTERMEDIATE_COLOR}:\ ${D_BRANCH_COLOR}%b %r ${D_CHANGES_COLOR}%m%u ${D_DEFAULT_COLOR}" - $VCPROMPT_EXECUTABLE -f "$D_VCPROMPT_FORMAT" + $VCPROMPT_EXECUTABLE -f "$D_VCPROMPT_FORMAT" fi } # checks if the plugin is installed before calling battery_charge safe_battery_charge() { - if [ -e "${BASH_IT}/plugins/enabled/battery.plugin.bash" ]; + if command_exists battery_charge ; then battery_charge fi @@ -127,4 +127,3 @@ ${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}" # Runs prompt (this bypasses bash_it $PROMPT setting) safe_append_prompt_command prompt - diff --git a/themes/rana/rana.theme.bash b/themes/rana/rana.theme.bash index c1122429..0aed8348 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 [ -e "${BASH_IT}/plugins/enabled/battery.plugin.bash" ]; + if command_exists battery_charge ; then battery_charge fi From c33861a9b0a2fc7f94493d174c0fe9b84e81b3b9 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Mon, 29 May 2017 17:36:55 +0200 Subject: [PATCH 53/67] Change dependency check for battery_char function --- themes/base.theme.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 89c01e3b..58e2d288 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -482,7 +482,9 @@ if ! command_exists battery_charge ; then } fi -if ! command_exists battery_char ; then +# 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 function battery_char (){ # no op echo -n From 228b86f3d128e4ad3ffbaa24347abd06817f54e2 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Mon, 29 May 2017 17:45:51 +0200 Subject: [PATCH 54/67] Change order of theme loading The base theme is now loaded after plugins, since it now uses the `command_exists` function, which is defined in the `base` plugin. --- DEVELOPMENT.md | 4 ++-- bash_it.sh | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 5dde8b9b..d9c0abf6 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -9,12 +9,12 @@ This page summarizes a couple of rules to keep in mind when developing features The main `bash_it.sh` script loads the frameworks individual components in the following order: * `lib/composure.bash` -* `themes/colors.theme.bash` -* `themes/base.theme.bash` * Files in `lib` with the exception of `appearance.bash` - this means that `composure.bash` is loaded again here (possible improvement?) * Enabled `aliases` * Enabled `plugins` * Enabled `completions` +* `themes/colors.theme.bash` +* `themes/base.theme.bash` * `lib/appearance.bash`, which loads the selected theme * Custom `aliases` * Custom `plugins` diff --git a/bash_it.sh b/bash_it.sh index 065069ff..43a7509b 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -34,10 +34,6 @@ source "${BASH_IT}/lib/composure.bash" # support 'plumbing' metadata cite _about _param _example _group _author _version -# Load colors first so they can be use in base theme -source "${BASH_IT}/themes/colors.theme.bash" -source "${BASH_IT}/themes/base.theme.bash" - # libraries, but skip appearance (themes) for now LIB="${BASH_IT}/lib/*.bash" APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash" @@ -54,6 +50,10 @@ do _load_bash_it_files $file_type done +# Load colors first so they can be used in base theme +source "${BASH_IT}/themes/colors.theme.bash" +source "${BASH_IT}/themes/base.theme.bash" + # appearance (themes) now, after all dependencies source $APPEARANCE_LIB From 0aad8b4ab0ca3c1301a099e4ea105154e67792ed Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Tue, 30 May 2017 07:25:17 +0200 Subject: [PATCH 55/67] Fixed assert syntax --- test/plugins/base.plugin.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats index 3b21ca7f..a27a4ae7 100755 --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -52,5 +52,5 @@ load ../../plugins/available/base.plugin declare -r file="${BASH_IT_ROOT}/file" touch $file run buf $file - [[ -e ${file}_$(date +%Y%m%d_%H%M%S) ]] + assert [ -e ${file}_$(date +%Y%m%d_%H%M%S) ] } From b55c0251ed78d7e89b6bc7ae7fe9e0eaaa6b2917 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Tue, 30 May 2017 08:33:07 +0200 Subject: [PATCH 56/67] Add tests for base theme's battery functions --- test/run | 2 +- test/themes/base.theme.bats | 69 +++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 test/themes/base.theme.bats diff --git a/test/run b/test/run index 59150a39..737f17e2 100755 --- a/test/run +++ b/test/run @@ -9,4 +9,4 @@ if [ -z "${BASH_IT}" ]; then export BASH_IT=$(cd ${test_directory} && dirname $(pwd)) fi -exec $bats_executable ${CI:+--tap} ${test_directory}/{install,lib,plugins} +exec $bats_executable ${CI:+--tap} ${test_directory}/{install,lib,plugins,themes} diff --git a/test/themes/base.theme.bats b/test/themes/base.theme.bats new file mode 100644 index 00000000..6bf7efed --- /dev/null +++ b/test/themes/base.theme.bats @@ -0,0 +1,69 @@ +#!/usr/bin/env bats + +load ../test_helper +load ../../lib/composure +load ../../plugins/available/base.plugin +load ../../themes/base.theme + +@test 'themes base: battery_percentage should not exist' { + run type -a battery_percentage &> /dev/null + assert_failure +} + +@test 'themes base: battery_percentage should exist if battery plugin loaded' { + load ../../plugins/available/battery.plugin + + run type -a battery_percentage &> /dev/null + assert_success +} + +@test 'themes base: battery_char should exist' { + run type -a battery_char &> /dev/null + assert_success + + run battery_char + assert_success + assert_line "0" "" + + run type -a battery_char + assert_line " echo -n" +} + +@test 'themes base: battery_char should exist if battery plugin loaded' { + unset -f battery_char + load ../../plugins/available/battery.plugin + load ../../themes/base.theme + + run type -a battery_char &> /dev/null + assert_success + + run battery_char + assert_success + + run type -a battery_char + assert_line ' if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" = true ]]; then' +} + +@test 'themes base: battery_charge should exist' { + run type -a battery_charge &> /dev/null + assert_success + + run battery_charge + assert_success + assert_line "0" "" +} + +@test 'themes base: battery_charge should exist if battery plugin loaded' { + unset -f battery_charge + load ../../plugins/available/battery.plugin + load ../../themes/base.theme + + run type -a battery_charge &> /dev/null + assert_success + + run battery_charge + assert_success + + run type -a battery_charge + assert_line ' no)' +} From e13c75c433281d77e0be90f9a6ea616bf6c9efd4 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 31 May 2017 07:36:07 +0200 Subject: [PATCH 57/67] Add safeguard for no battery percentage available --- themes/brainy/brainy.theme.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/themes/brainy/brainy.theme.bash b/themes/brainy/brainy.theme.bash index d689332e..54d29f8b 100644 --- a/themes/brainy/brainy.theme.bash +++ b/themes/brainy/brainy.theme.bash @@ -153,7 +153,9 @@ ___brainy_prompt_clock() { ___brainy_prompt_battery() { ! command_exists battery_percentage || - [ "${THEME_SHOW_BATTERY}" != "true" ] && return + [ "${THEME_SHOW_BATTERY}" != "true" ] || + [ "$(battery_percentage)" = "no" ] && return + info=$(battery_percentage) color=$bold_green if [ "$info" -lt 50 ]; then From 11469fe235937811cc6d34d2b0e14a94d8f632d6 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 31 May 2017 07:42:57 +0200 Subject: [PATCH 58/67] Fix battery_percentage check in Atomic theme Check for the return value "no", which is returned when no battery check funcationality is available in the OS. This is now consistent with how the Brainy theme does this. --- themes/atomic/atomic.theme.bash | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/themes/atomic/atomic.theme.bash b/themes/atomic/atomic.theme.bash index 4e58f014..3df4e7ce 100644 --- a/themes/atomic/atomic.theme.bash +++ b/themes/atomic/atomic.theme.bash @@ -164,8 +164,10 @@ ___atomic_prompt_clock() { } ___atomic_prompt_battery() { - chk=$(command_exists battery_percentage && echo yes || echo no) - [ "$chk" != "yes" ] || [ "${THEME_SHOW_BATTERY}" != "true" ] && return + ! command_exists battery_percentage || + [ "${THEME_SHOW_BATTERY}" != "true" ] || + [ "$(battery_percentage)" = "no" ] && return + batp=$(battery_percentage) if [ "$batp" -eq 50 ] || [ "$batp" -gt 50 ]; then color=$bold_green From bd2e0f1366a911e844cf9044e43ff44e140e2e04 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 31 May 2017 17:26:29 +0200 Subject: [PATCH 59/67] Add note about migrate command to readme --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9b2cec18..47f546da 100644 --- a/README.md +++ b/README.md @@ -55,17 +55,25 @@ Have a look at our [bash-it-docker respository](https://github.com/Bash-it/bash- ## Update -To update Bash-it, simply run: +To update Bash-it to the latest version, simply run: -``` +```bash bash-it update ``` that's all. +If you are using an older version of Bash-it, it's possible that some functionality has changed, or that the internal structure of how Bash-it organizes its functionality has been updated. For these cases, we provide a `migrate` command: + +```bash +bash-it migrate +``` + +This command will automatically migrate the Bash-it structure to the latest version. The `migrate` command is run automatically if you run the `update`, `enable` or `disable` commands. + ## Help Screens -``` +```bash bash-it show aliases # shows installed and available aliases bash-it show completions # shows installed and available completions bash-it show plugins # shows installed and available plugins From f221f63d7df418d538b5171c173676fd611e5d0e Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 31 May 2017 17:34:46 +0200 Subject: [PATCH 60/67] Add completion for help command, and help for migrate --- completion/available/bash-it.completion.bash | 2 +- lib/helpers.bash | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 4d28723d..e3e37ce6 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -61,7 +61,7 @@ _bash-it-comp() return 0 ;; help) - local help_args="plugins aliases completions update" + local help_args="plugins aliases completions migrate update" COMPREPLY=( $(compgen -W "${help_args}" -- ${cur}) ) return 0 ;; diff --git a/lib/helpers.bash b/lib/helpers.bash index 138d8392..7974bd5f 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -469,6 +469,14 @@ _help-update () { echo "Check for a new version of Bash-it and update it." } +_help-migrate () { + _about 'help message for migrate command' + _group 'lib' + + echo "Migrates internal Bash-it structure to the latest version in case of changes." + echo "The 'migrate' command is run automatically when calling 'update', 'enable' or 'disable'." +} + all_groups () { about 'displays all unique metadata groups' From 732b287a57462c685f850658c69710ca295594f8 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Wed, 31 May 2017 17:41:56 +0200 Subject: [PATCH 61/67] Run migrate command after a succesful update --- lib/helpers.bash | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 7974bd5f..d26d39b8 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -145,7 +145,12 @@ _bash-it_update() { if [[ -n "${status}" ]]; then git pull --rebase &> /dev/null if [[ $? -eq 0 ]]; then - echo "Bash-it successfully updated, enjoy!" + echo "Bash-it successfully updated." + echo "" + echo "Migrating your installation to the latest version now..." + _bash-it-migrate + echo "" + echo "All done, enjoy!" reload else echo "Error updating Bash-it, please, check if your Bash-it installation folder (${BASH_IT}) is clean." From 87270c2962609f9cbf4a26de14fb23de9cdaed57 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Tue, 6 Jun 2017 07:26:50 +0200 Subject: [PATCH 62/67] Copy all of Bash-it during the helper tests --- test/lib/helpers.bats | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 47fdb229..1a1fd45c 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -9,9 +9,11 @@ cite _about _param _example _group _author _version load ../../lib/helpers function local_setup { - mkdir -p $BASH_IT/plugins + mkdir -p $BASH_IT lib_directory="$(cd "$(dirname "$0")" && pwd)" - cp -r $lib_directory/../../plugins/available $BASH_IT/plugins + cp -r $lib_directory/../.. $BASH_IT + mkdir -p $BASH_IT/aliases/enabled + mkdir -p $BASH_IT/completion/enabled mkdir -p $BASH_IT/plugins/enabled } From 1068e7916b3c912c5dcb59d2090f738e0d534396 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Tue, 6 Jun 2017 07:32:46 +0200 Subject: [PATCH 63/67] Add tests for enabling aliases and completions --- test/lib/helpers.bats | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 1a1fd45c..e275801c 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -17,6 +17,30 @@ 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/aliases/enabled/150---ansible.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" ] +} + +@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" ] +} + +@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" ] +} + @test "bash-it: enable the node plugin" { run _enable-plugin "node" assert_line "0" 'node enabled with priority 250.' From fc4ce80329b627c889af4959ef4e42fe7e852c10 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Tue, 6 Jun 2017 07:38:19 +0200 Subject: [PATCH 64/67] Add tests for enabling multiple plugins at the same time --- test/lib/helpers.bats | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index e275801c..f43938ce 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -53,6 +53,21 @@ function local_setup { assert [ -L "$BASH_IT/plugins/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" ] +} + +@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" ] +} + @test "bash-it: enable the nvm plugin" { run _enable-plugin "nvm" assert_line "0" 'nvm enabled with priority 225.' From 94e68b96b516dc0e50f90fe13069e6bb80ec98e9 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Tue, 6 Jun 2017 18:06:26 +0200 Subject: [PATCH 65/67] Fix migration of todo.txt-cli component --- lib/helpers.bash | 2 +- test/lib/helpers.bats | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index d26d39b8..fd0fdd1f 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -175,7 +175,7 @@ _bash-it-migrate() { # 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 | awk -F'.' '{print $2}' | sed 's/aliases/alias/g') + 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." diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index f43938ce..b41ef636 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -23,6 +23,12 @@ function local_setup { assert [ -L "$BASH_IT/aliases/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" ] +} + @test "bash-it: enable the curl aliases" { run _enable-alias "curl" assert_line "0" 'curl enabled with priority 150.' @@ -140,6 +146,9 @@ function local_setup { 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" ] + 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" ] + run _enable-plugin "ssh" assert [ -L "$BASH_IT/plugins/enabled/250---ssh.plugin.bash" ] @@ -147,8 +156,10 @@ function local_setup { 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/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: run the migrate command without anything to migrate and nothing enabled" { From 2581abdf5469e833610fd0ba070712172f56f231 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Tue, 6 Jun 2017 18:27:03 +0200 Subject: [PATCH 66/67] Fix some issues that showed the todo.txt-cli aliases in the wrong way --- lib/helpers.bash | 2 +- test/lib/helpers.bats | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index fd0fdd1f..0184455e 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -216,7 +216,7 @@ _bash-it-describe () else enabled=' ' fi - printf "%-20s%-10s%s\n" "$(basename $f | cut -d'.' -f1)" " [$enabled]" "$(cat $f | metafor about-$file_type)" + printf "%-20s%-10s%s\n" "$(basename $f | sed -e 's/\(.*\)\..*\.bash/\1/g')" " [$enabled]" "$(cat $f | metafor about-$file_type)" done printf '\n%s\n' "to enable $preposition $file_type, do:" printf '%s\n' "$ bash-it enable $file_type <$file_type name> [$file_type name]... -or- $ bash-it enable $file_type all" diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index b41ef636..00b13b3a 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -233,3 +233,8 @@ function local_setup { _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 48f04159e0cce694e1d8d1f01aa1671e081efda2 Mon Sep 17 00:00:00 2001 From: David Sharp Date: Mon, 26 Jun 2017 14:50:23 -0700 Subject: [PATCH 67/67] general.aliases: Run `which gshuf` in if condition If .bashrc is sourced while `set -e` is set, and `gshuf` is not installed, then running `which gshuf` will cause the shell to error and exit. Running `which gshuf` during an if condition will capture the error. --- aliases/available/general.aliases.bash | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/aliases/available/general.aliases.bash b/aliases/available/general.aliases.bash index 7f3dbd4d..2d232a1b 100644 --- a/aliases/available/general.aliases.bash +++ b/aliases/available/general.aliases.bash @@ -27,8 +27,7 @@ then export GREP_COLOR='1;33' fi -which gshuf &> /dev/null -if [ $? -eq 0 ] +if which gshuf &> /dev/null then alias shuf=gshuf fi