From bf811cd38e30e63e0ddd7ca5138fb4e115933b2e Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 12 Jan 2022 00:02:52 -0800 Subject: [PATCH 01/66] BATS: require `shellcheck` on test files BATS: add `*.bats` to `.gitattributes` --- .gitattributes | 1 + .pre-commit-config.yaml | 4 +--- hooks/dot-bash.sh | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitattributes b/.gitattributes index de622e0618..8a9080546c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,6 @@ *.sh text eol=lf *.bash text eol=lf +*.bats text eol=lf # Docs allow trailing whitespaces *.md whitespace=-blank-at-eol diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index af5f30afe5..8c3f35253f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,7 +19,6 @@ repos: hooks: - id: git-check # Configure in .gitattributes - id: shellcheck - exclude: ".bats$" - id: shfmt exclude: ".bats$" - repo: https://github.com/Lucas-C/pre-commit-hooks @@ -38,10 +37,9 @@ repos: types: [file] - id: dot-bash name: Check .bash files against bash-it requirements - exclude: "test/test_helper.bash" entry: ./hooks/dot-bash.sh language: system - files: "\\.bash$" + files: "\\.ba[ts][sh]$" types: [file] - id: clean-files-txt name: Check that clean_files.txt is sorted alphabetically. diff --git a/hooks/dot-bash.sh b/hooks/dot-bash.sh index 253cb595e4..94a03708b5 100755 --- a/hooks/dot-bash.sh +++ b/hooks/dot-bash.sh @@ -12,7 +12,8 @@ for file in "$@"; do # Confirm expected schellcheck header # LINE1="$(head -n 1 "${file}")" - if [[ "${LINE1}" != "# shellcheck shell=bash" ]]; then + SCSH="${file##*.}" + if [[ "${LINE1}" != "# shellcheck shell=${SCSH}" ]]; then echo "Bash include file \`${file}\` has bad/missing shellcheck header" exit_code=1 fi From 49b477ef3f64971047088e835cbc36f69c1f46e5 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 13 Feb 2022 16:29:04 -0800 Subject: [PATCH 02/66] test/lib: `shellcheck` --- test/lib/helpers.bats | 392 ++++++++++++++++++++++-------------------- test/lib/log.bats | 33 ++-- test/lib/preexec.bats | 16 +- test/lib/search.bats | 40 ++++- 4 files changed, 271 insertions(+), 210 deletions(-) diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 38a917fe95..b27e775e0a 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -4,25 +4,25 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { setup_libs "colors" - load "${BASH_IT?}/plugins/available/base.plugin.bash" } function local_setup() { # Copy the test fixture to the Bash-it folder - cp -RP "$BASH_IT/test/fixtures/bash_it"/* "$BASH_IT/" + cp -RP "${BASH_IT?}/test/fixtures/bash_it"/* "${BASH_IT?}/" } # TODO Create global __is_enabled function # TODO Create global __get_base_name function # TODO Create global __get_enabled_name function @test "bash-it: verify that the test fixture is available" { - assert_file_exist "$BASH_IT/profiles/test-bad-component.bash_it" - assert_file_exist "$BASH_IT/profiles/test-bad-type.bash_it" + assert_file_exist "${BASH_IT?}/profiles/test-bad-component.bash_it" + assert_file_exist "${BASH_IT?}/profiles/test-bad-type.bash_it" } @test "helpers: _command_exists function exists" { - run type -a _command_exists &> /dev/null + run type -t _command_exists assert_success + assert_output "function" } @test "helpers: _command_exists function positive test ls" { @@ -41,8 +41,9 @@ function local_setup() { } @test "helpers: _binary_exists function exists" { - run type -a _binary_exists &> /dev/null + run type -t _binary_exists assert_success + assert_output "function" } @test "helpers: _binary_exists function positive test ls" { @@ -67,54 +68,54 @@ function local_setup() { @test "helpers: bash-it help aliases without any aliases enabled" { run bash-it help aliases - assert_line -n 0 "" + assert_output "" } @test "helpers: bash-it help plugins" { run bash-it help plugins - assert_line -n 1 "base:" + assert_line -n 1 "composure:" } @test "helpers: bash-it help list aliases without any aliases enabled" { - run _help-list-aliases "$BASH_IT/aliases/available/ag.aliases.bash" + run _help-list-aliases "${BASH_IT?}/aliases/available/ag.aliases.bash" assert_line -n 0 "ag:" } @test "helpers: bash-it help list aliases with ag aliases enabled" { - ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/aliases/enabled/150---ag.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---ag.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" - run _help-list-aliases "$BASH_IT/aliases/enabled/150---ag.aliases.bash" + run _help-list-aliases "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" assert_line -n 0 "ag:" } @test "helpers: bash-it help list aliases with todo.txt-cli aliases enabled" { - ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/todo.txt-cli.aliases.bash" "${BASH_IT?}/aliases/enabled/150---todo.txt-cli.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---todo.txt-cli.aliases.bash" - run _help-list-aliases "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" + run _help-list-aliases "${BASH_IT?}/aliases/enabled/150---todo.txt-cli.aliases.bash" assert_line -n 0 "todo.txt-cli:" } @test "helpers: bash-it help list aliases with docker-compose aliases enabled" { - ln -s $BASH_IT/aliases/available/docker-compose.aliases.bash $BASH_IT/aliases/enabled/150---docker-compose.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/docker-compose.aliases.bash" "${BASH_IT?}/aliases/enabled/150---docker-compose.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---docker-compose.aliases.bash" - run _help-list-aliases "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + run _help-list-aliases "${BASH_IT?}/aliases/enabled/150---docker-compose.aliases.bash" assert_line -n 0 "docker-compose:" } @test "helpers: bash-it help list aliases with ag aliases enabled in global directory" { - ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/enabled/150---ag.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" - run _help-list-aliases "$BASH_IT/enabled/150---ag.aliases.bash" + run _help-list-aliases "${BASH_IT?}/enabled/150---ag.aliases.bash" assert_line -n 0 "ag:" } @test "helpers: bash-it help aliases one alias enabled in the old directory" { - ln -s $BASH_IT/aliases/available/ag.aliases.bash $BASH_IT/aliases/enabled/150---ag.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---ag.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" run bash-it help aliases assert_line -n 0 "ag:" @@ -123,11 +124,11 @@ function local_setup() { @test "helpers: bash-it help aliases one alias enabled in global directory" { run bash-it enable alias "ag" assert_line -n 0 'ag enabled with priority 150.' - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" run bash-it enable plugin "aws" assert_line -n 0 'aws enabled with priority 250.' - assert_link_exist "$BASH_IT/enabled/250---aws.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---aws.plugin.bash" run bash-it help aliases assert_line -n 0 "ag:" @@ -137,58 +138,58 @@ function local_setup() { @test "helpers: enable the todo.txt-cli aliases through the bash-it function" { run bash-it enable alias "todo.txt-cli" assert_line -n 0 'todo.txt-cli enabled with priority 150.' - assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---todo.txt-cli.aliases.bash" } @test "helpers: enable the curl aliases" { run _enable-alias "curl" assert_line -n 0 'curl enabled with priority 150.' - assert_link_exist "$BASH_IT/enabled/150---curl.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---curl.aliases.bash" } @test "helpers: enable the apm completion through the bash-it function" { run bash-it enable completion "apm" assert_line -n 0 'apm enabled with priority 350.' - assert_link_exist "$BASH_IT/enabled/350---apm.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/350---apm.completion.bash" } @test "helpers: enable the brew completion" { run _enable-completion "brew" assert_line -n 0 'brew enabled with priority 375.' - assert_link_exist "$BASH_IT/enabled/375---brew.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/375---brew.completion.bash" } @test "helpers: enable the node plugin" { run _enable-plugin "node" assert_line -n 0 'node enabled with priority 250.' - assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" "../plugins/available/node.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" "../plugins/available/node.plugin.bash" } @test "helpers: enable the node plugin through the bash-it function" { run bash-it enable plugin "node" assert_line -n 0 'node enabled with priority 250.' - assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" } @test "helpers: enable the node and nvm plugins through the bash-it function" { run bash-it enable plugin "node" "nvm" assert_line -n 0 'node enabled with priority 250.' assert_line -n 1 'nvm enabled with priority 225.' - assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" } @test "helpers: enable the foo-unkown and nvm plugins through the bash-it function" { run bash-it enable plugin "foo-unknown" "nvm" assert_line -n 0 'sorry, foo-unknown does not appear to be an available plugin.' assert_line -n 1 'nvm enabled with priority 225.' - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" } @test "helpers: enable the nvm plugin" { run _enable-plugin "nvm" assert_line -n 0 'nvm enabled with priority 225.' - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" } @test "helpers: enable an unknown plugin" { @@ -196,11 +197,11 @@ function local_setup() { assert_line -n 0 'sorry, unknown-foo does not appear to be an available plugin.' # Check for both old an new structure - assert [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ] - assert [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/250---unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/unknown-foo.plugin.bash" ] - assert [ ! -L "$BASH_IT/enabled/250---unknown-foo.plugin.bash" ] - assert [ ! -L "$BASH_IT/enabled/unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/250---unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/unknown-foo.plugin.bash" ] } @test "helpers: enable an unknown plugin through the bash-it function" { @@ -209,11 +210,11 @@ function local_setup() { assert_line -n 0 'sorry, unknown-foo does not appear to be an available plugin.' # Check for both old an new structure - assert [ ! -L "$BASH_IT/plugins/enabled/250---unknown-foo.plugin.bash" ] - assert [ ! -L "$BASH_IT/plugins/enabled/unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/250---unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/unknown-foo.plugin.bash" ] - assert [ ! -L "$BASH_IT/enabled/250---unknown-foo.plugin.bash" ] - assert [ ! -L "$BASH_IT/enabled/unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/250---unknown-foo.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/unknown-foo.plugin.bash" ] } @test "helpers: disable a plugin that is not enabled" { @@ -224,75 +225,75 @@ function local_setup() { @test "helpers: enable and disable the nvm plugin" { run _enable-plugin "nvm" assert_line -n 0 'nvm enabled with priority 225.' - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" - assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" ] run _disable-plugin "nvm" assert_line -n 0 'nvm disabled.' - assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] } @test "helpers: disable the nvm plugin if it was enabled with a priority, but in the component-specific directory" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" - assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] run _disable-plugin "nvm" assert_line -n 0 'nvm disabled.' - assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] - assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] } @test "helpers: disable the nvm plugin if it was enabled without a priority" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" run _disable-plugin "nvm" assert_line -n 0 'nvm disabled.' - assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] } @test "helpers: enable the nvm plugin if it was enabled without a priority" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" run _enable-plugin "nvm" assert_line -n 0 'nvm is already enabled.' - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" - assert [ ! -L "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" ] - assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] } @test "helpers: enable the nvm plugin if it was enabled with a priority, but in the component-specific directory" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" run _enable-plugin "nvm" assert_line -n 0 'nvm is already enabled.' - assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] - assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" - assert [ ! -L "$BASH_IT/enabled/225---nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] + assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert [ ! -L "${BASH_IT?}/enabled/225---nvm.plugin.bash" ] } @test "helpers: enable the nvm plugin twice" { run _enable-plugin "nvm" assert_line -n 0 'nvm enabled with priority 225.' - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" run _enable-plugin "nvm" assert_line -n 0 'nvm is already enabled.' - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" } @test "helpers: profile load command sanity" { run _bash-it-profile-load "default" assert_success - assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash" - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" - assert_link_exist "$BASH_IT/enabled/800---aliases.completion.bash" - assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash" - assert_link_exist "$BASH_IT/enabled/325---system.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/150---general.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/800---aliases.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/325---system.completion.bash" } @test "helpers: profile save command sanity" { @@ -303,14 +304,14 @@ function local_setup() { assert_line -n 1 "Saving completion configuration..." assert_line -n 2 "Saving aliases configuration..." assert_line -n 3 "All done!" - assert_file_exist "$BASH_IT/profiles/test.bash_it" + assert_file_exist "${BASH_IT?}/profiles/test.bash_it" } @test "helpers: profile save creates valid file with only plugin enabled" { run _enable-plugin "nvm" run _bash-it-profile-save "test" - run cat "$BASH_IT/profiles/test.bash_it" + run cat "${BASH_IT?}/profiles/test.bash_it" assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!" assert_line -n 1 "# plugins" assert_line -n 2 "plugins nvm" @@ -320,7 +321,7 @@ function local_setup() { run _enable-completion "bash-it" run _bash-it-profile-save "test" - run cat "$BASH_IT/profiles/test.bash_it" + run cat "${BASH_IT?}/profiles/test.bash_it" assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!" assert_line -n 1 "# completion" assert_line -n 2 "completion bash-it" @@ -330,7 +331,7 @@ function local_setup() { run _enable-alias "general" run _bash-it-profile-save "test" - run cat "$BASH_IT/profiles/test.bash_it" + run cat "${BASH_IT?}/profiles/test.bash_it" assert_line -n 0 "# This file is auto generated by Bash-it. Do not edit manually!" assert_line -n 1 "# aliases" assert_line -n 2 "aliases general" @@ -338,37 +339,53 @@ function local_setup() { @test "helpers: profile edge case, empty configuration" { run _bash-it-profile-save "test" + assert_success assert_line -n 3 "It seems like no configuration was enabled.." assert_line -n 4 "Make sure to double check that this is the wanted behavior." run _enable-alias "general" + assert_success run _enable-plugin "base" - run _enable-plugin "alias-completion" + assert_success + run _enable-completion "aliases" + assert_success run _enable-completion "bash-it" + assert_success run _enable-completion "system" + assert_success run _bash-it-profile-load "test" - assert_link_not_exist "$BASH_IT/enabled/150---general.aliases.bash" - assert_link_not_exist "$BASH_IT/enabled/250---base.plugin.bash" - assert_link_not_exist "$BASH_IT/enabled/800---aliases.completion.bash" - assert_link_not_exist "$BASH_IT/enabled/350---bash-it.completion.bash" - assert_link_not_exist "$BASH_IT/enabled/325---system.completion.bash" + assert_success + assert_line -n 0 "Trying to parse profile 'test'..." + assert_link_not_exist "${BASH_IT?}/enabled/150---general.aliases.bash" + assert_link_not_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_not_exist "${BASH_IT?}/enabled/800---aliases.completion.bash" + assert_link_not_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash" + assert_link_not_exist "${BASH_IT?}/enabled/325---system.completion.bash" } @test "helpers: profile save and load" { run _enable-alias "general" + assert_success run _enable-plugin "base" + assert_success run _enable-plugin "alias-completion" + assert_success run _enable-completion "bash-it" + assert_success run _enable-completion "system" + assert_success run _bash-it-profile-save "test" assert_success run _disable-alias "general" - assert_link_not_exist "$BASH_IT/enabled/150---general.aliases.bash" + assert_success + assert_output "general disabled." + assert_link_not_exist "${BASH_IT?}/enabled/150---general.aliases.bash" run _bash-it-profile-load "test" - assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash" + assert_success + assert_link_exist "${BASH_IT?}/enabled/150---general.aliases.bash" } @test "helpers: profile load corrupted profile file: bad component" { @@ -383,10 +400,10 @@ function local_setup() { @test "helpers: profile rm sanity" { run _bash-it-profile-save "test" - assert_file_exist "$BASH_IT/profiles/test.bash_it" + assert_file_exist "${BASH_IT?}/profiles/test.bash_it" run _bash-it-profile-rm "test" assert_line -n 0 "Removed profile 'test' successfully!" - assert_file_not_exist "$BASH_IT/profiles/test.bash_it" + assert_file_not_exist "${BASH_IT?}/profiles/test.bash_it" } @test "helpers: profile rm no params" { @@ -402,7 +419,7 @@ function local_setup() { @test "helpers: profile rm default" { run _bash-it-profile-rm "default" assert_line -n 0 -p "Can not remove the default profile..." - assert_file_exist "$BASH_IT/profiles/default.bash_it" + assert_file_exist "${BASH_IT?}/profiles/default.bash_it" } @test "helpers: profile rm bad profile name" { @@ -429,11 +446,11 @@ function local_setup() { } @test "helpers: migrate plugins and completions that share the same name" { - ln -s $BASH_IT/completion/available/dirs.completion.bash $BASH_IT/completion/enabled/350---dirs.completion.bash - assert_link_exist "$BASH_IT/completion/enabled/350---dirs.completion.bash" + ln -s "${BASH_IT?}/completion/available/dirs.completion.bash" "${BASH_IT?}/completion/enabled/350---dirs.completion.bash" + assert_link_exist "${BASH_IT?}/completion/enabled/350---dirs.completion.bash" - ln -s $BASH_IT/plugins/available/dirs.plugin.bash $BASH_IT/plugins/enabled/250---dirs.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---dirs.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/dirs.plugin.bash" "${BASH_IT?}/plugins/enabled/250---dirs.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---dirs.plugin.bash" run _bash-it-migrate assert_line -n 0 'Migrating plugin dirs.' @@ -444,60 +461,60 @@ function local_setup() { assert_line -n 5 'dirs enabled with priority 350.' assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate' - assert_link_exist "$BASH_IT/enabled/350---dirs.completion.bash" - assert_link_exist "$BASH_IT/enabled/250---dirs.plugin.bash" - assert [ ! -L "$BASH_IT/completion/enabled/350----dirs.completion.bash" ] - assert [ ! -L "$BASH_IT/plugins/enabled/250----dirs.plugin.bash" ] + assert_link_exist "${BASH_IT?}/enabled/350---dirs.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/250---dirs.plugin.bash" + assert [ ! -L "${BASH_IT?}/completion/enabled/350----dirs.completion.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/250----dirs.plugin.bash" ] } @test "helpers: migrate enabled plugins that don't use the new priority-based configuration" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" - ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/node.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/node.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/node.plugin.bash" + assert_link_exist "${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_link_exist "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/todo.txt-cli.aliases.bash" "${BASH_IT?}/aliases/enabled/todo.txt-cli.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/todo.txt-cli.aliases.bash" run _enable-plugin "ssh" - assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" run _bash-it-migrate assert_line -n 0 'Migrating alias todo.txt-cli.' assert_line -n 1 'todo.txt-cli disabled.' assert_line -n 2 'todo.txt-cli enabled with priority 150.' - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" - assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" - assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" - assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" - assert [ ! -L "$BASH_IT/plugins/enabled/node.plugin.bash" ] - assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] - assert [ ! -L "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" ] + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/150---todo.txt-cli.aliases.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/node.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/aliases/enabled/todo.txt-cli.aliases.bash" ] } @test "helpers: migrate enabled plugins that use the new priority-based configuration in the individual directories" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" - ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" - ln -s $BASH_IT/aliases/available/todo.txt-cli.aliases.bash $BASH_IT/aliases/enabled/250---todo.txt-cli.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/250---todo.txt-cli.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/todo.txt-cli.aliases.bash" "${BASH_IT?}/aliases/enabled/250---todo.txt-cli.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/250---todo.txt-cli.aliases.bash" run _enable-plugin "ssh" - assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" run _bash-it-migrate - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" - assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" - assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" - assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" - assert [ ! -L "$BASH_IT/plugins/enabled/225----node.plugin.bash" ] - assert [ ! -L "$BASH_IT/plugins/enabled/250----nvm.plugin.bash" ] - assert [ ! -L "$BASH_IT/aliases/enabled/250----todo.txt-cli.aliases.bash" ] + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/150---todo.txt-cli.aliases.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/225----node.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/250----nvm.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/aliases/enabled/250----todo.txt-cli.aliases.bash" ] } @test "helpers: run the migrate command without anything to migrate and nothing enabled" { @@ -506,28 +523,28 @@ function local_setup() { @test "helpers: run the migrate command without anything to migrate" { run _enable-plugin "ssh" - assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" run _bash-it-migrate - assert_link_exist "$BASH_IT/enabled/250---ssh.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" } function __migrate_all_components() { - subdirectory="$1" - one_type="$2" - priority="$3" + subdirectory="${1:-}" + one_type="${2:-}" + priority="${3:-}" for f in "${BASH_IT}/$subdirectory/available/"*.bash do - to_enable=$(basename $f) - if [ -z "$priority" ]; then + to_enable=$(basename "$f") + if [[ -z "$priority" ]]; then ln -s "../available/$to_enable" "${BASH_IT}/${subdirectory}/enabled/$to_enable" else ln -s "../available/$to_enable" "${BASH_IT}/${subdirectory}/enabled/$priority---$to_enable" fi done - ls ${BASH_IT}/${subdirectory}/enabled + ls "${BASH_IT?}/${subdirectory}/enabled" all_available=$(compgen -G "${BASH_IT}/${subdirectory}/available/*.$one_type.bash" | wc -l | xargs) all_enabled_old=$(compgen -G "${BASH_IT}/${subdirectory}/enabled/*.$one_type.bash" | wc -l | xargs) @@ -547,47 +564,53 @@ function __migrate_all_components() { subdirectory="plugins" one_type="plugin" - __migrate_all_components "$subdirectory" "$one_type" + run __migrate_all_components "$subdirectory" "$one_type" + assert_success } @test "helpers: migrate all aliases" { subdirectory="aliases" one_type="aliases" - __migrate_all_components "$subdirectory" "$one_type" + run __migrate_all_components "$subdirectory" "$one_type" + assert_success } @test "helpers: migrate all completions" { subdirectory="completion" one_type="completion" - __migrate_all_components "$subdirectory" "$one_type" + run __migrate_all_components "$subdirectory" "$one_type" + assert_success } @test "helpers: migrate all plugins with previous priority" { subdirectory="plugins" one_type="plugin" - __migrate_all_components "$subdirectory" "$one_type" "100" + run __migrate_all_components "$subdirectory" "$one_type" "100" + assert_success } @test "helpers: migrate all aliases with previous priority" { subdirectory="aliases" one_type="aliases" - __migrate_all_components "$subdirectory" "$one_type" "100" + run __migrate_all_components "$subdirectory" "$one_type" "100" + assert_success } @test "helpers: migrate all completions with previous priority" { subdirectory="completion" one_type="completion" - __migrate_all_components "$subdirectory" "$one_type" "100" + run __migrate_all_components "$subdirectory" "$one_type" "100" + assert_success } @test "helpers: verify that existing components are automatically migrated when something is enabled" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" run bash-it enable plugin "node" assert_line -n 0 'Migrating plugin nvm.' @@ -595,16 +618,16 @@ function __migrate_all_components() { assert_line -n 2 'nvm enabled with priority 225.' assert_line -n 3 'If any migration errors were reported, please try the following: reload && bash-it migrate' assert_line -n 4 'node enabled with priority 250.' - assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" - assert_link_exist "$BASH_IT/enabled/250---node.plugin.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" } @test "helpers: verify that existing components are automatically migrated when something is disabled" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert_link_exist "$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_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${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_link_exist "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" run bash-it disable plugin "node" assert_line -n 0 'Migrating plugin node.' @@ -615,89 +638,94 @@ function __migrate_all_components() { assert_line -n 5 'nvm enabled with priority 225.' assert_line -n 6 'If any migration errors were reported, please try the following: reload && bash-it migrate' assert_line -n 7 'node disabled.' - assert [ ! -L "$BASH_IT/plugins/enabled/nvm.plugin.bash" ] - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" - assert [ ! -L "$BASH_IT/plugins/enabled/250---node.plugin.bash" ] - assert [ ! -L "$BASH_IT/enabled/250---node.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" + assert [ ! -L "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" ] + assert [ ! -L "${BASH_IT?}/enabled/250---node.plugin.bash" ] } @test "helpers: enable all plugins" { + local available enabled run _enable-plugin "all" - local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l | xargs) - local enabled=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) + available=$(find "${BASH_IT?}/plugins/available" -name '*.plugin.bash' | wc -l | xargs) + enabled=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) assert_equal "$available" "$enabled" } @test "helpers: disable all plugins" { + local available enabled enabled2 run _enable-plugin "all" - local available=$(find $BASH_IT/plugins/available -name *.plugin.bash | wc -l | xargs) - local enabled=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) + available=$(find "${BASH_IT?}/plugins/available" -name '*.plugin.bash' | wc -l | xargs) + enabled=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) assert_equal "$available" "$enabled" run _enable-alias "ag" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" run _disable-plugin "all" - local enabled2=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) + enabled2=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) assert_equal "0" "$enabled2" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" } @test "helpers: disable all plugins in the old directory structure" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" + local enabled enabled2 + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" - ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/node.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/node.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/node.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/node.plugin.bash" - local enabled=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) + enabled=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) assert_equal "2" "$enabled" run _enable-alias "ag" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" run _disable-plugin "all" - local enabled2=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) + enabled2=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) assert_equal "0" "$enabled2" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" } @test "helpers: disable all plugins in the old directory structure with priority" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/250---nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---nvm.plugin.bash" + local enabled enabled2 + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/250---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---nvm.plugin.bash" - ln -s $BASH_IT/plugins/available/node.plugin.bash $BASH_IT/plugins/enabled/250---node.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---node.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/node.plugin.bash" "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---node.plugin.bash" - local enabled=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) + enabled=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) assert_equal "2" "$enabled" run _enable-alias "ag" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" run _disable-plugin "all" - local enabled2=$(find $BASH_IT/plugins/enabled -name *.plugin.bash | wc -l | xargs) + enabled2=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) assert_equal "0" "$enabled2" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" } @test "helpers: disable all plugins without anything enabled" { - local enabled=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) + local enabled enabled2 + enabled=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) assert_equal "0" "$enabled" run _enable-alias "ag" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" run _disable-plugin "all" - local enabled2=$(find $BASH_IT/enabled -name [0-9]*.plugin.bash | wc -l | xargs) + enabled2=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) assert_equal "0" "$enabled2" - assert_link_exist "$BASH_IT/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" } @test "helpers: enable the ansible aliases through the bash-it function" { run bash-it enable alias "ansible" assert_line -n 0 'ansible enabled with priority 150.' - assert_link_exist "$BASH_IT/enabled/150---ansible.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---ansible.aliases.bash" } @test "helpers: describe the nvm plugin without enabling it" { @@ -707,21 +735,21 @@ function __migrate_all_components() { @test "helpers: describe the nvm plugin after enabling it" { run _enable-plugin "nvm" assert_line -n 0 'nvm enabled with priority 225.' - assert_link_exist "$BASH_IT/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" _bash-it-plugins | grep "nvm" | grep "\[x\]" } @test "helpers: describe the nvm plugin after enabling it in the old directory" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" _bash-it-plugins | grep "nvm" | grep "\[x\]" } @test "helpers: describe the nvm plugin after enabling it in the old directory with priority" { - ln -s $BASH_IT/plugins/available/nvm.plugin.bash $BASH_IT/plugins/enabled/225---nvm.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/225---nvm.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/nvm.plugin.bash" "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/225---nvm.plugin.bash" _bash-it-plugins | grep "nvm" | grep "\[x\]" } diff --git a/test/lib/log.bats b/test/lib/log.bats index 7d868fd6da..906d5fa22c 100644 --- a/test/lib/log.bats +++ b/test/lib/log.bats @@ -1,4 +1,5 @@ # shellcheck shell=bats +# shellcheck disable=SC2034 load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" @@ -7,77 +8,77 @@ function local_setup_file() { } @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_ALL" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?} run _log_debug "test test test" assert_output "DEBUG: default: test test test" } @test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_ALL" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?} run _log_warning "test test test" assert_output " WARN: default: test test test" } @test "lib log: basic error logging with BASH_IT_LOG_LEVEL_ALL" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?} run _log_error "test test test" assert_output "ERROR: default: test test test" } @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_WARNING" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_WARNING + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_WARNING?} run _log_debug "test test test" - refute_output + assert_output "" } @test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_WARNING" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_WARNING + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_WARNING?} run _log_warning "test test test" assert_output " WARN: default: test test test" } @test "lib log: basic error logging with BASH_IT_LOG_LEVEL_WARNING" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_WARNING + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_WARNING?} run _log_error "test test test" assert_output "ERROR: default: test test test" } @test "lib log: basic debug logging with BASH_IT_LOG_LEVEL_ERROR" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ERROR + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ERROR?} run _log_debug "test test test" - refute_output + assert_output "" } @test "lib log: basic warning logging with BASH_IT_LOG_LEVEL_ERROR" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ERROR + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ERROR?} run _log_warning "test test test" - refute_output + assert_output "" } @test "lib log: basic error logging with BASH_IT_LOG_LEVEL_ERROR" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ERROR + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ERROR?} run _log_error "test test test" assert_output "ERROR: default: test test test" } @test "lib log: basic debug silent logging" { run _log_debug "test test test" - refute_output + assert_output "" } @test "lib log: basic warning silent logging" { run _log_warning "test test test" - refute_output + assert_output "" } @test "lib log: basic error silent logging" { run _log_error "test test test" - refute_output + assert_output "" } @test "lib log: logging with prefix" { - BASH_IT_LOG_LEVEL=$BASH_IT_LOG_LEVEL_ALL + BASH_IT_LOG_LEVEL=${BASH_IT_LOG_LEVEL_ALL?} BASH_IT_LOG_PREFIX="nice: prefix: " run _log_debug "test test test" assert_output "DEBUG: nice: prefix: test test test" diff --git a/test/lib/preexec.bats b/test/lib/preexec.bats index 10dc666d04..3c5ed4b041 100644 --- a/test/lib/preexec.bats +++ b/test/lib/preexec.bats @@ -1,4 +1,5 @@ # shellcheck shell=bats +# shellcheck disable=SC2030 disable=SC2031 load ../test_helper @@ -11,8 +12,9 @@ function local_setup { test_prompt_string="" export PROMPT_COMMAND="$test_prompt_string" - load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh + run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_success + load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_equal "${PROMPT_COMMAND}" $'__bp_trap_string="$(trap -p DEBUG)"\ntrap - DEBUG\n__bp_install' } @@ -21,8 +23,9 @@ function local_setup { test_prompt_string="nah" export PROMPT_COMMAND="$test_prompt_string" - load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh + run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_success + load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_equal "${PROMPT_COMMAND}" "$test_prompt_string"$'\n__bp_trap_string="$(trap -p DEBUG)"\ntrap - DEBUG\n__bp_install' } @@ -32,8 +35,9 @@ function local_setup { export PROMPT_COMMAND="$test_prompt_string" export __bp_delay_install="blarg" - load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh + run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_success + load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_equal "${PROMPT_COMMAND}" "$test_prompt_string" @@ -48,8 +52,9 @@ function local_setup { test_prompt_string="" export PROMPT_COMMAND="$test_prompt_string" - load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh + run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_success + load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh run __bp_install assert_success @@ -62,8 +67,9 @@ function local_setup { test_prompt_string="nah" export PROMPT_COMMAND="$test_prompt_string" - load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh + run load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh assert_success + load ../../vendor/github.com/rcaloras/bash-preexec/bash-preexec.sh run __bp_install assert_success diff --git a/test/lib/search.bats b/test/lib/search.bats index e28922f455..99b7cc39c6 100644 --- a/test/lib/search.bats +++ b/test/lib/search.bats @@ -12,25 +12,30 @@ function local_setup() { } @test "search: plugin base" { - export BASH_IT_SEARCH_USE_COLOR=false run _bash-it-search-component 'plugins' 'base' + assert_success assert_line -n 0 ' plugins: base ' } @test "search: git" { + local plugin completion run _bash-it-search 'git' --no-color + assert_success assert_line -n 0 ' aliases: git gitsvn ' assert_line -n 1 -p ' plugins:' for plugin in "autojump" "git" "gitstatus" "git-subrepo" "jgitflow" "jump" do - echo $plugin - assert_line -n 1 -p $plugin + assert_line -n 1 -p "$plugin" + done + for completion in "git" "git_flow" "git_flow_avh" "github-cli" + do + assert_line -n 2 -p "$completion" done - assert_line -n 2 ' completions: git git_flow git_flow_avh github-cli ' } @test "search: ruby gem bundle rake rails" { run _bash-it-search rails ruby gem bundler rake --no-color + assert_success assert_line -n 0 ' aliases: bundler rails ' assert_line -n 1 ' plugins: chruby chruby-auto rails ruby ' @@ -39,6 +44,7 @@ function local_setup() { @test "search: rails ruby gem bundler rake -chruby" { run _bash-it-search rails ruby gem bundler rake -chruby --no-color + assert_success assert_line -n 0 ' aliases: bundler rails ' assert_line -n 1 ' plugins: rails ruby ' @@ -47,22 +53,42 @@ function local_setup() { @test "search: @git" { run _bash-it-search '@git' --no-color + assert_success assert_line -n 0 ' aliases: git ' assert_line -n 1 ' plugins: git ' assert_line -n 2 ' completions: git ' } -@test "search: @git --enable / --disable" { - set -e +@test "search: @git --enable / --disable" { run _bash-it-search '@git' --enable --no-color + assert_success + run _bash-it-search '@git' --no-color + assert_success + assert_line -n 0 -p '✓' + + run _bash-it-search '@git' --disable --no-color + assert_success run _bash-it-search '@git' --no-color + assert_success - [[ "${lines[0]}" =~ '✓' ]] + assert_line -n 0 ' aliases: git ' + assert_line -n 1 ' plugins: git ' + assert_line -n 2 ' completions: git ' +} +@test "search: @git --disable / --enable" { run _bash-it-search '@git' --disable --no-color + assert_success run _bash-it-search '@git' --no-color + assert_success assert_line -n 0 ' aliases: git ' assert_line -n 1 ' plugins: git ' assert_line -n 2 ' completions: git ' + + run _bash-it-search '@git' --enable --no-color + assert_success + run _bash-it-search '@git' --no-color + assert_success + assert_line -n 0 -p '✓' } From 45ab5b3d9668c563e2c6c3742ea8a4144fdcaaef Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 3 Feb 2022 21:57:19 -0800 Subject: [PATCH 03/66] test/theme: `shellcheck` test: don't clobber `$PATH` BATS depends on `$PATH` somehow and if not handled properly, modifying `$PATH` breaks BATS badly. But, it doesn't seem like we have any reason to modify `$PATH` in the first place...so don't. test/svn: don't clobber `$PATH` test/ruby: don't clobber `$PATH` test/search: don't clobber `$PATH` --- test/themes/base.theme.bats | 2 +- test/themes/base.theme.git.bats | 148 ++++++++++++++++---------------- test/themes/base.theme.svn.bats | 44 ++++++---- 3 files changed, 102 insertions(+), 92 deletions(-) diff --git a/test/themes/base.theme.bats b/test/themes/base.theme.bats index 81b08a01fc..dd2b9288ba 100644 --- a/test/themes/base.theme.bats +++ b/test/themes/base.theme.bats @@ -25,7 +25,7 @@ function local_setup_file() { assert_line "function" run battery_char - assert_line -n 0 "" + assert_output "" } @test 'themes base: battery_char should exist if battery plugin loaded' { diff --git a/test/themes/base.theme.git.bats b/test/themes/base.theme.git.bats index b2bc7c5ae0..2d43414d4b 100644 --- a/test/themes/base.theme.git.bats +++ b/test/themes/base.theme.git.bats @@ -20,12 +20,12 @@ add_commit() { enter_new_git_repo() { repo="$(setup_repo)" - pushd "${repo}" + pushd "${repo}" || return } setup_repo() { upstream="$(mktemp -d)" - pushd "$upstream" > /dev/null + pushd "$upstream" > /dev/null || return git init . > /dev/null echo "$upstream" @@ -33,83 +33,83 @@ setup_repo() { setup_repo_with_upstream() { upstream="$(setup_repo)" - pushd "$upstream" > /dev/null + pushd "$upstream" > /dev/null || return add_commit > /dev/null git checkout -b branch-two git checkout -b gone-branch git checkout master - popd > /dev/null + popd > /dev/null || return downstream="$(setup_repo)" - pushd "$downstream" > /dev/null + pushd "$downstream" > /dev/null || return add_commit > /dev/null git remote add my-remote "$upstream" git fetch my-remote git branch -u my-remote/master > /dev/null - popd > /dev/null + popd > /dev/null || return - pushd "$upstream" > /dev/null + pushd "$upstream" > /dev/null || return git branch -d gone-branch > /dev/null - popd > /dev/null + popd > /dev/null || return - pushd "$downstream" > /dev/null + pushd "$downstream" > /dev/null || return git fetch my-remote - popd > /dev/null + popd > /dev/null || return echo "$downstream" } @test 'themes base: Git: when tracking a remote branch: it shows the commits ahead and behind' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' remote="$(setup_repo)" - pushd "$remote" + pushd "$remote" || return add_commit add_commit - popd + popd || return clone="$(mktemp -d)" - pushd "$clone" + pushd "$clone" || return git clone "$remote" clone cd clone SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}" + assert_equal "${SCM_BRANCH?}" "${pre}" add_commit git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ↑1" + assert_equal "${SCM_BRANCH?}" "${pre} ↑1" add_commit git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ↑2" - popd + assert_equal "${SCM_BRANCH?}" "${pre} ↑2" + popd || return - pushd "$remote" + pushd "$remote" || return add_commit add_commit add_commit - popd + popd || return - pushd "$clone/clone" + pushd "$clone/clone" || return git fetch git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ↑2 ↓3" + assert_equal "${SCM_BRANCH?}" "${pre} ↑2 ↓3" git reset HEAD~2 --hard SCM_GIT_BEHIND_CHAR="↓" git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ↓3" + assert_equal "${SCM_BRANCH?}" "${pre} ↓3" } @test 'themes base: Git: when stashes exist: it shows the number of stashes' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' enter_new_git_repo add_commit @@ -121,90 +121,90 @@ setup_repo_with_upstream() { SCM_GIT_SHOW_STASH_INFO=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} {1}" + assert_equal "${SCM_BRANCH?}" "${pre} {1}" touch file2 git add file2 git stash git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} {2}" + assert_equal "${SCM_BRANCH?}" "${pre} {2}" } @test 'themes base: Git: remote info: when there is no upstream remote: is empty' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' post=" ↑1 ↓1" enter_new_git_repo add_commit git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}" + assert_equal "${SCM_BRANCH?}" "${pre}" } @test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is true: includes the remote' { - pre="\$(_git-friendly-ref) → " + pre='$(_git-friendly-ref) → ' eval_pre="master → " post=" ↑1 ↓1" repo="$(setup_repo_with_upstream)" - pushd "${repo}" + pushd "${repo}" || return SCM_GIT_SHOW_REMOTE_INFO=true SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}my-remote${post}" + assert_equal "${SCM_BRANCH?}" "${pre}my-remote${post}" git branch -u my-remote/branch-two git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream)${post}" - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "${eval_pre}my-remote/branch-two${post}" + assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream)'"${post}" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}my-remote/branch-two${post}" } @test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is auto: includes the remote when more than one remote' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' eval_pre="master" post=" ↑1 ↓1" repo="$(setup_repo_with_upstream)" - pushd "${repo}" + pushd "${repo}" || return SCM_GIT_SHOW_REMOTE_INFO=auto SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}${post}" + assert_equal "${SCM_BRANCH?}" "${pre}${post}" pre="${pre} → " eval_pre="${eval_pre} → " git branch -u my-remote/branch-two git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream-branch)${post}" - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "${eval_pre}branch-two${post}" + assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream-branch)'"${post}" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}branch-two${post}" git remote add second-remote "$(mktemp -d)" git branch -u my-remote/master git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}my-remote${post}" + assert_equal "${SCM_BRANCH?}" "${pre}my-remote${post}" git branch -u my-remote/branch-two git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream)${post}" - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "${eval_pre}my-remote/branch-two${post}" + assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream)'"${post}" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}my-remote/branch-two${post}" } @test 'themes base: Git: remote info: when SCM_GIT_SHOW_REMOTE_INFO is false: never include the remote' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' eval_pre="master" post=" ↑1 ↓1" repo="$(setup_repo_with_upstream)" - pushd "${repo}" + pushd "${repo}" || return git remote add second-remote "$(mktemp -d)" git remote add third-remote "$(mktemp -d)" @@ -212,59 +212,59 @@ setup_repo_with_upstream() { SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}${post}" + assert_equal "${SCM_BRANCH?}" "${pre}${post}" pre="${pre} → " eval_pre="${eval_pre} → " git branch -u my-remote/branch-two git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}\$(_git-upstream-branch)${post}" - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "${eval_pre}branch-two${post}" + assert_equal "${SCM_BRANCH?}" "${pre}"'$(_git-upstream-branch)'"${post}" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "${eval_pre}branch-two${post}" } @test 'themes base: Git: remote info: when showing remote info: show if upstream branch is gone' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' post=" ↑1 ↓1" repo="$(setup_repo_with_upstream)" - pushd "${repo}" + pushd "${repo}" || return SCM_GIT_SHOW_REMOTE_INFO=true SCM_GIT_SHOW_COMMIT_COUNT=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} → my-remote${post}" + assert_equal "${SCM_BRANCH?}" "${pre} → my-remote${post}" git checkout gone-branch git fetch --prune --all git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ⇢ my-remote" + assert_equal "${SCM_BRANCH?}" "${pre} ⇢ my-remote" } @test 'themes base: Git: git friendly ref: when a branch is checked out: shows that branch' { enter_new_git_repo git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "master" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "master" git checkout -b second-branch git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "second-branch" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "second-branch" } @test 'themes base: Git: git friendly ref: when a branch is not checked out: shows that branch' { enter_new_git_repo git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "master" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "master" git checkout -b second-branch git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "second-branch" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "second-branch" } @test 'themes base: Git: git friendly ref: when detached: commit has branch and tag: show a tag' { @@ -276,7 +276,7 @@ setup_repo_with_upstream() { git checkout HEAD~1 git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "tag:first-tag" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "tag:first-tag" } @test 'themes base: Git: git friendly ref: when detached: commit has branch and no tag: show a branch' { @@ -287,7 +287,7 @@ setup_repo_with_upstream() { git checkout HEAD~1 git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "detached:master" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "detached:master" } @test 'themes base: Git: git friendly ref: when detached with no branch or tag: commit is parent to a named ref: show relative name' { @@ -297,7 +297,7 @@ setup_repo_with_upstream() { git checkout HEAD~1 git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "detached:master~1" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "detached:master~1" } @test 'themes base: Git: git friendly ref: when detached with no branch or tag: commit is not parent to a named ref: show short sha' { @@ -309,11 +309,11 @@ setup_repo_with_upstream() { git checkout "$sha" git_prompt_vars - assert_equal "$(eval "echo \"$SCM_BRANCH\"")" "detached:$sha" + assert_equal "$(eval "echo \"${SCM_BRANCH?}\"")" "detached:$sha" } @test 'themes base: Git: git friendly ref: shows staged, unstaged, and untracked file counts' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' enter_new_git_repo echo "line1" > file1 @@ -324,7 +324,7 @@ setup_repo_with_upstream() { git commit -m"commit1" git_prompt_vars - assert_equal "$SCM_STATE" " ✓" + assert_equal "${SCM_STATE?}" " ✓" echo "line2" >> file1 git add file1 @@ -332,56 +332,56 @@ setup_repo_with_upstream() { SCM_GIT_SHOW_DETAILS=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} S:1" - assert_equal "$SCM_STATE" " ✗" - assert_equal "$SCM_DIRTY" "3" + assert_equal "${SCM_BRANCH?}" "${pre} S:1" + assert_equal "${SCM_STATE?}" " ✗" + assert_equal "${SCM_DIRTY?}" "3" echo "line2" >> file2 echo "line2" >> file3 echo "line2" >> file4 git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} S:1 U:3" - assert_equal "$SCM_DIRTY" "2" + assert_equal "${SCM_BRANCH?}" "${pre} S:1 U:3" + assert_equal "${SCM_DIRTY?}" "2" echo "line1" > newfile5 echo "line1" > newfile6 git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} S:1 U:3 ?:2" - assert_equal "$SCM_DIRTY" "1" + assert_equal "${SCM_BRANCH?}" "${pre} S:1 U:3 ?:2" + assert_equal "${SCM_DIRTY?}" "1" git config bash-it.hide-status 1 SCM_DIRTY='nope' git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}" - assert_equal "$SCM_DIRTY" "nope" + assert_equal "${SCM_BRANCH?}" "${pre}" + assert_equal "${SCM_DIRTY?}" "nope" } @test 'themes base: Git: git user info: shows user initials' { - pre="\$(_git-friendly-ref)" + pre='$(_git-friendly-ref)' enter_new_git_repo git config user.name "Cool User" git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre}" + assert_equal "${SCM_BRANCH?}" "${pre}" SCM_GIT_SHOW_CURRENT_USER=true git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ☺︎ cu" + assert_equal "${SCM_BRANCH?}" "${pre} ☺︎ cu" git config user.name "Çool Üser" git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ☺︎ çü" + assert_equal "${SCM_BRANCH?}" "${pre} ☺︎ çü" # show initials set by `git pair` git config user.initials "ab cd" git_prompt_vars - assert_equal "$SCM_BRANCH" "${pre} ☺︎ ab+cd" + assert_equal "${SCM_BRANCH?}" "${pre} ☺︎ ab+cd" } diff --git a/test/themes/base.theme.svn.bats b/test/themes/base.theme.svn.bats index 360e8636ae..e2fc10135d 100644 --- a/test/themes/base.theme.svn.bats +++ b/test/themes/base.theme.svn.bats @@ -9,7 +9,7 @@ function local_setup_file() { function setup_repo { upstream="$(mktemp -d)" - pushd "$upstream" > /dev/null + pushd "$upstream" > /dev/null || return # Create a dummy SVN folder - this will not work with an actual `svn` command, # but will be enough to trigger the SVN check in the base theme. mkdir .svn @@ -24,83 +24,93 @@ function setup_svn_path { assert_file_exist "$svn_path/svn" # Make sure that the requested SVN script is on the path - export PATH="$svn_path:/usr/bin:/bin:/usr/sbin" + export PATH="$svn_path:$PATH" } @test 'themes base: SVN: detect SVN repo' { repo="$(setup_repo)" - pushd "$repo" + pushd "$repo" || return setup_svn_path "$BASH_IT/test/fixtures/svn/working" # Init the base theme again so that the working SVN script is detected + run _bash_it_appearance_scm_init + assert_success _bash_it_appearance_scm_init scm # Make sure that the SVN command is used - assert_equal "$SCM" "$SCM_SVN" + assert_equal "${SCM?}" "${SCM_SVN?}" } @test 'themes base: SVN: detect SVN repo even from a subfolder' { repo="$(setup_repo)" - pushd "$repo" + pushd "$repo" || return mkdir foo - pushd foo + pushd foo || return setup_svn_path "$BASH_IT/test/fixtures/svn/working" - # init the base theme again so that the working SVN script is detected + # Init the base theme again so that the working SVN script is detected + run _bash_it_appearance_scm_init + assert_success _bash_it_appearance_scm_init scm # Make sure that the SVN command is used - assert_equal "$SCM" "$SCM_SVN" + assert_equal "${SCM?}" "${SCM_SVN?}" } @test 'themes base: SVN: no SCM if no .svn folder can be found' { repo="$(setup_repo)" - pushd "$repo" + pushd "$repo" || return rm -rf .svn setup_svn_path "$BASH_IT/test/fixtures/svn/working" # Init the base theme again so that the working SVN script is detected + run _bash_it_appearance_scm_init + assert_success _bash_it_appearance_scm_init scm # Make sure that no SVN command is used - assert_equal "$SCM" "$SCM_NONE" + assert_equal "${SCM?}" "${SCM_NONE?}" } @test 'themes base: SVN: ignore SVN repo when using broken SVN command' { repo="$(setup_repo)" - pushd "$repo" + pushd "$repo" || return setup_svn_path "$BASH_IT/test/fixtures/svn/broken" - # Init the base theme again so that the broken SVN script is detected + # Init the base theme again so that the working SVN script is detected + run _bash_it_appearance_scm_init + assert_success _bash_it_appearance_scm_init scm # Make sure that no SVN command is not used - assert_equal "$SCM" "$SCM_NONE" + assert_equal "${SCM?}" "${SCM_NONE?}" } @test 'themes base: SVN: ignore SVN repo even from a subfolder when using a broken SVN' { repo="$(setup_repo)" - pushd "$repo" + pushd "$repo" || return mkdir foo - pushd foo + pushd foo || return setup_svn_path "$BASH_IT/test/fixtures/svn/broken" - # Init the base theme again so that the broken SVN script is detected + # Init the base theme again so that the working SVN script is detected + run _bash_it_appearance_scm_init + assert_success _bash_it_appearance_scm_init scm # Make sure that no SVN command is used - assert_equal "$SCM" "$SCM_NONE" + assert_equal "${SCM?}" "${SCM_NONE?}" } From 99decb80108083040470a55c235dd9c6e7acaed8 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 3 Feb 2022 21:48:03 -0800 Subject: [PATCH 04/66] test/bash_it: `shellcheck` --- test/bash_it/bash_it.bats | 258 ++++++++++++++++---------------------- 1 file changed, 111 insertions(+), 147 deletions(-) diff --git a/test/bash_it/bash_it.bats b/test/bash_it/bash_it.bats index ef3cdbab3c..dc9d28112a 100644 --- a/test/bash_it/bash_it.bats +++ b/test/bash_it/bash_it.bats @@ -9,27 +9,24 @@ function local_setup_file() { } @test "bash-it: verify that the test fixture is available" { - assert_file_exist "$BASH_IT/aliases/available/a.aliases.bash" - assert_file_exist "$BASH_IT/aliases/available/b.aliases.bash" + assert_file_exist "${BASH_IT?}/aliases/available/a.aliases.bash" + assert_file_exist "${BASH_IT?}/aliases/available/b.aliases.bash" } @test "bash-it: load aliases in order" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" - - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/150---a.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -37,22 +34,19 @@ function local_setup_file() { } @test "bash-it: load aliases in priority order" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled - - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/175---a.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/175---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/175---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/175---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -60,24 +54,21 @@ function local_setup_file() { } @test "bash-it: load aliases and plugins in priority order" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled - - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/150---a.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash" - ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/250---c.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---c.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -85,25 +76,21 @@ function local_setup_file() { } @test "bash-it: load aliases, plugins and completions in priority order" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled - mkdir -p $BASH_IT/completion/enabled + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" - - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/150---a.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/completion/enabled/350---b.completion.bash - assert_link_exist "$BASH_IT/completion/enabled/350---b.completion.bash" - ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/250---c.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---c.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/completion/enabled/350---b.completion.bash" + assert_link_exist "${BASH_IT?}/completion/enabled/350---b.completion.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -112,25 +99,21 @@ function local_setup_file() { } @test "bash-it: load aliases, plugins and completions in priority order, even if the priority says otherwise" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled - mkdir -p $BASH_IT/completion/enabled - - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/450---a.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/450---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/completion/enabled/350---b.completion.bash - assert_link_exist "$BASH_IT/completion/enabled/350---b.completion.bash" - ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/950---c.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/950---c.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/450---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/450---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/completion/enabled/350---b.completion.bash" + assert_link_exist "${BASH_IT?}/completion/enabled/350---b.completion.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/950---c.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/950---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -139,24 +122,21 @@ function local_setup_file() { } @test "bash-it: load aliases and plugins in priority order, with one alias higher than plugins" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" - - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/aliases/enabled/350---a.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/350---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash" - ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/plugins/enabled/250---c.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---c.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/350---a.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/350---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -166,21 +146,19 @@ function local_setup_file() { } @test "bash-it: load global aliases in order" { - mkdir -p $BASH_IT/enabled - - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/150---a.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/150---a.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -188,21 +166,19 @@ function local_setup_file() { } @test "bash-it: load global aliases in priority order" { - mkdir -p $BASH_IT/enabled - - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/175---a.aliases.bash - assert_link_exist "$BASH_IT/enabled/175---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/175---a.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/175---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -210,23 +186,21 @@ function local_setup_file() { } @test "bash-it: load global aliases and plugins in priority order" { - mkdir -p $BASH_IT/enabled + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" - - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/150---a.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash" - ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/enabled/250---c.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---c.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/150---a.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -234,23 +208,21 @@ function local_setup_file() { } @test "bash-it: load global aliases and plugins in priority order, with one alias higher than plugins" { - mkdir -p $BASH_IT/enabled - - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/350---a.aliases.bash - assert_link_exist "$BASH_IT/enabled/350---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash" - ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/enabled/250---c.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---c.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/350---a.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/350---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -260,27 +232,24 @@ function local_setup_file() { } @test "bash-it: load global aliases and plugins in priority order, individual old directories are loaded later" { - mkdir -p $BASH_IT/enabled - mkdir -p $BASH_IT/aliases/enabled - - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" - - ln -s $BASH_IT/aliases/available/a.aliases.bash $BASH_IT/enabled/350---a.aliases.bash - assert_link_exist "$BASH_IT/enabled/350---a.aliases.bash" - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---b.aliases.bash" - ln -s $BASH_IT/plugins/available/c.plugin.bash $BASH_IT/enabled/250---c.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---c.plugin.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + + ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/350---a.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/350---a.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---c.plugin.bash" # Add one file in the old directory structure - ln -s $BASH_IT/aliases/available/b.aliases.bash $BASH_IT/aliases/enabled/150---b.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---b.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null assert_success @@ -290,53 +259,48 @@ function local_setup_file() { } @test "bash-it: load enabled aliases from new structure, priority-based" { - mkdir -p $BASH_IT/enabled - ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/enabled/150---atom.aliases.bash - assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash" - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/enabled/150---atom.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/150---atom.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" # The `ah` alias should not exist run alias ah &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias ah &> /dev/null assert_success } @test "bash-it: load enabled aliases from old structure, priority-based" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled - ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/150---atom.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash" - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/250---base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/aliases/enabled/150---atom.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/150---atom.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" # The `ah` alias should not exist run alias ah &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias ah &> /dev/null assert_success } @test "bash-it: load enabled aliases from old structure, without priorities" { - mkdir -p $BASH_IT/aliases/enabled - mkdir -p $BASH_IT/plugins/enabled - ln -s $BASH_IT/aliases/available/atom.aliases.bash $BASH_IT/aliases/enabled/atom.aliases.bash - assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash" - ln -s $BASH_IT/plugins/available/base.plugin.bash $BASH_IT/plugins/enabled/base.plugin.bash - assert_link_exist "$BASH_IT/plugins/enabled/base.plugin.bash" + ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/aliases/enabled/atom.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/atom.aliases.bash" + ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/base.plugin.bash" + assert_link_exist "${BASH_IT?}/plugins/enabled/base.plugin.bash" # The `ah` alias should not exist run alias ah &> /dev/null assert_failure - load "$BASH_IT/bash_it.sh" + load "${BASH_IT?}/bash_it.sh" run alias ah &> /dev/null assert_success From 5f11a0d3a2e74b77325ce0de35ba2fed66316ad4 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 13 Feb 2022 16:29:39 -0800 Subject: [PATCH 05/66] test/completion: `shellcheck` --- test/completion/aliases.completion.bats | 2 +- test/completion/bash-it.completion.bats | 160 ++++++++++++------------ 2 files changed, 83 insertions(+), 79 deletions(-) mode change 100755 => 100644 test/completion/bash-it.completion.bats diff --git a/test/completion/aliases.completion.bats b/test/completion/aliases.completion.bats index 83ae947a35..2367e6154b 100644 --- a/test/completion/aliases.completion.bats +++ b/test/completion/aliases.completion.bats @@ -26,5 +26,5 @@ function local_setup_file() { alias rm='rm -v' run load "${BASH_IT?}/completion/available/aliases.completion.bash" - refute_output + assert_output "" } diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats old mode 100755 new mode 100644 index 29d1dc944b..7fe60e3e19 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -13,11 +13,12 @@ function local_setup_file() { assert_output "function" } -function __check_completion () { +function __check_completion() { # Get the parameters as a single value COMP_LINE=$* # Get the parameters as an array + # shellcheck disable=SC2294 eval set -- "$@" COMP_WORDS=("$@") @@ -25,7 +26,7 @@ function __check_completion () { COMP_POINT=${#COMP_LINE} # Get the last character of the line that was entered - COMP_LAST=$((${COMP_POINT} - 1)) + COMP_LAST=$((COMP_POINT - 1)) # If the last character was a space... if [[ ${COMP_LINE:$COMP_LAST} = ' ' ]]; then @@ -45,315 +46,318 @@ function __check_completion () { @test "completion bash-it: doctor - show options" { run __check_completion 'bash-it doctor ' - assert_line -n 0 "errors warnings all" + assert_output "errors warnings all" } @test "completion bash-it: help - show options" { run __check_completion 'bash-it help ' - assert_line -n 0 "aliases completions migrate plugins update" + assert_output "aliases completions migrate plugins update" } @test "completion bash-it: help - aliases v" { run __check_completion 'bash-it help aliases v' - assert_line -n 0 "vagrant vault vim" + assert_output "vagrant vault vim" } @test "completion bash-it: update - show options" { run __check_completion 'bash-it update ' - assert_line -n 0 "stable dev" + assert_output "stable dev" } @test "completion bash-it: update - show optional flags" { run __check_completion 'bash-it update -' - assert_line -n 0 "-s --silent" + assert_output "-s --silent" } @test "completion bash-it: search - show no options" { run __check_completion 'bash-it search ' - assert_line -n 0 "" + assert_output "" } @test "completion bash-it: migrate - show no options" { run __check_completion 'bash-it migrate ' - assert_line -n 0 "" + assert_output "" } @test "completion bash-it: show options" { run __check_completion 'bash-it ' - assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: bash-ti - show options" { run __check_completion 'bash-ti ' - assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: shit - show options" { run __check_completion 'shit ' - assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: bashit - show options" { run __check_completion 'bashit ' - assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: batshit - show options" { run __check_completion 'batshit ' - assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: bash_it - show options" { run __check_completion 'bash_it ' - assert_line -n 0 "disable enable help migrate reload restart preview profile doctor search show update version" + assert_output "disable enable help migrate reload restart preview profile doctor search show update version" } @test "completion bash-it: profile - show options" { run __check_completion 'bash-it profile ' - assert_line -n 0 "load save list rm" + assert_output "load save list rm" } @test "completion bash-it: profile load - show options" { run __check_completion 'bash-it profile load ' - assert_line -n 0 "default" + assert_output "default" } @test "completion bash-it: show - show options" { run __check_completion 'bash-it show ' - assert_line -n 0 "aliases completions plugins" + assert_output "aliases completions plugins" } @test "completion bash-it: enable - show options" { run __check_completion 'bash-it enable ' - assert_line -n 0 "alias completion plugin" + assert_output "alias completion plugin" } @test "completion bash-it: enable - show options a" { run __check_completion 'bash-it enable a' - assert_line -n 0 "alias" + assert_output "alias" } @test "completion bash-it: disable - show options" { run __check_completion 'bash-it disable ' - assert_line -n 0 "alias completion plugin" + assert_output "alias completion plugin" } @test "completion bash-it: disable - show options a" { run __check_completion 'bash-it disable a' - assert_line -n 0 "alias" + assert_output "alias" } @test "completion bash-it: disable - provide nothing when atom is not enabled" { run __check_completion 'bash-it disable alias ato' - assert_line -n 0 "" + assert_output "" } -@test "completion bash-it: disable - provide all when atom is not enabled" { +@test "completion bash-it: disable - provide 'all' when atom is not enabled" { run __check_completion 'bash-it disable alias a' - assert_line -n 0 "all" + assert_output "all" } @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the old location and name" { - ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/atom.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash" - ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/completion/enabled/apm.completion.bash" + run ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/completion/enabled/apm.completion.bash" assert_link_exist "$BASH_IT/completion/enabled/apm.completion.bash" + run _bash-it-component-item-is-enabled "alias" "atom" + assert_success + run __check_completion 'bash-it disable alias a' - assert_line -n 0 "all atom" + assert_output "all atom" } @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the old location and priority-based name" { - ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash" - ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/completion/enabled/350---apm.completion.bash" + run ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/completion/enabled/350---apm.completion.bash" assert_link_exist "$BASH_IT/completion/enabled/350---apm.completion.bash" run __check_completion 'bash-it disable alias a' - assert_line -n 0 "all atom" + assert_output "all atom" } @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the new location and priority-based name" { - ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash" - ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/enabled/350---apm.completion.bash" + run ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/enabled/350---apm.completion.bash" assert_link_exist "$BASH_IT/enabled/350---apm.completion.bash" run __check_completion 'bash-it disable alias a' - assert_line -n 0 "all atom" + assert_output "all atom" } @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the old location and name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" - ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/plugins/enabled/docker-machine.plugin.bash" + run ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/plugins/enabled/docker-machine.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/docker-machine.plugin.bash" run __check_completion 'bash-it disable plugin docker' - assert_line -n 0 "docker-machine" + assert_output "docker-machine" } @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the old location and priority-based name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" - ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash" + run ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash" run __check_completion 'bash-it disable plugin docker' - assert_line -n 0 "docker-machine" + assert_output "docker-machine" } @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the new location and priority-based name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" - ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/enabled/350---docker-machine.plugin.bash" + run ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/enabled/350---docker-machine.plugin.bash" assert_link_exist "$BASH_IT/enabled/350---docker-machine.plugin.bash" run __check_completion 'bash-it disable plugin docker' - assert_line -n 0 "docker-machine" + assert_output "docker-machine" } @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and name" { - ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" + run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/todo.txt-cli.aliases.bash" - ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/todo.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/todo.plugin.bash" run __check_completion 'bash-it disable alias to' - assert_line -n 0 "todo.txt-cli" + assert_output "todo.txt-cli" } @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and priority-based name" { - ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" + run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" - ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/350---todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/350---todo.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/350---todo.plugin.bash" run __check_completion 'bash-it disable alias to' - assert_line -n 0 "todo.txt-cli" + assert_output "todo.txt-cli" } @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the new location and priority-based name" { - ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" + run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" - ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/enabled/350---todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/enabled/350---todo.plugin.bash" assert_link_exist "$BASH_IT/enabled/350---todo.plugin.bash" run __check_completion 'bash-it disable alias to' - assert_line -n 0 "todo.txt-cli" + assert_output "todo.txt-cli" } @test "completion bash-it: enable - provide the atom aliases when not enabled" { run __check_completion 'bash-it enable alias ato' - assert_line -n 0 "atom" + assert_output "atom" } @test "completion bash-it: enable - provide the a* aliases when not enabled" { run __check_completion 'bash-it enable alias a' - assert_line -n 0 "all ag ansible apt atom" + assert_output "all ag ansible apt atom" } @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the old location and name" { - ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/atom.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/atom.aliases.bash" run __check_completion 'bash-it enable alias a' - assert_line -n 0 "all ag ansible apt" + assert_output "all ag ansible apt" } @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the old location and priority-based name" { - ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash" run __check_completion 'bash-it enable alias a' - assert_line -n 0 "all ag ansible apt" + assert_output "all ag ansible apt" } @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the new location and priority-based name" { - ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash" run __check_completion 'bash-it enable alias a' - assert_line -n 0 "all ag ansible apt" + assert_output "all ag ansible apt" } @test "completion bash-it: enable - provide the docker* plugins when docker-compose is enabled with the old location and name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" run __check_completion 'bash-it enable plugin docker' - assert_line -n 0 "docker docker-compose docker-machine" + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker-* plugins when docker-compose is enabled with the old location and priority-based name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" run __check_completion 'bash-it enable plugin docker' - assert_line -n 0 "docker docker-compose docker-machine" + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker-* plugins when docker-compose is enabled with the new location and priority-based name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" run __check_completion 'bash-it enable plugin docker' - assert_line -n 0 "docker docker-compose docker-machine" + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker* completions when docker-compose is enabled with the old location and name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/docker-compose.aliases.bash" run __check_completion 'bash-it enable completion docker' - assert_line -n 0 "docker docker-compose docker-machine" + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker* completions when docker-compose is enabled with the old location and priority-based name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" run __check_completion 'bash-it enable completion docker' - assert_line -n 0 "docker docker-compose docker-machine" + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker* completions when docker-compose is enabled with the new location and priority-based name" { - ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" run __check_completion 'bash-it enable completion docker' - assert_line -n 0 "docker docker-compose docker-machine" + assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and name" { - ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/todo.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/todo.plugin.bash" run __check_completion 'bash-it enable alias to' - assert_line -n 0 "todo.txt-cli" + assert_output "todo.txt-cli" } @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and priority-based name" { - ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/350---todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/350---todo.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/350---todo.plugin.bash" run __check_completion 'bash-it enable alias to' - assert_line -n 0 "todo.txt-cli" + assert_output "todo.txt-cli" } @test "completion bash-it: enable - provide the todo.txt-cli aliases when todo plugin is enabled with the new location and priority-based name" { - ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/enabled/350---todo.plugin.bash" + run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/enabled/350---todo.plugin.bash" assert_link_exist "$BASH_IT/enabled/350---todo.plugin.bash" run __check_completion 'bash-it enable alias to' - assert_line -n 0 "todo.txt-cli" + assert_output "todo.txt-cli" } From 61247a1b76ebf9da0ae8ec53498fc2a068357c6a Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 4 Mar 2022 14:20:40 -0800 Subject: [PATCH 06/66] test/plugin: `shellcheck` --- test/plugins/base.plugin.bats | 32 +++++++++++--------- test/plugins/cmd-returned-notify.plugin.bats | 13 ++++---- test/plugins/go.plugin.bats | 27 +++++++++-------- test/plugins/ruby.plugin.bats | 3 +- test/plugins/xterm.plugin.bats | 9 +++--- 5 files changed, 45 insertions(+), 39 deletions(-) diff --git a/test/plugins/base.plugin.bats b/test/plugins/base.plugin.bats index 6022451a91..11b8ee0cf5 100644 --- a/test/plugins/base.plugin.bats +++ b/test/plugins/base.plugin.bats @@ -8,37 +8,39 @@ function local_setup_file() { } @test 'plugins base: ips()' { - declare -r localhost='127.0.0.1' + readonly localhost='127.0.0.1' run ips assert_success - assert_line $localhost + assert_line "$localhost" } @test 'plugins base: myip()' { + local mask_ip run myip assert_success - declare -r mask_ip=$(echo $output | tr -s '[0-9]' '?') - [[ $mask_ip == 'Your public IP is:'*'?.?.?.?'* ]] + shopt -s extglob + mask_ip="${output//+([[:digit:]]|[[:digit:]][[:digit:]]|[[:digit:]][[:digit:]][[:digit:]])/?}" #$(echo "$output" | tr -s '0-9' '?') + [[ $mask_ip == 'Your public IP is: ?.?.?.? ' ]] } @test 'plugins base: pickfrom()' { - stub_file="${BATS_TEST_TMPDIR}/stub_file" - printf "l1\nl2\nl3" > $stub_file - run pickfrom $stub_file + stub_file="${BATS_TEST_TMPDIR?}/stub_file" + printf "l1\nl2\nl3" > "$stub_file" + run pickfrom "$stub_file" assert_success [[ $output == l? ]] } @test 'plugins base: mkcd()' { - cd "${BATS_TEST_TMPDIR}" + cd "${BATS_TEST_TMPDIR?}" declare -r dir_name="-dir_with_dash" # Make sure that the directory does not exist prior to the test - rm -rf "${BATS_TEST_TMPDIR}/${dir_name}" + rm -rf "${BATS_TEST_TMPDIR:?}/${dir_name}" run mkcd "${dir_name}" assert_success - assert_dir_exist "${BATS_TEST_TMPDIR}/${dir_name}" + assert_dir_exist "${BATS_TEST_TMPDIR?}/${dir_name}" mkcd "${dir_name}" assert_equal "${PWD}" "${BATS_TEST_TMPDIR//\/\///}/${dir_name}" @@ -46,20 +48,20 @@ function local_setup_file() { @test 'plugins base: lsgrep()' { for i in 1 2 3; do mkdir -p "${BASH_IT}/${i}"; done - cd $BASH_IT + cd "${BASH_IT?}" run lsgrep 2 assert_success - assert_equal $output 2 + assert_equal "$output" 2 } @test 'plugins base: buf()' { - declare -r file="${BATS_TEST_TMPDIR}/file" - touch $file + declare -r file="${BATS_TEST_TMPDIR?}/file" + touch "$file" # Take one timestamp before running the `buf` function declare -r stamp1=$(date +%Y%m%d_%H%M%S) - run buf $file + run buf "$file" # Take another timestamp after running `buf`. declare -r stamp2=$(date +%Y%m%d_%H%M%S) diff --git a/test/plugins/cmd-returned-notify.plugin.bats b/test/plugins/cmd-returned-notify.plugin.bats index 04edad9582..e120e9ef6b 100644 --- a/test/plugins/cmd-returned-notify.plugin.bats +++ b/test/plugins/cmd-returned-notify.plugin.bats @@ -1,4 +1,5 @@ # shellcheck shell=bats +# shellcheck disable=SC2034 load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" @@ -8,8 +9,8 @@ function local_setup_file() { } @test "plugins cmd-returned-notify: notify after elapsed time" { - export NOTIFY_IF_COMMAND_RETURNS_AFTER=0 - export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" + NOTIFY_IF_COMMAND_RETURNS_AFTER=0 + COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" sleep 1 run precmd_return_notification assert_success @@ -17,8 +18,8 @@ function local_setup_file() { } @test "plugins cmd-returned-notify: do not notify before elapsed time" { - export NOTIFY_IF_COMMAND_RETURNS_AFTER=10 - export COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" + NOTIFY_IF_COMMAND_RETURNS_AFTER=10 + COMMAND_DURATION_START_SECONDS="${EPOCHREALTIME:-$SECONDS}" sleep 1 run precmd_return_notification assert_success @@ -26,13 +27,13 @@ function local_setup_file() { } @test "lib command_duration: preexec no output" { - export COMMAND_DURATION_START_SECONDS= + COMMAND_DURATION_START_SECONDS= run _command_duration_pre_exec assert_success assert_output "" } @test "lib command_duration: preexec set COMMAND_DURATION_START_SECONDS" { - export COMMAND_DURATION_START_SECONDS= + COMMAND_DURATION_START_SECONDS= assert_equal "${COMMAND_DURATION_START_SECONDS}" "" NOW="${EPOCHREALTIME:-$SECONDS}" _command_duration_pre_exec diff --git a/test/plugins/go.plugin.bats b/test/plugins/go.plugin.bats index ebb9cd8823..b8fb779a4b 100644 --- a/test/plugins/go.plugin.bats +++ b/test/plugins/go.plugin.bats @@ -1,4 +1,5 @@ # shellcheck shell=bats +# shellcheck disable=SC2034 load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" @@ -21,7 +22,7 @@ function setup_go_path() @test 'ensure _bash-it-gopath-pathmunge is defined' { { _command_exists go && go version &>/dev/null; } || skip 'golang not found' - load ../../plugins/available/go.plugin + load "${BASH_IT?}/plugins/available/go.plugin.bash" run type -t _bash-it-gopath-pathmunge assert_line 'function' } @@ -29,39 +30,39 @@ function setup_go_path() @test 'plugins go: single entry in GOPATH' { { _command_exists go && go version &>/dev/null; } || skip 'golang not found' setup_go_path "$BASH_IT/test/fixtures/go/gopath" - load ../../plugins/available/go.plugin - assert_equal "$(cut -d':' -f1 <<<$PATH)" "$BASH_IT/test/fixtures/go/gopath/bin" + load "${BASH_IT?}/plugins/available/go.plugin.bash" + assert_equal "$(cut -d':' -f1 <<<"$PATH")" "$BASH_IT/test/fixtures/go/gopath/bin" } @test 'plugins go: single entry in GOPATH, with space' { { _command_exists go && go version &>/dev/null; } || skip 'golang not found' setup_go_path "$BASH_IT/test/fixtures/go/go path" - load ../../plugins/available/go.plugin - assert_equal "$(cut -d':' -f1 <<<$PATH)" "$BASH_IT/test/fixtures/go/go path/bin" + load "${BASH_IT?}/plugins/available/go.plugin.bash" + assert_equal "$(cut -d':' -f1 <<<"$PATH")" "$BASH_IT/test/fixtures/go/go path/bin" } @test 'plugins go: single entry in GOPATH, with escaped space' { skip 'huh?' { _command_exists go && go version &>/dev/null; } || skip 'golang not found' setup_go_path "$BASH_IT/test/fixtures/go/go\ path" - load ../../plugins/available/go.plugin - assert_equal "$(cut -d':' -f1 <<<$PATH)" "$BASH_IT/test/fixtures/go/go\ path/bin" + load "${BASH_IT?}/plugins/available/go.plugin.bash" + assert_equal "$(cut -d':' -f1 <<<"$PATH")" "$BASH_IT/test/fixtures/go/go\ path/bin" } @test 'plugins go: multiple entries in GOPATH' { { _command_exists go && go version &>/dev/null; } || skip 'golang not found' setup_go_path "$BASH_IT/test/fixtures/go/gopath" setup_go_path "$BASH_IT/test/fixtures/go/gopath2" - load ../../plugins/available/go.plugin - assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "$BASH_IT/test/fixtures/go/gopath2/bin:$BASH_IT/test/fixtures/go/gopath/bin" + load "${BASH_IT?}/plugins/available/go.plugin.bash" + assert_equal "$(cut -d':' -f1,2 <<<"$PATH")" "$BASH_IT/test/fixtures/go/gopath2/bin:$BASH_IT/test/fixtures/go/gopath/bin" } @test 'plugins go: multiple entries in GOPATH, with space' { { _command_exists go && go version &>/dev/null; } || skip 'golang not found' setup_go_path "$BASH_IT/test/fixtures/go/gopath" setup_go_path "$BASH_IT/test/fixtures/go/go path" - load ../../plugins/available/go.plugin - assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "$BASH_IT/test/fixtures/go/go path/bin:$BASH_IT/test/fixtures/go/gopath/bin" + load "${BASH_IT?}/plugins/available/go.plugin.bash" + assert_equal "$(cut -d':' -f1,2 <<<"$PATH")" "$BASH_IT/test/fixtures/go/go path/bin:$BASH_IT/test/fixtures/go/gopath/bin" } @test 'plugins go: multiple entries in GOPATH, with escaped space' { @@ -69,6 +70,6 @@ function setup_go_path() { _command_exists go && go version &>/dev/null; } || skip 'golang not found' setup_go_path "$BASH_IT/test/fixtures/go/gopath" setup_go_path "$BASH_IT/test/fixtures/go/go path" - load ../../plugins/available/go.plugin - assert_equal "$(cut -d':' -f1,2 <<<$PATH)" "$BASH_IT/test/fixtures/go/go\ path/bin:$BASH_IT/test/fixtures/go/gopath/bin" + load "${BASH_IT?}/plugins/available/go.plugin.bash" + assert_equal "$(cut -d':' -f1,2 <<<"$PATH")" "$BASH_IT/test/fixtures/go/go\ path/bin:$BASH_IT/test/fixtures/go/gopath/bin" } diff --git a/test/plugins/ruby.plugin.bats b/test/plugins/ruby.plugin.bats index 7bfc64555d..a6ff87c4f3 100644 --- a/test/plugins/ruby.plugin.bats +++ b/test/plugins/ruby.plugin.bats @@ -16,6 +16,7 @@ function local_setup_file() { } @test "plugins ruby: PATH includes ~/.gem/ruby/bin" { + local last_path_entry if ! type ruby >/dev/null; then skip 'ruby not installed' fi @@ -26,6 +27,6 @@ function local_setup_file() { assert_success load "${BASH_IT?}/plugins/available/ruby.plugin.bash" - local last_path_entry="$(tail -1 <<<"${PATH//:/$'\n'}")" + last_path_entry="$(tail -1 <<<"${PATH//:/$'\n'}")" [[ "${last_path_entry}" == "$(ruby -e 'print Gem.user_dir')/bin" ]] } diff --git a/test/plugins/xterm.plugin.bats b/test/plugins/xterm.plugin.bats index 4cb1ffdae0..0d2c629816 100644 --- a/test/plugins/xterm.plugin.bats +++ b/test/plugins/xterm.plugin.bats @@ -1,4 +1,5 @@ # shellcheck shell=bats +# shellcheck disable=SC2034 load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" @@ -8,28 +9,28 @@ function local_setup_file() { } @test "plugins xterm: shorten command output" { - export SHORT_TERM_LINE=true + SHORT_TERM_LINE=true run _short-command "${BASH_IT}/test/fixtures/plugin/xterm/files"/* assert_success assert_output "${BASH_IT}/test/fixtures/plugin/xterm/files/arg0" } @test "plugins xterm: full command output" { - export SHORT_TERM_LINE=false + SHORT_TERM_LINE=false run _short-command "${BASH_IT}/test/fixtures/plugin/xterm/files"/* assert_success assert_output "$(echo "${BASH_IT}/test/fixtures/plugin/xterm/files"/*)" } @test "plugins xterm: shorten dirname output" { - export SHORT_TERM_LINE=true + SHORT_TERM_LINE=true run _short-dirname assert_success assert_output "$(basename "${PWD}")" } @test "plugins xterm: full dirname output" { - export SHORT_TERM_LINE=false + SHORT_TERM_LINE=false run _short-dirname assert_success assert_output "${PWD}" From 6f6a99e3ebf41d91b730ed26cc1a47efceded35c Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 13 Feb 2022 16:30:10 -0800 Subject: [PATCH 07/66] test/install: `shellcheck` --- test/install/install.bats | 21 +++++++++++---------- test/install/uninstall.bats | 18 ++++++++++-------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/test/install/install.bats b/test/install/install.bats index c9e1794c57..c5e3187524 100644 --- a/test/install/install.bats +++ b/test/install/install.bats @@ -3,7 +3,7 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup() { - export HOME="$BATS_TEST_TMPDIR" + export HOME="${BATS_TEST_TMPDIR?}" } function local_setup_file() { @@ -20,7 +20,7 @@ function local_setup_file() { } @test "install: verify that the install script exists" { - assert_file_exist "$BASH_IT/install.sh" + assert_file_exist "${BASH_IT?}/install.sh" } @test "install: run the install script silently" { @@ -30,26 +30,27 @@ function local_setup_file() { assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" - assert_link_exist "$BASH_IT/enabled/150---general.aliases.bash" - assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" - assert_link_exist "$BASH_IT/enabled/800---aliases.completion.bash" - assert_link_exist "$BASH_IT/enabled/350---bash-it.completion.bash" - assert_link_exist "$BASH_IT/enabled/325---system.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/150---general.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + assert_link_exist "${BASH_IT?}/enabled/800---aliases.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash" + assert_link_exist "${BASH_IT?}/enabled/325---system.completion.bash" } @test "install: verify that a backup file is created" { - cd "$BASH_IT" + local md5_orig md5_bak + cd "${BASH_IT?}" touch "$HOME/$BASH_IT_CONFIG_FILE" echo "test file content" > "$HOME/$BASH_IT_CONFIG_FILE" - local md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') ./install.sh --silent assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" - local md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') + md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') assert_equal "$md5_orig" "$md5_bak" } diff --git a/test/install/uninstall.bats b/test/install/uninstall.bats index ab71a775f7..849e01d2d6 100644 --- a/test/install/uninstall.bats +++ b/test/install/uninstall.bats @@ -3,7 +3,7 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup() { - export HOME="$BATS_TEST_TMPDIR" + export HOME="${BATS_TEST_TMPDIR?}" } function local_setup_file() { @@ -20,15 +20,16 @@ function local_setup_file() { } @test "uninstall: verify that the uninstall script exists" { - assert_file_exist "$BASH_IT/uninstall.sh" + assert_file_exist "${BASH_IT?}/uninstall.sh" } @test "uninstall: run the uninstall script with an existing backup file" { - cd "$BASH_IT" + local md5_bak md5_conf + cd "${BASH_IT?}" echo "test file content for backup" > "$HOME/$BASH_IT_CONFIG_FILE.bak" echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE" - local md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') + md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') run ./uninstall.sh assert_success @@ -37,16 +38,17 @@ function local_setup_file() { assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" - local md5_conf=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + md5_conf=$(md5sum "$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" + local md5_orig md5_uninstall + cd "${BASH_IT?}" echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE" - local md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') run ./uninstall.sh assert_success @@ -55,7 +57,7 @@ function local_setup_file() { assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE" - local md5_uninstall=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}') + md5_uninstall=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}') assert_equal "$md5_orig" "$md5_uninstall" } From c893be359467eaadf28a3d8beabbe0b9a659a08b Mon Sep 17 00:00:00 2001 From: John D Pell Date: Mon, 31 Jan 2022 11:20:50 -0800 Subject: [PATCH 08/66] tests: add to `clean_files.txt` --- clean_files.txt | 7 +------ test/fixtures/bash_it/aliases/available/a.aliases.bash | 2 +- test/fixtures/bash_it/aliases/available/b.aliases.bash | 2 +- test/fixtures/bash_it/plugins/available/c.plugin.bash | 2 +- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index e52d5a9f29..82b07d7b0a 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -20,6 +20,7 @@ aliases/ docs/ hooks/ scripts/ +test/ # root files # @@ -134,12 +135,6 @@ plugins/available/todo.plugin.bash plugins/available/xterm.plugin.bash plugins/available/zoxide.plugin.bash -# tests -# -test/plugins/alias-completion.plugin.bats -test/run -test/test_helper.bash - # themes # themes/90210 diff --git a/test/fixtures/bash_it/aliases/available/a.aliases.bash b/test/fixtures/bash_it/aliases/available/a.aliases.bash index 9dede3f66c..7410181383 100644 --- a/test/fixtures/bash_it/aliases/available/a.aliases.bash +++ b/test/fixtures/bash_it/aliases/available/a.aliases.bash @@ -1,3 +1,3 @@ -#!/usr/bin/env bash +# shellcheck shell=bash alias test_alias="a" diff --git a/test/fixtures/bash_it/aliases/available/b.aliases.bash b/test/fixtures/bash_it/aliases/available/b.aliases.bash index 4f90a7ad66..f0321d491b 100644 --- a/test/fixtures/bash_it/aliases/available/b.aliases.bash +++ b/test/fixtures/bash_it/aliases/available/b.aliases.bash @@ -1,3 +1,3 @@ -#!/usr/bin/env bash +# shellcheck shell=bash alias test_alias="b" diff --git a/test/fixtures/bash_it/plugins/available/c.plugin.bash b/test/fixtures/bash_it/plugins/available/c.plugin.bash index 3d17ad7aeb..db52fd0f4d 100644 --- a/test/fixtures/bash_it/plugins/available/c.plugin.bash +++ b/test/fixtures/bash_it/plugins/available/c.plugin.bash @@ -1,3 +1,3 @@ -#!/usr/bin/env bash +# shellcheck shell=bash alias test_alias="c" From 93a05ccb64c95ea1e7e78d4014c3471d2b124132 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Wed, 12 Jan 2022 10:20:21 -0800 Subject: [PATCH 09/66] test_helper: make lib loading default Make library loading overridable default for all tests, up through "seach". --- test/test_helper.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_helper.bash b/test/test_helper.bash index bffb59edd6..7d62212630 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -66,7 +66,7 @@ function setup_libs() { } function local_setup_file() { - true + setup_libs "search" # overridable default } function local_setup() { From 810c52f91a97325813a29fb59de241a45faf3d34 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 4 Mar 2022 14:25:22 -0800 Subject: [PATCH 10/66] test: add new lib files to `setup_libs()` --- test/test_helper.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_helper.bash b/test/test_helper.bash index 7d62212630..9728801681 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -57,7 +57,7 @@ function common_setup_file() { function setup_libs() { local lib # Use a loop to allow convenient short-circuiting for some test files - for lib in "log" "utilities" "helpers" "search" "preexec" "colors" "command_duration"; do + for lib in "log" "utilities" "helpers" "search" "colors" "preview" "preexec" "history" "command_duration"; do load "${BASH_IT?}/lib/${lib}.bash" || return # shellcheck disable=SC2015 # short-circuit if we've reached the requested library [[ "${lib}" == "${1:-}" ]] && return 0 || true @@ -66,7 +66,7 @@ function setup_libs() { } function local_setup_file() { - setup_libs "search" # overridable default + setup_libs "colors" # overridable default } function local_setup() { From 31d1a007074927d18b541036d171bcfa448cec7b Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Tue, 8 Mar 2022 20:28:01 +0200 Subject: [PATCH 11/66] tests: Use git worktree correctly git worktree -d does not work on all versions of git worktree --- test/test_helper.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_helper.bash b/test/test_helper.bash index bffb59edd6..e665796576 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -41,7 +41,7 @@ function common_setup_file() { BASH_IT="${BATS_FILE_TMPDIR//\/\///}/.bash_it" # This sets up a local test fixture, i.e. a completely fresh and isolated Bash-it directory. This is done to avoid messing with your own Bash-it source directory. - git --git-dir="${MAIN_BASH_IT_GITDIR?}" worktree add -d "${BASH_IT}" + git --git-dir="${MAIN_BASH_IT_GITDIR?}" worktree add --detach "${BASH_IT}" load "${BASH_IT?}/vendor/github.com/erichs/composure/composure.sh" # support 'plumbing' metadata From 0ad2d659efd3fc87eb965289f22feabfc0946cba Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Tue, 15 Mar 2022 07:45:31 +0530 Subject: [PATCH 12/66] improve (lint): add completion/available/export.completion.bash entry --- clean_files.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/clean_files.txt b/clean_files.txt index 3c76421b68..ce72829f46 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -45,6 +45,7 @@ completion/available/dmidecode.completion.bash completion/available/docker-machine.completion.bash completion/available/docker.completion.bash completion/available/dotnet.completion.bash +completion/available/export.completion.bash completion/available/gcloud.completion.bash completion/available/gem.completion.bash completion/available/git.completion.bash From 9dd88df936604e5b2e503d3d52477714475b662f Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Tue, 15 Mar 2022 07:46:25 +0530 Subject: [PATCH 13/66] fix (completion): SC2016 in export.completion.bash --- completion/available/export.completion.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/completion/available/export.completion.bash b/completion/available/export.completion.bash index 42da3a97be..4898eb9a01 100644 --- a/completion/available/export.completion.bash +++ b/completion/available/export.completion.bash @@ -1 +1,3 @@ -complete -o nospace -S = -W '$(printenv | awk -F= "{print \$1}")' export +# shellcheck shell=bash + +complete -o nospace -S = -W "$(printenv | awk -F= "{print \$1}")" export From 8ddda1fe5c22e21d621fa0bb045805dacf4f46ef Mon Sep 17 00:00:00 2001 From: Matthew Adams Date: Fri, 15 Apr 2022 09:41:25 -0500 Subject: [PATCH 14/66] feat: support plain old node as strategy to get node version --- themes/base.theme.bash | 18 +++++++++++++++++- .../powerline-multiline.theme.bash | 2 ++ .../powerline-naked/powerline-naked.theme.bash | 2 ++ .../powerline-plain/powerline-plain.theme.bash | 2 ++ themes/powerline/powerline.theme.bash | 2 ++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 92a56e5ec0..6854d66a3a 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -74,6 +74,9 @@ SCM_NONE_CHAR='○' NVM_THEME_PROMPT_PREFIX=' |' NVM_THEME_PROMPT_SUFFIX='|' +NODE_THEME_PROMPT_PREFIX=' |' +NODE_THEME_PROMPT_SUFFIX='|' + RVM_THEME_PROMPT_PREFIX=' |' RVM_THEME_PROMPT_SUFFIX='|' @@ -399,8 +402,21 @@ function nvm_version_prompt() { fi } +function node_native_version_prompt() { + local node + if which -s node; then + node=$(node --version 2> /dev/null) + echo -ne "${NODE_THEME_PROMPT_PREFIX-}${node}${NODE_THEME_PROMPT_SUFFIX-}" + fi +} + function node_version_prompt() { - nvm_version_prompt + NODE_VERSION_STRATEGY="${NODE_VERSION_STRATEGY:-nvm}" + if [ "$NODE_VERSION_STRATEGY" == "nvm" ]; then + nvm_version_prompt + elif [ "$NODE_VERSION_STRATEGY" == "node" ]; then + node_native_version_prompt + fi } function rvm_version_prompt() { diff --git a/themes/powerline-multiline/powerline-multiline.theme.bash b/themes/powerline-multiline/powerline-multiline.theme.bash index 48a1243e03..9db10cb409 100644 --- a/themes/powerline-multiline/powerline-multiline.theme.bash +++ b/themes/powerline-multiline/powerline-multiline.theme.bash @@ -39,6 +39,8 @@ SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} NVM_THEME_PROMPT_PREFIX="" NVM_THEME_PROMPT_SUFFIX="" +NODE_THEME_PROMPT_PREFIX="" +NODE_THEME_PROMPT_SUFFIX="" NODE_CHAR=${POWERLINE_NODE_CHAR:="❲n❳ "} NODE_THEME_PROMPT_COLOR=${POWERLINE_NODE_COLOR:=22} diff --git a/themes/powerline-naked/powerline-naked.theme.bash b/themes/powerline-naked/powerline-naked.theme.bash index 2fb4137ef0..a5aaaa34a0 100644 --- a/themes/powerline-naked/powerline-naked.theme.bash +++ b/themes/powerline-naked/powerline-naked.theme.bash @@ -34,6 +34,8 @@ SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} NVM_THEME_PROMPT_PREFIX="" NVM_THEME_PROMPT_SUFFIX="" +NODE_THEME_PROMPT_PREFIX="" +NODE_THEME_PROMPT_SUFFIX="" NODE_CHAR=${POWERLINE_NODE_CHAR:="❲n❳ "} NODE_THEME_PROMPT_COLOR=${POWERLINE_NODE_COLOR:=22} diff --git a/themes/powerline-plain/powerline-plain.theme.bash b/themes/powerline-plain/powerline-plain.theme.bash index 6ff68e8fae..162fb5ca00 100644 --- a/themes/powerline-plain/powerline-plain.theme.bash +++ b/themes/powerline-plain/powerline-plain.theme.bash @@ -31,6 +31,8 @@ SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} NVM_THEME_PROMPT_PREFIX="" NVM_THEME_PROMPT_SUFFIX="" +NODE_THEME_PROMPT_PREFIX="" +NODE_THEME_PROMPT_SUFFIX="" NODE_CHAR=${POWERLINE_NODE_CHAR:="❲n❳ "} NODE_THEME_PROMPT_COLOR=${POWERLINE_NODE_COLOR:=22} diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index 49b397aa1d..2772a018cd 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -37,6 +37,8 @@ SCM_THEME_PROMPT_COLOR=${SCM_THEME_PROMPT_CLEAN_COLOR} NVM_THEME_PROMPT_PREFIX="" NVM_THEME_PROMPT_SUFFIX="" +NODE_THEME_PROMPT_PREFIX="" +NODE_THEME_PROMPT_SUFFIX="" NODE_CHAR=${POWERLINE_NODE_CHAR:="❲n❳ "} NODE_THEME_PROMPT_COLOR=${POWERLINE_NODE_COLOR:=22} From f7d21b5191b9c11741f6e1491e02bb47f486e304 Mon Sep 17 00:00:00 2001 From: Matthew Adams Date: Fri, 15 Apr 2022 09:57:05 -0500 Subject: [PATCH 15/66] chore: update docs --- docs/themes-list/powerline-base.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/themes-list/powerline-base.rst b/docs/themes-list/powerline-base.rst index faa1af3401..f38f940daa 100644 --- a/docs/themes-list/powerline-base.rst +++ b/docs/themes-list/powerline-base.rst @@ -81,7 +81,7 @@ The contents of the prompt can be "reordered", all the "segments" (every piece o * ``python_venv`` - Python virtual environment information (\ ``virtualenv``\ , ``venv`` and ``conda`` supported) * ``ruby`` - Current ruby version if using ``rvm`` -* ``node`` - Current node version (only ``nvm`` is supported) +* ``node`` - Current node version (``nvm`` is the default strategy; set ``NODE_VERSION_STRATEGY`` to ``node`` to use ``node --version``) * ``scm`` - Version control information, ``git`` * ``terraform`` - Current terraform workspace * ``user_info`` - Current user From 06b4b014cf97fc68f9cad7448b3511df5c4830c8 Mon Sep 17 00:00:00 2001 From: Matthew Adams Date: Thu, 19 May 2022 07:20:33 -0500 Subject: [PATCH 16/66] chore: use _command_exists based on MR feedback --- themes/base.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 6854d66a3a..2283915826 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -404,7 +404,7 @@ function nvm_version_prompt() { function node_native_version_prompt() { local node - if which -s node; then + if _command_exists node; then node=$(node --version 2> /dev/null) echo -ne "${NODE_THEME_PROMPT_PREFIX-}${node}${NODE_THEME_PROMPT_SUFFIX-}" fi From 5913d222c5e437bfcbd30b092909017476a727ab Mon Sep 17 00:00:00 2001 From: Matthew Adams Date: Thu, 19 May 2022 07:25:36 -0500 Subject: [PATCH 17/66] chore: add log stmt based on MR feedback --- themes/base.theme.bash | 3 +++ 1 file changed, 3 insertions(+) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 2283915826..e25014f86b 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -412,6 +412,9 @@ function node_native_version_prompt() { function node_version_prompt() { NODE_VERSION_STRATEGY="${NODE_VERSION_STRATEGY:-nvm}" + + _log_debug "node: using version strategy '$NODE_VERSION_STRATEGY'" + if [ "$NODE_VERSION_STRATEGY" == "nvm" ]; then nvm_version_prompt elif [ "$NODE_VERSION_STRATEGY" == "node" ]; then From 58bae6f900ce81c4f8777a9265b149c21b265627 Mon Sep 17 00:00:00 2001 From: Darren Bishop Date: Mon, 28 Nov 2022 14:52:34 +0000 Subject: [PATCH 18/66] Fix call to liquidprompt function Missing leading underscore in `_lp_escape` --- themes/liquidprompt/liquidprompt.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/liquidprompt/liquidprompt.theme.bash b/themes/liquidprompt/liquidprompt.theme.bash index 60e64210c4..c458ad4af5 100644 --- a/themes/liquidprompt/liquidprompt.theme.bash +++ b/themes/liquidprompt/liquidprompt.theme.bash @@ -39,7 +39,7 @@ _lp_git_branch() # Recent versions of Git support the --short option for symbolic-ref, but # not 1.7.9 (Ubuntu 12.04) if branch="$(\git symbolic-ref -q HEAD)"; then - _lp_escape "$(\git rev-parse --short=5 -q HEAD 2>/dev/null):${branch#refs/heads/}" + __lp_escape "$(\git rev-parse --short=5 -q HEAD 2>/dev/null):${branch#refs/heads/}" else # In detached head state, use commit instead # No escape needed From e2fbfa6c736a087bc5ad17e3dc7bc9e0e1f157e5 Mon Sep 17 00:00:00 2001 From: Darren Bishop Date: Mon, 28 Nov 2022 15:03:50 +0000 Subject: [PATCH 19/66] Update liquidprompt.theme.bash --- themes/liquidprompt/liquidprompt.theme.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/themes/liquidprompt/liquidprompt.theme.bash b/themes/liquidprompt/liquidprompt.theme.bash index c458ad4af5..ebf55969b0 100644 --- a/themes/liquidprompt/liquidprompt.theme.bash +++ b/themes/liquidprompt/liquidprompt.theme.bash @@ -40,10 +40,11 @@ _lp_git_branch() # not 1.7.9 (Ubuntu 12.04) if branch="$(\git symbolic-ref -q HEAD)"; then __lp_escape "$(\git rev-parse --short=5 -q HEAD 2>/dev/null):${branch#refs/heads/}" + lp_vcs_branch="$ret" else # In detached head state, use commit instead # No escape needed - \git rev-parse --short -q HEAD 2>/dev/null + lp_vcs_branch="$(\git rev-parse --short -q HEAD 2>/dev/null)" fi } From 7724fcab6b16c63500b2748de7ba2d961405a648 Mon Sep 17 00:00:00 2001 From: Darren Bishop Date: Tue, 29 Nov 2022 08:56:31 +0000 Subject: [PATCH 20/66] Update liquidprompt.theme.bash Added `ret` to local declarations as per provided liquidprompt change notes --- themes/liquidprompt/liquidprompt.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/liquidprompt/liquidprompt.theme.bash b/themes/liquidprompt/liquidprompt.theme.bash index ebf55969b0..3e5ff013d8 100644 --- a/themes/liquidprompt/liquidprompt.theme.bash +++ b/themes/liquidprompt/liquidprompt.theme.bash @@ -35,7 +35,7 @@ _lp_git_branch() \git rev-parse --is-inside-work-tree >/dev/null 2>&1 || return - local branch + local branch ret # Recent versions of Git support the --short option for symbolic-ref, but # not 1.7.9 (Ubuntu 12.04) if branch="$(\git symbolic-ref -q HEAD)"; then From 5e92af959abcd9bec98d7df49026ba7a2c16864d Mon Sep 17 00:00:00 2001 From: Darren Bishop Date: Tue, 29 Nov 2022 11:28:21 +0000 Subject: [PATCH 21/66] Attempt to no break existing installs --- themes/liquidprompt/liquidprompt.theme.bash | 22 +++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/themes/liquidprompt/liquidprompt.theme.bash b/themes/liquidprompt/liquidprompt.theme.bash index 3e5ff013d8..9631cab716 100644 --- a/themes/liquidprompt/liquidprompt.theme.bash +++ b/themes/liquidprompt/liquidprompt.theme.bash @@ -21,7 +21,7 @@ export LP_BATTERY_THRESHOLD=${LP_BATTERY_THRESHOLD:-75} export LP_LOAD_THRESHOLD=${LP_LOAD_THRESHOLD:-60} export LP_TEMP_THRESHOLD=${LP_TEMP_THRESHOLD:-80} - +unset _lp_legacy _lp_escape __lp_escape source "$targetdir/liquidprompt" prompt() { true; } export PS2=" ┃ " @@ -29,23 +29,37 @@ export LP_PS1_PREFIX="┌─" export LP_PS1_POSTFIX="\n└▪ " export LP_ENABLE_RUNTIME=0 +_lp_legacy() +{ + type -t _lp_escape &> /dev/null +} + +_lp_legacy && __lp_escape() +{ + ret="$(_lp_escape "$@")" +} + _lp_git_branch() { (( LP_ENABLE_GIT )) || return \git rev-parse --is-inside-work-tree >/dev/null 2>&1 || return - local branch ret + local commit branch ret + + commit="$(\git rev-parse --short -q HEAD 2>/dev/null)" + # Recent versions of Git support the --short option for symbolic-ref, but # not 1.7.9 (Ubuntu 12.04) if branch="$(\git symbolic-ref -q HEAD)"; then - __lp_escape "$(\git rev-parse --short=5 -q HEAD 2>/dev/null):${branch#refs/heads/}" + __lp_escape "$commit:${branch#refs/heads/}" lp_vcs_branch="$ret" else # In detached head state, use commit instead # No escape needed - lp_vcs_branch="$(\git rev-parse --short -q HEAD 2>/dev/null)" + lp_vcs_branch="$commit" fi + _lp_legacy && echo $lp_vcs_branch || return 0 } _lp_time() { From d7b6cff2c1d4beedef7340f6e295d786a6635d20 Mon Sep 17 00:00:00 2001 From: Darren Bishop Date: Tue, 29 Nov 2022 11:54:24 +0000 Subject: [PATCH 22/66] Removed trailing whitespace on line 51 --- themes/liquidprompt/liquidprompt.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/liquidprompt/liquidprompt.theme.bash b/themes/liquidprompt/liquidprompt.theme.bash index 9631cab716..17458fd5f1 100644 --- a/themes/liquidprompt/liquidprompt.theme.bash +++ b/themes/liquidprompt/liquidprompt.theme.bash @@ -48,7 +48,7 @@ _lp_git_branch() local commit branch ret commit="$(\git rev-parse --short -q HEAD 2>/dev/null)" - + # Recent versions of Git support the --short option for symbolic-ref, but # not 1.7.9 (Ubuntu 12.04) if branch="$(\git symbolic-ref -q HEAD)"; then From 602acc711a4deef20455b8358132ebc447f3d333 Mon Sep 17 00:00:00 2001 From: Roy Attias Date: Fri, 2 Dec 2022 21:28:14 +0200 Subject: [PATCH 23/66] aliases: git: Modernize get default branch function --- aliases/available/git.aliases.bash | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 535665b14d..9b71859948 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -200,9 +200,5 @@ function gdv() { } function get_default_branch() { - if git branch | grep -q '^. main\s*$'; then - echo main - else - echo master - fi + git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@' } From 54cdf3a60aa0540cf7809f6d8a953cf428d521b2 Mon Sep 17 00:00:00 2001 From: Roy Attias Date: Fri, 2 Dec 2022 21:24:34 +0200 Subject: [PATCH 24/66] aliases: git: Modernize 'gpf' and make it use --force-with-lease --- aliases/available/git.aliases.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 9b71859948..aa106b572b 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -103,7 +103,8 @@ alias gpatch='git format-patch -1' # push alias gp='git push' alias gpd='git push --delete' -alias gpf='git push --force' +alias gpf='git push --force-with-lease' +alias gpff='git push --force' alias gpo='git push origin HEAD' alias gpom='git push origin $(get_default_branch)' alias gpu='git push --set-upstream' From d9c339cf2956e24e5b3e67696c812dcdcd8ac07f Mon Sep 17 00:00:00 2001 From: Roy Attias Date: Sun, 4 Dec 2022 17:35:44 +0200 Subject: [PATCH 25/66] aliases: git: Don't use sed for extracting branch name --- aliases/available/git.aliases.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index aa106b572b..11ea2518d1 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -201,5 +201,6 @@ function gdv() { } function get_default_branch() { - git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@' + branch=$(git symbolic-ref refs/remotes/origin/HEAD) + ${branch#refs/remotes/origin/} } From 0137211d87c7d254726cd4354d694445fae7a87b Mon Sep 17 00:00:00 2001 From: Bruce <971697+tomaytotomato@users.noreply.github.com> Date: Sat, 4 Feb 2023 13:58:53 +0000 Subject: [PATCH 26/66] Add more Maven aliases Aliases for testing only, skipping tests on Package and Compile lifecycles. Also added aliases to start stop Spring Boot, Quarkus, Micronaut and Jetty server --- aliases/available/maven.aliases.bash | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/aliases/available/maven.aliases.bash b/aliases/available/maven.aliases.bash index 737826eb47..96cc620232 100644 --- a/aliases/available/maven.aliases.bash +++ b/aliases/available/maven.aliases.bash @@ -3,8 +3,13 @@ about-alias 'maven abbreviations' alias mci='mvn clean install' alias mi='mvn install' +alias mc='mvn clean' +alias mcc='mvn clean compile' alias mcp='mvn clean package' +alias mcpnt='mvn clean package -DskipTests=true' alias mp='mvn package' +alias mpnt='mvn package =DskipTests=true' +alias mct='mvn clean test' alias mrprep='mvn release:prepare' alias mrperf='mvn release:perform' alias mrrb='mvn release:rollback' @@ -12,3 +17,10 @@ alias mdep='mvn dependency:tree' alias mpom='mvn help:effective-pom' alias mcisk='mci -Dmaven.test.skip=true' alias mcpsk='mcp -Dmaven.test.skip=true' + +# Maven service plugin aliases +alias springrun='mvn spring-boot:run' +alias springstop='mvn spring-boot:stop' +alias jettyrun='mvn jetty:run' +alias quarkrun='mvn quarkus:dev' +alias microrun='mvn mn:run' From b0c38bb42e412ce341ad976ebe12ec71d993329a Mon Sep 17 00:00:00 2001 From: Bruce <971697+tomaytotomato@users.noreply.github.com> Date: Sat, 4 Feb 2023 20:42:19 +0000 Subject: [PATCH 27/66] Typo fix and rename maven service plugin aliases to be more friendly --- aliases/available/maven.aliases.bash | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/aliases/available/maven.aliases.bash b/aliases/available/maven.aliases.bash index 96cc620232..21bc99059d 100644 --- a/aliases/available/maven.aliases.bash +++ b/aliases/available/maven.aliases.bash @@ -8,7 +8,7 @@ alias mcc='mvn clean compile' alias mcp='mvn clean package' alias mcpnt='mvn clean package -DskipTests=true' alias mp='mvn package' -alias mpnt='mvn package =DskipTests=true' +alias mpnt='mvn package -DskipTests=true' alias mct='mvn clean test' alias mrprep='mvn release:prepare' alias mrperf='mvn release:perform' @@ -19,8 +19,7 @@ alias mcisk='mci -Dmaven.test.skip=true' alias mcpsk='mcp -Dmaven.test.skip=true' # Maven service plugin aliases -alias springrun='mvn spring-boot:run' -alias springstop='mvn spring-boot:stop' -alias jettyrun='mvn jetty:run' -alias quarkrun='mvn quarkus:dev' -alias microrun='mvn mn:run' +alias mspring='mvn spring-boot:run' +alias mjetty='mvn jetty:run' +alias mquark='mvn quarkus:dev' +alias mmicro='mvn mn:run' From 76e2c779150c1c08aa8af94acc0dfac6fb74f14c Mon Sep 17 00:00:00 2001 From: Bruce <971697+tomaytotomato@users.noreply.github.com> Date: Sat, 4 Feb 2023 20:45:22 +0000 Subject: [PATCH 28/66] Reordered aliases to be more friendly --- aliases/available/maven.aliases.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aliases/available/maven.aliases.bash b/aliases/available/maven.aliases.bash index 21bc99059d..2746da2c95 100644 --- a/aliases/available/maven.aliases.bash +++ b/aliases/available/maven.aliases.bash @@ -4,12 +4,12 @@ about-alias 'maven abbreviations' alias mci='mvn clean install' alias mi='mvn install' alias mc='mvn clean' +alias mct='mvn clean test' alias mcc='mvn clean compile' +alias mccnt='mvn clean compile -DskipTests=true' +alias mp='mvn package' alias mcp='mvn clean package' alias mcpnt='mvn clean package -DskipTests=true' -alias mp='mvn package' -alias mpnt='mvn package -DskipTests=true' -alias mct='mvn clean test' alias mrprep='mvn release:prepare' alias mrperf='mvn release:perform' alias mrrb='mvn release:rollback' From b62e6141a28839ef1842ef1740650066c9b64e9b Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Sat, 7 May 2022 00:14:58 +0530 Subject: [PATCH 29/66] feature (plugins): add url manipulation plugin --- plugins/available/url.plugin.bash | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 plugins/available/url.plugin.bash diff --git a/plugins/available/url.plugin.bash b/plugins/available/url.plugin.bash new file mode 100644 index 0000000000..bb4248f8e9 --- /dev/null +++ b/plugins/available/url.plugin.bash @@ -0,0 +1,44 @@ +# shellcheck shell=bash +cite about-plugin +about-plugin 'Basic url handling and manipulation functions' + +function slugify() { + about 'takes the text and transform to slug url, also supports formats like (html,link,rst,md)' + group 'url' + param "1: Text to transform (optional)" + param "2: Output format (html,rst,link,md). Omit or pass any text to return only output" + + local TXT=$1 + local OUTPUT=$2 + local SLUG + + if [[ -z $TXT ]]; then + read -rp "Enter the valid string: " TXT + fi + + # Pass 1 - Clean the url + SLUG=$(echo -n "$TXT" | tr -cd ' [:alnum:]._-' | tr -s ' ') + + # Pass 2 - Transformation + SLUG=$(echo -n "$SLUG" | tr '[:upper:]' '[:lower:]' | tr ' ' '-') + + case "$OUTPUT" in + html | htm) + echo "$TXT" + ;; + href | link) + echo "#$SLUG" + ;; + md) + echo "[$TXT](#$SLUG)" + ;; + rst) + echo "\`$TXT <#$SLUG>\`_" + ;; + + *) + echo "$SLUG" + ;; + esac + +} From 324eba4b83964440f7db72b0fdef9c4ec33c010e Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Sat, 7 May 2022 00:15:23 +0530 Subject: [PATCH 30/66] improve (lint): add plugins/available/url.plugin.bash --- clean_files.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/clean_files.txt b/clean_files.txt index 758e3b80a7..f8dae5aecf 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -134,6 +134,7 @@ plugins/available/rbenv.plugin.bash plugins/available/ruby.plugin.bash plugins/available/textmate.plugin.bash plugins/available/todo.plugin.bash +plugins/available/url.plugin.bash plugins/available/xterm.plugin.bash plugins/available/zoxide.plugin.bash From 0805de548f1340fbb59a4fe66fe850f74328c176 Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Sat, 7 May 2022 00:18:05 +0530 Subject: [PATCH 31/66] improve (plugins): add credits in url.plugin --- plugins/available/url.plugin.bash | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/available/url.plugin.bash b/plugins/available/url.plugin.bash index bb4248f8e9..72a41bfd3a 100644 --- a/plugins/available/url.plugin.bash +++ b/plugins/available/url.plugin.bash @@ -17,6 +17,7 @@ function slugify() { fi # Pass 1 - Clean the url + # Credits: https://stackoverflow.com/a/20007549/10362396 SLUG=$(echo -n "$TXT" | tr -cd ' [:alnum:]._-' | tr -s ' ') # Pass 2 - Transformation From cb44790e61dbdb62b0fabe50e65edd5447a4c62c Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Mon, 17 Apr 2023 16:48:59 +0300 Subject: [PATCH 32/66] Add a --help option --- plugins/available/gif.plugin.bash | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/available/gif.plugin.bash b/plugins/available/gif.plugin.bash index a04ff5c7d1..21dcc139a5 100644 --- a/plugins/available/gif.plugin.bash +++ b/plugins/available/gif.plugin.bash @@ -64,7 +64,7 @@ function v2gif() { fi # Parse the options - args=$("$getopt" -l "alert:" -l "lossy:" -l "width:" -l del,delete -l high -l tag -l "fps:" -l webm -o "a:l:w:f:dhmt" -- "$@") || { + args=$("$getopt" -l "alert:" -l "lossy:" -l "width:" -l del,delete -l high -l help -l tag -l "fps:" -l webm -o "a:l:w:f:dhmt" -- "$@") || { echo 'Terminating...' >&2 return 2 } @@ -82,6 +82,7 @@ function v2gif() { local fps="" local make_webm="" local alert=5000 + local printhelp="" while [[ $# -ge 1 ]]; do case "$1" in --) @@ -94,6 +95,11 @@ function v2gif() { opt_del_after="true" shift ;; + --help) + # Print Help + printhelp="true" + shift + ;; -h | --high) #High Quality, use gifski gifski="$(type -p gifski)" @@ -141,7 +147,7 @@ function v2gif() { esac done - if [[ -z "$*" ]]; then + if [[ -z "$*" || "$printhelp" ]]; then echo "$(tput setaf 1)No input files given. Example: v2gif file [file...] [-w ] [-l ] $(tput sgr 0)" echo "-d/--del/--delete Delete original vid if done suceessfully (and file not over the size limit)" echo "-h/--high High Quality - use Gifski instead of gifsicle" From 33342129449b549a0087c5e795d6dc271dd2ead8 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Mon, 17 Apr 2023 20:05:48 +0300 Subject: [PATCH 33/66] Fix commandline options for the current versions of gifski and gifsicle --- plugins/available/gif.plugin.bash | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/plugins/available/gif.plugin.bash b/plugins/available/gif.plugin.bash index 21dcc139a5..7cca37d4d2 100644 --- a/plugins/available/gif.plugin.bash +++ b/plugins/available/gif.plugin.bash @@ -72,9 +72,9 @@ function v2gif() { eval set -- "$args" local use_gifski="" local opt_del_after="" - local maxsize="" - local lossiness="" - local maxwidthski="" + local maxsize=() + local lossiness=() + local maxwidthski=() local giftagopt="" local giftag="" local defaultfps=10 @@ -112,8 +112,8 @@ function v2gif() { shift ;; -w | --width) - maxsize="-vf scale=$2:-1" - maxwidthski="-W $2" + maxsize=(-vf "scale=$2:-1") + maxwidthski=(-W "$2") giftag="${giftag}-w$2" shift 2 ;; @@ -124,7 +124,7 @@ function v2gif() { ;; -l | --lossy) # Use giflossy parameter - lossiness="--lossy=$2" + lossiness=("--lossy=$2") giftag="${giftag}-l$2" shift 2 ;; @@ -170,7 +170,7 @@ function v2gif() { local del_after=$opt_del_after if [[ -n "$make_webm" ]]; then - $ffmpeg -loglevel panic -i "$file" \ + $ffmpeg -loglevel warning -i "$file" \ -c:v libvpx -crf 4 -threads 0 -an -b:v 2M -auto-alt-ref 0 \ -quality best -loop 0 "${file%.*}.webm" || return 2 fi @@ -190,12 +190,12 @@ function v2gif() { if [[ "$use_gifski" = "true" ]]; then # I trust @pornel to do his own resizing optimization choices - $ffmpeg -loglevel panic -i "$file" -r "$fps" -vcodec png v2gif-tmp-%05d.png \ - && $gifski v2gif-tmp-*.png "$maxwidthski" --fps "$(printf "%.0f" "$fps")" -o "$output_file" || return 2 + $ffmpeg -loglevel warning -i "$file" -r "$fps" -vcodec png v2gif-tmp-%05d.png \ + && $gifski "${maxwidthski[@]}" --fps "$(printf "%.0f" "$fps")" -o "$output_file" v2gif-tmp-*.png || return 2 else - $ffmpeg -loglevel panic -i "$file" "$maxsize" -r "$fps" -vcodec png v2gif-tmp-%05d.png \ + $ffmpeg -loglevel warning -i "$file" "${maxsize[@]}" -r "$fps" -vcodec png v2gif-tmp-%05d.png \ && $convert +dither -layers Optimize v2gif-tmp-*.png GIF:- \ - | $gifsicle "$lossiness" --no-warnings --colors 256 --delay="$(echo "100/$fps" | bc)" --loop --optimize=3 --multifile - > "$output_file" || return 2 + | $gifsicle "${lossiness[@]}" --no-warnings --colors 256 --delay="$(echo "100/$fps" | bc)" --loop --optimize=3 --multifile - > "$output_file" || return 2 fi rm v2gif-tmp-*.png @@ -305,7 +305,7 @@ function any2webm() { echo "$(tput setaf 2)Creating '$output_file' ...$(tput sgr 0)" - $ffmpeg -loglevel panic -i "$file" \ + $ffmpeg -loglevel warning -i "$file" \ -c:v libvpx -crf 4 -threads 0 -an -b:v "$bandwidth" -auto-alt-ref 0 \ -quality best "$fps" "$size" -loop 0 -pix_fmt yuva420p "$output_file" || return 2 From 8eb90f7ac1ccdcdd77b28df3d09a3dca063b0135 Mon Sep 17 00:00:00 2001 From: Brian Phillips <28457+brianphillips@users.noreply.github.com> Date: Tue, 30 Aug 2022 16:48:54 -0500 Subject: [PATCH 34/66] Fix loading of nvm for brew-installed nvm This reverts to the original (working) version from 2017. During the most recent refactor to use the `_bash_it_homebrew_check` helper method, it was overlooked that `${BASH_IT_HOMEBREW_PREFIX}/nvm.sh` is not the equivalent to `$(brew --prefix nvm)/nvm.sh` since `BASH_IT_HOMEBREW_PREFIX` is set from `brew --prefix` instead of `brew --prefix nvm`. --- plugins/available/nvm.plugin.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/available/nvm.plugin.bash b/plugins/available/nvm.plugin.bash index 0e6da5d8cf..3966cdf24a 100644 --- a/plugins/available/nvm.plugin.bash +++ b/plugins/available/nvm.plugin.bash @@ -10,9 +10,9 @@ about-plugin 'node version manager configuration' export NVM_DIR="${NVM_DIR:-$HOME/.nvm}" # This loads nvm -if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" ]] +if _bash_it_homebrew_check && [[ -s "$(brew --prefix nvm)/nvm.sh" ]] then - source "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" + source "$(brew --prefix nvm)/nvm.sh" else [[ -s "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh" fi From 6661159b865249b6e15b2e0dc21a057f728f0b08 Mon Sep 17 00:00:00 2001 From: Brian Phillips <28457+brianphillips@users.noreply.github.com> Date: Fri, 9 Jun 2023 11:34:26 -0500 Subject: [PATCH 35/66] attempt to be more efficient when checking for brew-managed NVM install --- plugins/available/nvm.plugin.bash | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/available/nvm.plugin.bash b/plugins/available/nvm.plugin.bash index 3966cdf24a..7e123fc03f 100644 --- a/plugins/available/nvm.plugin.bash +++ b/plugins/available/nvm.plugin.bash @@ -9,8 +9,16 @@ cite about-plugin about-plugin 'node version manager configuration' export NVM_DIR="${NVM_DIR:-$HOME/.nvm}" + +# first check if NVM is managed by brew +NVM_BREW_PREFIX="" +if _bash_it_homebrew_check +then + NVM_BREW_PREFIX=$(brew --prefix nvm 2>/dev/null) +fi + # This loads nvm -if _bash_it_homebrew_check && [[ -s "$(brew --prefix nvm)/nvm.sh" ]] +if [[ -n "$NVM_BREW_PREFIX" && -s "${NVM_BREW_PREFIX}/nvm.sh" ]] then source "$(brew --prefix nvm)/nvm.sh" else From c5fdefece65ef716801201dfe936fd54e5296527 Mon Sep 17 00:00:00 2001 From: Brian Phillips <28457+brianphillips@users.noreply.github.com> Date: Mon, 7 Aug 2023 15:04:47 -0500 Subject: [PATCH 36/66] reuse variable instead of invoking brew again --- 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 7e123fc03f..4dc4c6d630 100644 --- a/plugins/available/nvm.plugin.bash +++ b/plugins/available/nvm.plugin.bash @@ -20,7 +20,7 @@ fi # This loads nvm if [[ -n "$NVM_BREW_PREFIX" && -s "${NVM_BREW_PREFIX}/nvm.sh" ]] then - source "$(brew --prefix nvm)/nvm.sh" + source "${NVM_BREW_PREFIX}/nvm.sh" else [[ -s "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh" fi From 5690939f058bc9328d6cbc18968d50751baca48f Mon Sep 17 00:00:00 2001 From: Peter Bittner Date: Sat, 30 Sep 2023 18:41:13 +0200 Subject: [PATCH 37/66] Add git alias `gshn` (`git show --name-only`) Adds a short Git alias for `git show --name-only`, which list the files affected by the changes only (instead of the full diff). --- aliases/available/git.aliases.bash | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 5572c9322c..1c34f1d8bb 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -152,6 +152,8 @@ alias gsl='git shortlog -sn' # show alias gsh='git show' +alias gshn='git show --name-only' +alias gshns='git show --name-status' # svn alias gsd='git svn dcommit' From db3eb76645218c5e078ebc5b4ba5d8d31be02a01 Mon Sep 17 00:00:00 2001 From: Peter Bittner Date: Sun, 1 Oct 2023 15:09:59 +0200 Subject: [PATCH 38/66] Add more aliases for `git merge` and `git rebase` --- aliases/available/git.aliases.bash | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 5572c9322c..3227cd2d5a 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -97,6 +97,9 @@ fi # merge alias gm='git merge' +alias gma='git merge --abort' +alias gmc='git merge --continue' +alias gms='git merge --squash' # mv alias gmv='git mv' @@ -132,7 +135,9 @@ alias grm='git rm' # rebase alias grb='git rebase' +alias grba='git rebase --abort' alias grbc='git rebase --continue' +alias grbi='git rebase --interactive' alias grm='git rebase $(get_default_branch)' alias grmi='git rebase $(get_default_branch) -i' alias grma='GIT_SEQUENCE_EDITOR=: git rebase $(get_default_branch) -i --autosquash' From 0e006bb4d75c52e046f64bcb298fd0f998e2f88c Mon Sep 17 00:00:00 2001 From: Peter Bittner Date: Sun, 1 Oct 2023 09:36:04 +0200 Subject: [PATCH 39/66] Add alias for `git reset --hard` and `grh` like OMZ --- aliases/available/git.aliases.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 5572c9322c..5280237f6c 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -139,7 +139,9 @@ alias grma='GIT_SEQUENCE_EDITOR=: git rebase $(get_default_branch) -i --autosqu alias gprom='git fetch origin $(get_default_branch) && git rebase origin/$(get_default_branch) && git update-ref refs/heads/$(get_default_branch) origin/$(get_default_branch)' # Rebase with latest remote # reset -alias gus='git reset HEAD' +alias gus='git reset HEAD' # read as: 'git unstage' +alias grh='git reset' # equivalent to: git reset HEAD +alias grh!='git reset --hard' alias gpristine='git reset --hard && git clean -dfx' # status From 160efd2e4819240064a90ed04b6a206b2add2bb6 Mon Sep 17 00:00:00 2001 From: Peter Bittner Date: Thu, 28 Sep 2023 17:42:38 +0200 Subject: [PATCH 40/66] Short aliases for `git commit --amend` (bang) With a bang (!) character we can make amending a commit intuitively dangerous. The idea is taken from Oh-My-Zsh, https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/git --- aliases/available/git.aliases.bash | 3 +++ 1 file changed, 3 insertions(+) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 5572c9322c..b88d0b089c 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -32,6 +32,9 @@ alias gca='git commit -v -a' alias gcaa='git commit -a --amend -C HEAD' # Add uncommitted and unstaged changes to the last commit alias gcam='git commit -v -am' alias gcamd='git commit --amend' +alias gc!='git commit -v --amend' +alias gca!='git commit -v -a --amend' +alias gcn!='git commit -v --amend --no-edit' alias gcm='git commit -v -m' alias gci='git commit --interactive' alias gcsam='git commit -S -am' From 0f743f28dffff19b0f4194b49c30b5fa7899f5ca Mon Sep 17 00:00:00 2001 From: Peter Bittner Date: Sun, 1 Oct 2023 14:29:50 +0200 Subject: [PATCH 41/66] Add alias for `git pull --prune` --- aliases/available/git.aliases.bash | 1 + 1 file changed, 1 insertion(+) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 5572c9322c..6295c444c6 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -117,6 +117,7 @@ alias gpuoc='git push --set-upstream origin $(git symbolic-ref --short HEAD)' # pull alias gl='git pull' +alias glp='git pull --prune' alias glum='git pull upstream $(get_default_branch)' alias gpl='git pull' alias gpp='git pull && git push' From 6d4d1752fc99bcc1bf6023702282bb7f20850381 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Sun, 5 Nov 2023 02:25:17 -0800 Subject: [PATCH 42/66] Clean `aliases.completion.bash` --- clean_files.txt | 1 + completion/available/aliases.completion.bash | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 758e3b80a7..77805b3eb7 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -31,6 +31,7 @@ lint_clean_files.sh # completions # +completion/available/aliases.completion.bash completion/available/apm.completion.bash completion/available/awless.completion.bash completion/available/awscli.completion.bash diff --git a/completion/available/aliases.completion.bash b/completion/available/aliases.completion.bash index 3e45e960cf..a4b15959a8 100644 --- a/completion/available/aliases.completion.bash +++ b/completion/available/aliases.completion.bash @@ -20,7 +20,7 @@ function _bash-it-component-completion-callback-on-init-aliases() { completions=("${completions[@]##complete -* * -}") # strip all but last option plus trigger(s) completions=("${completions[@]#complete -}") # strip anything missed completions=("${completions[@]#? * }") # strip last option and arg, leaving only trigger(s) - completions=("${completions[@]#? }") # strip anything missed + completions=("${completions[@]#? }") # strip anything missed #TODO: this will fail on some completions... # create temporary file for wrapper functions and completions @@ -40,10 +40,10 @@ function _bash-it-component-completion-callback-on-init-aliases() { line="${line#alias -- }" line="${line#alias }" alias_name="${line%%=*}" - alias_defn="${line#*=\'}" # alias definition + alias_defn="${line#*=\'}" # alias definition alias_defn="${alias_defn%\'}" alias_cmd="${alias_defn%%[[:space:]]*}" # first word of alias - if [[ ${alias_defn} == ${alias_cmd} ]]; then + if [[ ${alias_defn} == "${alias_cmd}" ]]; then alias_args='' else alias_args="${alias_defn#*[[:space:]]}" # everything after first word @@ -89,7 +89,7 @@ function _bash-it-component-completion-callback-on-init-aliases() { prec_word=\${prec_word#* } fi (( COMP_CWORD += ${#alias_arg_words[@]} )) - COMP_WORDS=(\"$alias_cmd\" \"${alias_arg_words[@]}\" \"\${COMP_WORDS[@]:1}\") + COMP_WORDS=(\"$alias_cmd\" \"${alias_arg_words[*]}\" \"\${COMP_WORDS[@]:1}\") (( COMP_POINT -= \${#COMP_LINE} )) COMP_LINE=\${COMP_LINE/$alias_name/$alias_cmd $alias_args} (( COMP_POINT += \${#COMP_LINE} )) From 656a0235a2b5cc833750413bcf1de7b6ce240082 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Sun, 5 Nov 2023 03:36:58 -0800 Subject: [PATCH 43/66] Clean `clean.theme.bash` --- clean_files.txt | 1 + themes/clean/clean.theme.bash | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 758e3b80a7..a39c074021 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -159,6 +159,7 @@ themes/bobby-python themes/brainy themes/brunton themes/candy +themes/clean themes/easy themes/essential themes/githelpers.theme.bash diff --git a/themes/clean/clean.theme.bash b/themes/clean/clean.theme.bash index 0082d671a0..47a436b34d 100644 --- a/themes/clean/clean.theme.bash +++ b/themes/clean/clean.theme.bash @@ -1,19 +1,24 @@ +# shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. + # git theming -SCM_THEME_PROMPT_PREFIX="${bold_blue}(${yellow}" -SCM_THEME_PROMPT_SUFFIX="${bold_blue})${reset_color} " +SCM_THEME_PROMPT_PREFIX="${bold_blue?}(${yellow?}" +SCM_THEME_PROMPT_SUFFIX="${bold_blue?})${reset_color?} " SCM_THEME_PROMPT_CLEAN="" -SCM_THEME_PROMPT_DIRTY="${bold_red}✗" - +SCM_THEME_PROMPT_DIRTY="${bold_red?}✗" # LS colors, made with http://geoff.greer.fm/lscolors/ export LSCOLORS="Gxfxcxdxbxegedabagacad" export LS_COLORS='no=00:fi=00:di=01;34:ln=00;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=41;33;01:ex=00;32:*.cmd=00;32:*.exe=01;32:*.com=01;32:*.bat=01;32:*.btm=01;32:*.dll=01;32:*.tar=00;31:*.tbz=00;31:*.tgz=00;31:*.rpm=00;31:*.deb=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.lzma=00;31:*.zip=00;31:*.zoo=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.bz2=00;31:*.tb2=00;31:*.tz2=00;31:*.tbz2=00;31:*.avi=01;35:*.bmp=01;35:*.fli=01;35:*.gif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mng=01;35:*.mov=01;35:*.mpg=01;35:*.pcx=01;35:*.pbm=01;35:*.pgm=01;35:*.png=01;35:*.ppm=01;35:*.tga=01;35:*.tif=01;35:*.xbm=01;35:*.xpm=01;35:*.dl=01;35:*.gl=01;35:*.wmv=01;35:*.aiff=00;32:*.au=00;32:*.mid=00;32:*.mp3=00;32:*.ogg=00;32:*.voc=00;32:*.wav=00;32:' function prompt_command() { + if [ "$(whoami)" = root ]; then + no_color=${red?} + else + no_color=${white?} + fi - if [ "$(whoami)" = root ]; then no_color=$red; else no_color=$white; fi - - PS1="${no_color}\u${reset_color}:${blue}\W/${reset_color} $(scm_prompt_info)${normal}$ " + PS1="${no_color}\u${reset_color}:${blue?}\W/${reset_color} $(scm_prompt_info)${normal?}$ " } safe_append_prompt_command prompt_command From 937e50c77930f75d4baa80b2149da22c2c15909c Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Sun, 5 Nov 2023 03:42:27 -0800 Subject: [PATCH 44/66] Clean `elixr.theme.bash` --- clean_files.txt | 1 + themes/elixr/elixr.theme.bash | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 758e3b80a7..0aef425425 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -160,6 +160,7 @@ themes/brainy themes/brunton themes/candy themes/easy +themes/elixr themes/essential themes/githelpers.theme.bash themes/modern diff --git a/themes/elixr/elixr.theme.bash b/themes/elixr/elixr.theme.bash index 266abbad43..d266fae89d 100644 --- a/themes/elixr/elixr.theme.bash +++ b/themes/elixr/elixr.theme.bash @@ -1,15 +1,16 @@ -#!/usr/bin/env bash +# shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. -SCM_THEME_PROMPT_DIRTY=" ${red}✗" -SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓" -SCM_THEME_PROMPT_PREFIX=" ${green}| " -SCM_THEME_PROMPT_SUFFIX="${green} |" +SCM_THEME_PROMPT_DIRTY=" ${red?}✗" +SCM_THEME_PROMPT_CLEAN=" ${bold_green?}✓" +SCM_THEME_PROMPT_PREFIX=" ${green?}| " +SCM_THEME_PROMPT_SUFFIX="${green?} |" SCM_NONE_CHAR='◐ ' SCM_GIT_SHOW_MINIMAL_INFO=true -GIT_THEME_PROMPT_DIRTY=" ${red}✗" -GIT_THEME_PROMPT_CLEAN=" ${bold_green}✓" -GIT_THEME_PROMPT_PREFIX=" ${green}|" -GIT_THEME_PROMPT_SUFFIX="${green}|" +GIT_THEME_PROMPT_DIRTY=" ${red?}✗" +GIT_THEME_PROMPT_CLEAN=" ${bold_green?}✓" +GIT_THEME_PROMPT_PREFIX=" ${green?}|" +GIT_THEME_PROMPT_SUFFIX="${green?}|" RVM_THEME_PROMPT_PREFIX="|" RVM_THEME_PROMPT_SUFFIX=" d|" @@ -17,7 +18,7 @@ RVM_THEME_PROMPT_SUFFIX=" d|" BOLD="\[\e[1m\]" function prompt_command() { - PS1="\n${bold_cyan}$(scm_prompt_char_info)$(virtualenv_prompt) ${bold_cyan}\w :${reset_color}${normal}${BOLD} " + PS1="\n${bold_cyan?}$(scm_prompt_char_info)$(virtualenv_prompt) ${bold_cyan}\w :${reset_color?}${normal?}${BOLD} " } safe_append_prompt_command prompt_command From edec6480fd9ff859cdee25c5b25b223ceae929f3 Mon Sep 17 00:00:00 2001 From: Edwin Kofler Date: Sun, 5 Nov 2023 03:46:51 -0800 Subject: [PATCH 45/66] Tweaks to clean files scripts and file list --- clean_files.txt | 13 +------------ lint_clean_files.sh | 2 +- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 758e3b80a7..b8eeb17b77 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -19,6 +19,7 @@ aliases/ docs/ hooks/ +lib/ scripts/ # root files @@ -78,18 +79,6 @@ completion/available/vuejs.completion.bash completion/available/wpscan.completion.bash completion/available/yarn.completion.bash -# libraries -lib/appearance.bash -lib/colors.bash -lib/command_duration.bash -lib/helpers.bash -lib/history.bash -lib/log.bash -lib/preexec.bash -lib/preview.bash -lib/search.bash -lib/utilities.bash - # plugins # plugins/available/alias-completion.plugin.bash diff --git a/lint_clean_files.sh b/lint_clean_files.sh index cc2686042f..b341f4f46f 100755 --- a/lint_clean_files.sh +++ b/lint_clean_files.sh @@ -10,7 +10,7 @@ mapfile -t FILES < <( cat clean_files.txt \ | grep -E -v '^\s*$' \ | grep -E -v '^\s*#' \ - | xargs -n1 -I{} find "{}" -type f + | xargs -I{} find "{}" -type f ) # We clear the BASH_IT variable to help the shellcheck checker From d6efc5b7d4d1c1ab6f33522e17eff928c953d7e8 Mon Sep 17 00:00:00 2001 From: Pablo Palazon Date: Thu, 23 Nov 2023 17:01:51 +0100 Subject: [PATCH 46/66] Add pre-jgitflow function --- clean_files.txt | 1 + plugins/available/jgitflow.plugin.bash | 55 ++++++++++++++++---------- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 758e3b80a7..459572d532 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -115,6 +115,7 @@ plugins/available/history.plugin.bash plugins/available/hub.plugin.bash plugins/available/java.plugin.bash plugins/available/jekyll.plugin.bash +plugins/available/jgitflow.plugin.bash plugins/available/jump.plugin.bash plugins/available/latex.plugin.bash plugins/available/less-pretty-cat.plugin.bash diff --git a/plugins/available/jgitflow.plugin.bash b/plugins/available/jgitflow.plugin.bash index 83ee8a23f6..ff972f6221 100644 --- a/plugins/available/jgitflow.plugin.bash +++ b/plugins/available/jgitflow.plugin.bash @@ -1,47 +1,60 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'Maven jgitflow build helpers' +function pre-jgitflow { + about 'helper function for execute before jgitflow' + group 'jgitflow' +} + +function test-pre-jgitflow { + about 'helper function for starting a new hotfix' + group 'jgitflow' + + echo "Init pre-maven" && pre-jgitflow && echo "Finish pre-maven" +} + function hotfix-start { - about 'helper function for starting a new hotfix' - group 'jgitflow' + about 'helper function for starting a new hotfix' + group 'jgitflow' - mvn jgitflow:hotfix-start ${JGITFLOW_MVN_ARGUMENTS} + pre-jgitflow && mvn jgitflow:hotfix-start ${JGITFLOW_MVN_ARGUMENTS} } function hotfix-finish { - about 'helper function for finishing a hotfix' - group 'jgitflow' + about 'helper function for finishing a hotfix' + group 'jgitflow' - mvn jgitflow:hotfix-finish -Darguments="${JGITFLOW_MVN_ARGUMENTS}" && git push && git push origin master && git push --tags + pre-jgitflow && mvn jgitflow:hotfix-finish -Darguments="${JGITFLOW_MVN_ARGUMENTS}" && git push && git push origin master && git push --tags && mvn clean } function feature-start { - about 'helper function for starting a new feature' - group 'jgitflow' + about 'helper function for starting a new feature' + group 'jgitflow' - mvn jgitflow:feature-start ${JGITFLOW_MVN_ARGUMENTS} + pre-jgitflow && mvn jgitflow:feature-start ${JGITFLOW_MVN_ARGUMENTS} } function feature-finish { - about 'helper function for finishing a feature' - group 'jgitflow' + about 'helper function for finishing a feature' + group 'jgitflow' - mvn jgitflow:feature-finish ${JGITFLOW_MVN_ARGUMENTS} - echo -e '\033[32m----------------------------------------------------------------\033[0m' - echo -e '\033[32m===== REMEMBER TO CREATE A NEW RELEASE TO DEPLOY THIS FEATURE ====\033[0m' - echo -e '\033[32m----------------------------------------------------------------\033[0m' + pre-jgitflow && mvn jgitflow:feature-finish ${JGITFLOW_MVN_ARGUMENTS} && mvn clean + echo -e '\033[32m----------------------------------------------------------------\033[0m' + echo -e '\033[32m===== REMEMBER TO CREATE A NEW RELEASE TO DEPLOY THIS FEATURE ====\033[0m' + echo -e '\033[32m----------------------------------------------------------------\033[0m' } function release-start { - about 'helper function for starting a new release' - group 'jgitflow' + about 'helper function for starting a new release' + group 'jgitflow' - mvn jgitflow:release-start ${JGITFLOW_MVN_ARGUMENTS} + pre-jgitflow && mvn jgitflow:release-start ${JGITFLOW_MVN_ARGUMENTS} } function release-finish { - about 'helper function for finishing a release' - group 'jgitflow' + about 'helper function for finishing a release' + group 'jgitflow' - mvn jgitflow:release-finish -Darguments="${JGITFLOW_MVN_ARGUMENTS}" && git push && git push origin master && git push --tags + pre-jgitflow && mvn jgitflow:release-finish -Darguments="${JGITFLOW_MVN_ARGUMENTS}" && git push && git push origin master && git push --tags && mvn clean } From 87d3527789d78905cfc9b6d0acdcb3782e07d5da Mon Sep 17 00:00:00 2001 From: w453y Date: Sat, 2 Dec 2023 00:55:49 +0530 Subject: [PATCH 47/66] added new theme (lambda) --- clean_files.txt | 1 + themes/lambda/lambda.theme.bash | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 themes/lambda/lambda.theme.bash diff --git a/clean_files.txt b/clean_files.txt index 758e3b80a7..c12df79231 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -170,6 +170,7 @@ themes/pete themes/powerline themes/pure themes/purity +themes/lambda # vendor init files # diff --git a/themes/lambda/lambda.theme.bash b/themes/lambda/lambda.theme.bash new file mode 100644 index 0000000000..b3d6910c01 --- /dev/null +++ b/themes/lambda/lambda.theme.bash @@ -0,0 +1,30 @@ +function set_prompt { + local user_color="\[\033[1;31m\]" # bold red for username + local at_color="\[\033[1;37m\]" # bold white for @ symbol + local host_color="\[\033[1;31m\]" # bold red for hostname + local in_color="\[\033[1;37m\]" # bold white for "in" + local dir_color="\[\033[1;35m\]" # bold purple for current working directory + local git_color="\[\033[1;36m\]" # bold cyan for Git information + local time_color="\[\033[1;32m\]" # bold green for time taken + local reset_color="\[\033[0m\]" # reset color + local prompt_symbol_color="\[\033[1;31m\]" # bold red for the prompt symbol + + local end_time=$(date +%s%3N) # current time in milliseconds + local time_taken=$(( (end_time - start_time) )) # time in milliseconds + + PS1="${user_color}╭─\\u" # username + PS1+="${at_color}@${host_color}\\h" # @ symbol and hostname + PS1+="${in_color} in" # "in" between hostname and current directory + PS1+="${dir_color} \\w" # current working directory + + # Git information (status symbol) + PS1+=" ${git_color}$(__git_ps1 "[%s]")${reset_color}" + + if [ $time_taken -gt 0 ]; then + PS1+=" ${time_color}took ${time_taken}ms" # time taken in milliseconds + fi + + PS1+="\n${prompt_symbol_color}╰─λ${reset_color} " # red color for the prompt symbol, reset color after +} + +PROMPT_COMMAND='start_time=$(date +%s%3N); set_prompt' \ No newline at end of file From 6d77ba022512fc1eac5041bfa30c27a0dcdc17c3 Mon Sep 17 00:00:00 2001 From: Abdul Wasey <86080041+w453y@users.noreply.github.com> Date: Fri, 1 Dec 2023 20:16:11 +0000 Subject: [PATCH 48/66] Update clean_files.txt --- clean_files.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clean_files.txt b/clean_files.txt index c12df79231..ffa5dd08e5 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -162,6 +162,7 @@ themes/candy themes/easy themes/essential themes/githelpers.theme.bash +themes/lambda themes/modern themes/norbu themes/oh-my-posh @@ -170,7 +171,7 @@ themes/pete themes/powerline themes/pure themes/purity -themes/lambda + # vendor init files # From 178e24fd7102c1e948c3c88cee5664af50ae86db Mon Sep 17 00:00:00 2001 From: Abdul Wasey <86080041+w453y@users.noreply.github.com> Date: Fri, 1 Dec 2023 20:20:48 +0000 Subject: [PATCH 49/66] Update lambda.theme.bash --- themes/lambda/lambda.theme.bash | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/themes/lambda/lambda.theme.bash b/themes/lambda/lambda.theme.bash index b3d6910c01..8f3d5baf49 100644 --- a/themes/lambda/lambda.theme.bash +++ b/themes/lambda/lambda.theme.bash @@ -1,3 +1,6 @@ +#!/bin/bash +# shellcheck disable=SC1090,SC2034 + function set_prompt { local user_color="\[\033[1;31m\]" # bold red for username local at_color="\[\033[1;37m\]" # bold white for @ symbol @@ -27,4 +30,4 @@ function set_prompt { PS1+="\n${prompt_symbol_color}╰─λ${reset_color} " # red color for the prompt symbol, reset color after } -PROMPT_COMMAND='start_time=$(date +%s%3N); set_prompt' \ No newline at end of file +PROMPT_COMMAND='start_time=$(date +%s%3N); set_prompt' From 3bd701d15c74563285b586412eb834343ea107ae Mon Sep 17 00:00:00 2001 From: BarbUk Date: Thu, 8 Feb 2024 13:26:48 +0100 Subject: [PATCH 50/66] Fix clock_hand to display correct hour hand --- lib/command_duration.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/command_duration.bash b/lib/command_duration.bash index 2b5e1b4bda..08ca256cb6 100644 --- a/lib/command_duration.bash +++ b/lib/command_duration.bash @@ -26,7 +26,7 @@ function _dynamic_clock_icon { local clock_hand # clock hand value is between 90 and 9b in hexadecimal. # so between 144 and 155 in base 10. - printf -v clock_hand '%x' $(((${1:-${SECONDS}} % 12) + 144)) + printf -v clock_hand '%x' $((((${1:-${SECONDS}} -1 ) % 12) + 144)) printf -v 'COMMAND_DURATION_ICON' '%b' "\xf0\x9f\x95\x$clock_hand" } From c14e77eee03cc26d5b1dc9d14fa69cc736d6e5fc Mon Sep 17 00:00:00 2001 From: BarbUk Date: Thu, 8 Feb 2024 13:47:17 +0100 Subject: [PATCH 51/66] Lint --- lib/command_duration.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/command_duration.bash b/lib/command_duration.bash index 08ca256cb6..352ef0f01a 100644 --- a/lib/command_duration.bash +++ b/lib/command_duration.bash @@ -26,7 +26,7 @@ function _dynamic_clock_icon { local clock_hand # clock hand value is between 90 and 9b in hexadecimal. # so between 144 and 155 in base 10. - printf -v clock_hand '%x' $((((${1:-${SECONDS}} -1 ) % 12) + 144)) + printf -v clock_hand '%x' $((((${1:-${SECONDS}} - 1) % 12) + 144)) printf -v 'COMMAND_DURATION_ICON' '%b' "\xf0\x9f\x95\x$clock_hand" } From dc4979ca20a81fee36d2c2c79103560633565d50 Mon Sep 17 00:00:00 2001 From: gytisrepecka Date: Tue, 19 Mar 2024 22:59:45 +0200 Subject: [PATCH 52/66] Added new Inretio theme. --- clean_files.txt | 1 + themes/inretio/inretio.theme.bash | 99 +++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 themes/inretio/inretio.theme.bash diff --git a/clean_files.txt b/clean_files.txt index 758e3b80a7..0ba14ff020 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -170,6 +170,7 @@ themes/pete themes/powerline themes/pure themes/purity +themes/inretio # vendor init files # diff --git a/themes/inretio/inretio.theme.bash b/themes/inretio/inretio.theme.bash new file mode 100644 index 0000000000..ceac5a296b --- /dev/null +++ b/themes/inretio/inretio.theme.bash @@ -0,0 +1,99 @@ +#!/usr/bin/env bash + +# Inretio theme for Bash-it +# Contact: bashit@inretio.eu + +# Inspired by existing themes: +# - metal +# - bobby + +# virtualenv prompts +VIRTUALENV_CHAR=" ⓔ" +VIRTUALENV_THEME_PROMPT_PREFIX="" +VIRTUALENV_THEME_PROMPT_SUFFIX="" + +# SCM prompts +SCM_NONE_CHAR="" +SCM_GIT_CHAR="[±] " +SCM_GIT_BEHIND_CHAR="${red}↓${normal}" +SCM_GIT_AHEAD_CHAR="${bold_green}↑${normal}" +SCM_GIT_UNTRACKED_CHAR="⌀" +SCM_GIT_UNSTAGED_CHAR="${bold_yellow}•${normal}" +SCM_GIT_STAGED_CHAR="${bold_green}+${normal}" + +SCM_THEME_PROMPT_DIRTY="" +SCM_THEME_PROMPT_CLEAN="" +SCM_THEME_PROMPT_PREFIX="" +SCM_THEME_PROMPT_SUFFIX="" + +# Git status prompts +GIT_THEME_PROMPT_DIRTY=" ${red}✗${normal}" +GIT_THEME_PROMPT_CLEAN=" ${bold_green}✓${normal}" +GIT_THEME_PROMPT_PREFIX="" +GIT_THEME_PROMPT_SUFFIX="" + +# ICONS ======================================================================= + +icon_start="┌──" +icon_user=" 🐧 " +icon_host=" 💻 " +icon_directory=" 📂 " +icon_branch="🌵" +icon_end="└> " + +# extra spaces ensure legiblity in prompt + +# FUNCTIONS =================================================================== + +# Display virtual environment info +function _virtualenv_prompt { + VIRTUALENV_DETAILS="" + VIRTUALENV_CHAR="" + + # $VIRTUAL_ENV is set and is non-zero length + if [[ -n "$VIRTUAL_ENV" ]]; then + # Check if Python 3 exists + if command -v python3 >/dev/null 2>&1; then + VIRTUALENV_DETAILS="$($VIRTUAL_ENV/bin/python --version | sed 's,Python ,,') on [$(basename $VIRTUAL_ENV)]" + VIRTUALENV_CHAR=" 🐍" + else + VIRTUALENV_DETAILS="[$(basename $VIRTUAL_ENV)]" + VIRTUALENV_CHAR=" ⓔ" + fi + fi + + echo "$VIRTUALENV_CHAR $VIRTUALENV_DETAILS" +} + +# Rename tab +function tabname { + printf "\e]1;$1\a" +} + +# Rename window +function winname { + printf "\e]2;$1\a" +} + +_theme_clock() { + printf '[%s]' "$(clock_prompt)" + + if [ "${THEME_SHOW_CLOCK_CHAR}" == "true" ]; then + printf '%s' "$(clock_char) " + fi +} +THEME_SHOW_CLOCK_CHAR=${THEME_SHOW_CLOCK_CHAR:-"false"} +THEME_CLOCK_CHAR_COLOR=${THEME_CLOCK_CHAR_COLOR:-"$red"} +THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$normal"} +THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%Y-%m-%d %H:%M:%S"} + +# PROMPT OUTPUT =============================================================== + +# Displays the current prompt +function prompt_command() { + PS1="\n${icon_start}$(_theme_clock)${icon_user}${bold_green}\u${normal}${icon_host}${bold_cyan}\h${normal}${green}$(_virtualenv_prompt)${normal}${icon_directory}${bold_purple}\W${normal}\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on ${icon_branch} $(scm_prompt_info) \")${white}${normal}\n${icon_end}" + PS2="${icon_end}" +} + +# Runs prompt (this bypasses bash_it $PROMPT setting) +safe_append_prompt_command prompt_command From adb01ad8c28b9bd0e63ee10e2bcd8f0576f3c21a Mon Sep 17 00:00:00 2001 From: gytisrepecka Date: Wed, 20 Mar 2024 12:15:06 +0200 Subject: [PATCH 53/66] Added documentation for new Inretio theme. --- docs/themes-list/index.rst | 15 +++++++++++++++ docs/themes-list/inretio.rst | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 docs/themes-list/inretio.rst diff --git a/docs/themes-list/index.rst b/docs/themes-list/index.rst index 0275001b38..0196ba62ed 100644 --- a/docs/themes-list/index.rst +++ b/docs/themes-list/index.rst @@ -221,6 +221,21 @@ Envy ---- +Inretio +^^^^^^^ + + +.. image:: https://raw.githubusercontent.com/inretio/bash-it/gh-pages/docs/images/inretio-black.png + :target: https://raw.githubusercontent.com/inretio/bash-it/gh-pages/docs/images/inretio-black.png + :alt: Inretio theme in dark color scheme + + +.. image:: https://raw.githubusercontent.com/inretio/bash-it/gh-pages/docs/images/inretio-white.png + :target: https://raw.githubusercontent.com/inretio/bash-it/gh-pages/docs/images/inretio-white.png + :alt: Inretio theme in light color scheme + +---- + Iterate ^^^^^^^ diff --git a/docs/themes-list/inretio.rst b/docs/themes-list/inretio.rst new file mode 100644 index 0000000000..7850616ae5 --- /dev/null +++ b/docs/themes-list/inretio.rst @@ -0,0 +1,32 @@ +.. _inretio: + +Inretio Theme +========== + +Simple theme showing date and time, username and hostname, current folder, Git details and as a bonus - virtual environment along with Python version available in it. + +Inspired by existing themes: +- metal +- bobby + +Examples +-------- + +In Git-tracked folder: + +.. code-block:: bash + + ┌──[2024-03-20 12:05:07] 🐧 gytis 💻 gytis-legion 📂 bash-it on 🌵 theme-inretio ⌀1 ✗ + └> ls + aliases clean_files.txt custom hooks lib lint_clean_files.sh profiles template test_lib uninstall.sh + bash_it.sh completion docs install.sh LICENSE plugins scripts test themes vendor + + +In Python virtual environment: + +.. code-block:: bash + + ┌──[2024-03-20 12:07:32] 🐧 gytis 💻 gytis-legion 🐍 3.12.2 on [general] 📂 general + └> ls + bin include lib lib64 pyvenv.cfg share + From f486dc9f426c3c4e6d60faf19a62149bfbe8d1db Mon Sep 17 00:00:00 2001 From: gytisrepecka Date: Wed, 20 Mar 2024 13:07:22 +0200 Subject: [PATCH 54/66] Fix documentation: title underline too short. --- docs/themes-list/inretio.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/themes-list/inretio.rst b/docs/themes-list/inretio.rst index 7850616ae5..0e424a99f8 100644 --- a/docs/themes-list/inretio.rst +++ b/docs/themes-list/inretio.rst @@ -1,7 +1,7 @@ .. _inretio: Inretio Theme -========== +============= Simple theme showing date and time, username and hostname, current folder, Git details and as a bonus - virtual environment along with Python version available in it. From dcafe3ce70c24144f4daf408cfe078a751208ad6 Mon Sep 17 00:00:00 2001 From: gytisrepecka Date: Wed, 20 Mar 2024 13:09:48 +0200 Subject: [PATCH 55/66] Fix sorting in clean_files.txt list. --- clean_files.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clean_files.txt b/clean_files.txt index 0ba14ff020..c6c48d4589 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -162,6 +162,7 @@ themes/candy themes/easy themes/essential themes/githelpers.theme.bash +themes/inretio themes/modern themes/norbu themes/oh-my-posh @@ -170,7 +171,6 @@ themes/pete themes/powerline themes/pure themes/purity -themes/inretio # vendor init files # From c34f56e7cbffa68d893f8e25d1f83d693a929842 Mon Sep 17 00:00:00 2001 From: "Alexandre Nepomniachtchi (aka alexnav)" Date: Tue, 26 Mar 2024 17:58:21 +0100 Subject: [PATCH 56/66] (update) Add some new aliases for logginng --- aliases/available/git.aliases.bash | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index 5572c9322c..cd6e31cf71 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -3,6 +3,7 @@ about-alias 'common git abbreviations' alias g='git' alias get='git' +alias got='git ' # add alias ga='git add' @@ -79,6 +80,8 @@ alias ggup='git log --branches --not --remotes --no-walk --decorate --oneline' # alias gll='git log --graph --pretty=oneline --abbrev-commit' alias gnew='git log HEAD@{1}..HEAD@{0}' # Show commits since last pull, see http://blogs.atlassian.com/2014/10/advanced-git-aliases/ alias gwc='git whatchanged' +alias ghist='git log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short' # Use it to be fast and without color. +alias gprogress='git log --pretty=format:\"%C(yellow)%h %Cblue%ad %Creset%s%Cgreen [%cn] %Cred%d\" --decorate --date=short' #Usually use "git progress" in the file .gitconfig. The new alias from Git friends will be truly welcome. # ls-files alias gu='git ls-files . --exclude-standard --others' # Show untracked files @@ -129,6 +132,7 @@ alias grv='git remote -v' # rm alias grm='git rm' +alias grmc='git rm --cached' # Removes the file only from the Git repository, but not from the filesystem. This is useful to undo some of the changes you made to a file before you commit it. # rebase alias grb='git rebase' From e9facb2b229682ef67d4c5c9eb4c89cdb59b14c3 Mon Sep 17 00:00:00 2001 From: "Alexandre Nepomniachtchi (aka alexnav)" Date: Tue, 26 Mar 2024 18:28:55 +0100 Subject: [PATCH 57/66] (fix) log aliases for git. --- aliases/available/git.aliases.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index cd6e31cf71..71fc5178cf 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -80,8 +80,8 @@ alias ggup='git log --branches --not --remotes --no-walk --decorate --oneline' # alias gll='git log --graph --pretty=oneline --abbrev-commit' alias gnew='git log HEAD@{1}..HEAD@{0}' # Show commits since last pull, see http://blogs.atlassian.com/2014/10/advanced-git-aliases/ alias gwc='git whatchanged' -alias ghist='git log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short' # Use it to be fast and without color. -alias gprogress='git log --pretty=format:\"%C(yellow)%h %Cblue%ad %Creset%s%Cgreen [%cn] %Cred%d\" --decorate --date=short' #Usually use "git progress" in the file .gitconfig. The new alias from Git friends will be truly welcome. +alias ghist='git log --pretty=format:'\''%h %ad | %s%d [%an]'\'' --graph --date=short' # Use it to be fast and without color. +alias gprogress='git log --pretty=format:'\''%C(yellow)%h %Cblue%ad %Creset%s%Cgreen [%cn] %Cred%d'\'' --decorate --date=short' #Usually use "git progress" in the file .gitconfig. The new alias from Git friends will be truly welcome. # ls-files alias gu='git ls-files . --exclude-standard --others' # Show untracked files From 608b4399f341dab576e69084d429da6ab6f30b1f Mon Sep 17 00:00:00 2001 From: gytisrepecka Date: Thu, 28 Mar 2024 12:05:32 +0200 Subject: [PATCH 58/66] Fix theme file header as required by hooks/dot-bash.sh line 15. --- themes/inretio/inretio.theme.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/themes/inretio/inretio.theme.bash b/themes/inretio/inretio.theme.bash index ceac5a296b..58ac36ddfb 100644 --- a/themes/inretio/inretio.theme.bash +++ b/themes/inretio/inretio.theme.bash @@ -1,4 +1,5 @@ -#!/usr/bin/env bash +# shellcheck shell=bash +# shellcheck disable=SC2034 # Expected behavior for themes. # Inretio theme for Bash-it # Contact: bashit@inretio.eu From 1743bebca8038c24bd5ddc5ba0504b7c7dbbbcfc Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Fri, 21 Jun 2024 21:02:20 +0530 Subject: [PATCH 59/66] Support conda environement for bira theme --- themes/bira/bira.theme.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/themes/bira/bira.theme.bash b/themes/bira/bira.theme.bash index f30d8d5d00..cba4e425b8 100644 --- a/themes/bira/bira.theme.bash +++ b/themes/bira/bira.theme.bash @@ -6,6 +6,8 @@ SCM_THEME_PROMPT_SUFFIX="›${reset_color?}" VIRTUALENV_THEME_PROMPT_PREFIX=" ${cyan?}‹" VIRTUALENV_THEME_PROMPT_SUFFIX="›${reset_color?}" +CONDAENV_THEME_PROMPT_PREFIX=" ${cyan?}‹" +CONDAENV_THEME_PROMPT_SUFFIX="›${reset_color?}" bold="\[\e[1m\]" @@ -18,7 +20,7 @@ fi function prompt_command() { local current_dir=" ${bold_blue?}\w${normal?}${reset_color?}" local virtualenv_prompt scm_prompt_info - virtualenv_prompt="$(virtualenv_prompt)" + virtualenv_prompt="${virtualenv_prompt:-$(condaenv_prompt)}" scm_prompt_info="$(scm_prompt_info)" PS1="╭─${user_host?}${current_dir}${virtualenv_prompt}${scm_prompt_info}\n╰─${bold?}\\$ ${normal?}" } From 81bbf4408e633640f7aa176bff62f4d65732bbd0 Mon Sep 17 00:00:00 2001 From: Blackteahamburger Date: Tue, 27 Aug 2024 15:32:22 +0800 Subject: [PATCH 60/66] bash_profile.template.bash: fix theme location --- template/bash_profile.template.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/bash_profile.template.bash b/template/bash_profile.template.bash index 3def286612..4b90990489 100755 --- a/template/bash_profile.template.bash +++ b/template/bash_profile.template.bash @@ -11,7 +11,7 @@ export BASH_IT="{{BASH_IT}}" # Lock and Load a custom theme file. # Leave empty to disable theming. -# location /.bash_it/themes/ +# location "$BASH_IT"/themes/ export BASH_IT_THEME='bobby' # Some themes can show whether `sudo` has a current token or not. From 345d0081b98f805f4368746f346b5d6eb0a218d6 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Mon, 17 Apr 2023 20:05:48 +0300 Subject: [PATCH 61/66] Fix commandline options for the current versions of gifski and gifsicle --- plugins/available/gif.plugin.bash | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/plugins/available/gif.plugin.bash b/plugins/available/gif.plugin.bash index a04ff5c7d1..1f47f1f013 100644 --- a/plugins/available/gif.plugin.bash +++ b/plugins/available/gif.plugin.bash @@ -72,9 +72,9 @@ function v2gif() { eval set -- "$args" local use_gifski="" local opt_del_after="" - local maxsize="" - local lossiness="" - local maxwidthski="" + local maxsize=() + local lossiness=() + local maxwidthski=() local giftagopt="" local giftag="" local defaultfps=10 @@ -106,8 +106,8 @@ function v2gif() { shift ;; -w | --width) - maxsize="-vf scale=$2:-1" - maxwidthski="-W $2" + maxsize=(-vf "scale=$2:-1") + maxwidthski=(-W "$2") giftag="${giftag}-w$2" shift 2 ;; @@ -118,7 +118,7 @@ function v2gif() { ;; -l | --lossy) # Use giflossy parameter - lossiness="--lossy=$2" + lossiness=("--lossy=$2") giftag="${giftag}-l$2" shift 2 ;; @@ -164,7 +164,7 @@ function v2gif() { local del_after=$opt_del_after if [[ -n "$make_webm" ]]; then - $ffmpeg -loglevel panic -i "$file" \ + $ffmpeg -loglevel warning -i "$file" \ -c:v libvpx -crf 4 -threads 0 -an -b:v 2M -auto-alt-ref 0 \ -quality best -loop 0 "${file%.*}.webm" || return 2 fi @@ -184,12 +184,12 @@ function v2gif() { if [[ "$use_gifski" = "true" ]]; then # I trust @pornel to do his own resizing optimization choices - $ffmpeg -loglevel panic -i "$file" -r "$fps" -vcodec png v2gif-tmp-%05d.png \ - && $gifski v2gif-tmp-*.png "$maxwidthski" --fps "$(printf "%.0f" "$fps")" -o "$output_file" || return 2 + $ffmpeg -loglevel warning -i "$file" -r "$fps" -vcodec png v2gif-tmp-%05d.png \ + && $gifski "${maxwidthski[@]}" --fps "$(printf "%.0f" "$fps")" -o "$output_file" v2gif-tmp-*.png || return 2 else - $ffmpeg -loglevel panic -i "$file" "$maxsize" -r "$fps" -vcodec png v2gif-tmp-%05d.png \ + $ffmpeg -loglevel warning -i "$file" "${maxsize[@]}" -r "$fps" -vcodec png v2gif-tmp-%05d.png \ && $convert +dither -layers Optimize v2gif-tmp-*.png GIF:- \ - | $gifsicle "$lossiness" --no-warnings --colors 256 --delay="$(echo "100/$fps" | bc)" --loop --optimize=3 --multifile - > "$output_file" || return 2 + | $gifsicle "${lossiness[@]}" --no-warnings --colors 256 --delay="$(echo "100/$fps" | bc)" --loop --optimize=3 --multifile - > "$output_file" || return 2 fi rm v2gif-tmp-*.png @@ -299,7 +299,7 @@ function any2webm() { echo "$(tput setaf 2)Creating '$output_file' ...$(tput sgr 0)" - $ffmpeg -loglevel panic -i "$file" \ + $ffmpeg -loglevel warning -i "$file" \ -c:v libvpx -crf 4 -threads 0 -an -b:v "$bandwidth" -auto-alt-ref 0 \ -quality best "$fps" "$size" -loop 0 -pix_fmt yuva420p "$output_file" || return 2 From d60d806ab4fe5c37a86e4c6849498fdf964e49fa Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Tue, 5 Nov 2024 11:13:13 +0200 Subject: [PATCH 62/66] new version of oh-my-posh breaks the init commandline, fixing to the new syntax of v24 --- themes/oh-my-posh/oh-my-posh.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/oh-my-posh/oh-my-posh.theme.bash b/themes/oh-my-posh/oh-my-posh.theme.bash index ba3c77f1ef..430c8acb4c 100644 --- a/themes/oh-my-posh/oh-my-posh.theme.bash +++ b/themes/oh-my-posh/oh-my-posh.theme.bash @@ -2,7 +2,7 @@ if _command_exists oh-my-posh; then export POSH_THEME=${POSH_THEME:-https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/v$(oh-my-posh --version)/themes/jandedobbeleer.omp.json} - eval "$(oh-my-posh --init --shell bash --config "${POSH_THEME}")" + eval "$(oh-my-posh init bash --config "${POSH_THEME}")" else _log_warning "The oh-my-posh binary was not found on your PATH. Falling back to your existing PS1, please see the docs for more info." fi From fa6b4921cee361b31567d9ef9bccde3673325a4f Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Tue, 5 Nov 2024 11:27:18 +0200 Subject: [PATCH 63/66] Pass the shellcheck lint test --- themes/brainy/brainy.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/brainy/brainy.theme.bash b/themes/brainy/brainy.theme.bash index e1c3617531..b93c768f56 100644 --- a/themes/brainy/brainy.theme.bash +++ b/themes/brainy/brainy.theme.bash @@ -168,7 +168,7 @@ ___brainy_prompt_battery() { box="[|]" ac_adapter_connected && charging="+" ac_adapter_disconnected && charging="-" - info+=$charging + info+="$charging" [ "$info" == "100+" ] && info="AC" printf "%s|%s|%s|%s" "${color}" "${info}" "${bold_white}" "${box}" } From f1822f9467ca597bc254a8349eed147c1b2581a8 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Thu, 7 Nov 2024 10:06:10 +0200 Subject: [PATCH 64/66] lint cleanup for shfmt --- clean_files.txt | 1 + docs/themes-list/inretio.rst | 1 - plugins/available/browser.plugin.bash | 81 ++++++++++++++------------- themes/inretio/inretio.theme.bash | 52 ++++++++--------- themes/lambda/lambda.theme.bash | 46 +++++++-------- 5 files changed, 93 insertions(+), 88 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index e8dff795bf..cf8d8bcb72 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -90,6 +90,7 @@ plugins/available/base.plugin.bash plugins/available/basher.plugin.bash plugins/available/battery.plugin.bash plugins/available/blesh.plugin.bash +plugins/available/browser.plugin.bash plugins/available/cmd-returned-notify.plugin.bash plugins/available/colors.plugin.bash plugins/available/direnv.plugin.bash diff --git a/docs/themes-list/inretio.rst b/docs/themes-list/inretio.rst index 0e424a99f8..d37287d07c 100644 --- a/docs/themes-list/inretio.rst +++ b/docs/themes-list/inretio.rst @@ -29,4 +29,3 @@ In Python virtual environment: ┌──[2024-03-20 12:07:32] 🐧 gytis 💻 gytis-legion 🐍 3.12.2 on [general] 📂 general └> ls bin include lib lib64 pyvenv.cfg share - diff --git a/plugins/available/browser.plugin.bash b/plugins/available/browser.plugin.bash index f7d820aa07..b65d92ca76 100644 --- a/plugins/available/browser.plugin.bash +++ b/plugins/available/browser.plugin.bash @@ -1,39 +1,40 @@ +# shellcheck shell=bash # based on https://gist.github.com/318247 cite about-plugin about-plugin 'render commandline output in your browser' +# shellcheck disable=SC2120 function browser() { - about 'pipe html to a browser' - example '$ echo "

hi mom!

" | browser' - example '$ ron -5 man/rip.5.ron | browser' - group 'browser' + about 'pipe html to a browser' + example '$ echo "

hi mom!

" | browser' + example '$ ron -5 man/rip.5.ron | browser' + group 'browser' - if [ -t 0 ]; then - if [ -n "$1" ]; then - open $1 - else - reference browser - fi + if [ -t 0 ]; then + if [ -n "$1" ]; then + open "$1" + else + reference browser + fi - else - f="/tmp/browser.$RANDOM.html" - cat /dev/stdin > $f - open $f - fi + else + f="/tmp/browser.$RANDOM.html" + cat /dev/stdin > $f + open $f + fi } - function wmate() { - about 'pipe hot spicy interwebs into textmate and cleanup!' - example '$ wmate google.com' - group 'browser' - - if [ -t 0 ]; then - if [ -n "$1" ]; then - wget -qO- $1 | /usr/bin/mate + about 'pipe hot spicy interwebs into textmate and cleanup!' + example '$ wmate google.com' + group 'browser' -TIDY=`/usr/bin/osascript << EOT + if [ -t 0 ]; then + if [ -n "$1" ]; then + wget -qO- "$1" | /usr/bin/mate + TIDY=$( + /usr/bin/osascript << EOT tell application "TextMate" activate end tell @@ -53,24 +54,26 @@ tell application "System Events" end tell end tell end tell -EOT` +EOT + ) + export TIDY - else - reference wmate - fi - fi + else + reference wmate + fi + fi } function raw() { - about 'write wget into a temp file and pump it into your browser' - example '$ raw google.com' - group 'browser' + about 'write wget into a temp file and pump it into your browser' + example '$ raw google.com' + group 'browser' - if [ -t 0 ]; then - if [ -n "$1" ]; then - wget -qO- $1 | browser - else - reference raw - fi - fi + if [ -t 0 ]; then + if [ -n "$1" ]; then + wget -qO- "$1" | browser + else + reference raw + fi + fi } diff --git a/themes/inretio/inretio.theme.bash b/themes/inretio/inretio.theme.bash index 58ac36ddfb..1db6c6d1f4 100644 --- a/themes/inretio/inretio.theme.bash +++ b/themes/inretio/inretio.theme.bash @@ -16,11 +16,11 @@ VIRTUALENV_THEME_PROMPT_SUFFIX="" # SCM prompts SCM_NONE_CHAR="" SCM_GIT_CHAR="[±] " -SCM_GIT_BEHIND_CHAR="${red}↓${normal}" -SCM_GIT_AHEAD_CHAR="${bold_green}↑${normal}" +SCM_GIT_BEHIND_CHAR="${red?}↓${normal?}" +SCM_GIT_AHEAD_CHAR="${bold_green?}↑${normal?}" SCM_GIT_UNTRACKED_CHAR="⌀" -SCM_GIT_UNSTAGED_CHAR="${bold_yellow}•${normal}" -SCM_GIT_STAGED_CHAR="${bold_green}+${normal}" +SCM_GIT_UNSTAGED_CHAR="${bold_yellow?}•${normal?}" +SCM_GIT_STAGED_CHAR="${bold_green?}+${normal?}" SCM_THEME_PROMPT_DIRTY="" SCM_THEME_PROMPT_CLEAN="" @@ -28,8 +28,8 @@ SCM_THEME_PROMPT_PREFIX="" SCM_THEME_PROMPT_SUFFIX="" # Git status prompts -GIT_THEME_PROMPT_DIRTY=" ${red}✗${normal}" -GIT_THEME_PROMPT_CLEAN=" ${bold_green}✓${normal}" +GIT_THEME_PROMPT_DIRTY=" ${red?}✗${normal?}" +GIT_THEME_PROMPT_CLEAN=" ${bold_green?}✓${normal?}" GIT_THEME_PROMPT_PREFIX="" GIT_THEME_PROMPT_SUFFIX="" @@ -48,32 +48,32 @@ icon_end="└> " # Display virtual environment info function _virtualenv_prompt { - VIRTUALENV_DETAILS="" - VIRTUALENV_CHAR="" - - # $VIRTUAL_ENV is set and is non-zero length - if [[ -n "$VIRTUAL_ENV" ]]; then - # Check if Python 3 exists - if command -v python3 >/dev/null 2>&1; then - VIRTUALENV_DETAILS="$($VIRTUAL_ENV/bin/python --version | sed 's,Python ,,') on [$(basename $VIRTUAL_ENV)]" - VIRTUALENV_CHAR=" 🐍" - else - VIRTUALENV_DETAILS="[$(basename $VIRTUAL_ENV)]" - VIRTUALENV_CHAR=" ⓔ" - fi - fi - - echo "$VIRTUALENV_CHAR $VIRTUALENV_DETAILS" + VIRTUALENV_DETAILS="" + VIRTUALENV_CHAR="" + + # $VIRTUAL_ENV is set and is non-zero length + if [[ -n "$VIRTUAL_ENV" ]]; then + # Check if Python 3 exists + if command -v python3 > /dev/null 2>&1; then + VIRTUALENV_DETAILS="$("$VIRTUAL_ENV/bin/python" --version | sed 's,Python ,,') on [$(basename "$VIRTUAL_ENV")]" + VIRTUALENV_CHAR=" 🐍" + else + VIRTUALENV_DETAILS="[$(basename "$VIRTUAL_ENV")]" + VIRTUALENV_CHAR=" ⓔ" + fi + fi + + echo "$VIRTUALENV_CHAR $VIRTUALENV_DETAILS" } # Rename tab function tabname { - printf "\e]1;$1\a" + printf "\e]1;%s\a" "$1" } # Rename window function winname { - printf "\e]2;$1\a" + printf "\e]2;%s\a" "$1" } _theme_clock() { @@ -92,8 +92,8 @@ THEME_CLOCK_FORMAT=${THEME_CLOCK_FORMAT:-"%Y-%m-%d %H:%M:%S"} # Displays the current prompt function prompt_command() { - PS1="\n${icon_start}$(_theme_clock)${icon_user}${bold_green}\u${normal}${icon_host}${bold_cyan}\h${normal}${green}$(_virtualenv_prompt)${normal}${icon_directory}${bold_purple}\W${normal}\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on ${icon_branch} $(scm_prompt_info) \")${white}${normal}\n${icon_end}" - PS2="${icon_end}" + PS1="\n${icon_start}$(_theme_clock)${icon_user}${bold_green?}\u${normal}${icon_host}${bold_cyan?}\h${normal}${green?}$(_virtualenv_prompt)${normal}${icon_directory}${bold_purple?}\W${normal}\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on ${icon_branch} $(scm_prompt_info) \")${white?}${normal}\n${icon_end}" + PS2="${icon_end}" } # Runs prompt (this bypasses bash_it $PROMPT setting) diff --git a/themes/lambda/lambda.theme.bash b/themes/lambda/lambda.theme.bash index 8f3d5baf49..59f82a4a81 100644 --- a/themes/lambda/lambda.theme.bash +++ b/themes/lambda/lambda.theme.bash @@ -1,33 +1,35 @@ -#!/bin/bash +# shellcheck shell=bash # shellcheck disable=SC1090,SC2034 function set_prompt { - local user_color="\[\033[1;31m\]" # bold red for username - local at_color="\[\033[1;37m\]" # bold white for @ symbol - local host_color="\[\033[1;31m\]" # bold red for hostname - local in_color="\[\033[1;37m\]" # bold white for "in" - local dir_color="\[\033[1;35m\]" # bold purple for current working directory - local git_color="\[\033[1;36m\]" # bold cyan for Git information - local time_color="\[\033[1;32m\]" # bold green for time taken - local reset_color="\[\033[0m\]" # reset color - local prompt_symbol_color="\[\033[1;31m\]" # bold red for the prompt symbol + local user_color="\[\033[1;31m\]" # bold red for username + local at_color="\[\033[1;37m\]" # bold white for @ symbol + local host_color="\[\033[1;31m\]" # bold red for hostname + local in_color="\[\033[1;37m\]" # bold white for "in" + local dir_color="\[\033[1;35m\]" # bold purple for current working directory + local git_color="\[\033[1;36m\]" # bold cyan for Git information + local time_color="\[\033[1;32m\]" # bold green for time taken + local reset_color="\[\033[0m\]" # reset color + local prompt_symbol_color="\[\033[1;31m\]" # bold red for the prompt symbol - local end_time=$(date +%s%3N) # current time in milliseconds - local time_taken=$(( (end_time - start_time) )) # time in milliseconds + local end_time time_taken + end_time=$(date +%s%3N) # current time in milliseconds + # shellcheck disable=SC2154 + time_taken=$((end_time - start_time)) # time in milliseconds - PS1="${user_color}╭─\\u" # username - PS1+="${at_color}@${host_color}\\h" # @ symbol and hostname - PS1+="${in_color} in" # "in" between hostname and current directory - PS1+="${dir_color} \\w" # current working directory + PS1="${user_color}╭─\\u" # username + PS1+="${at_color}@${host_color}\\h" # @ symbol and hostname + PS1+="${in_color} in" # "in" between hostname and current directory + PS1+="${dir_color} \\w" # current working directory - # Git information (status symbol) - PS1+=" ${git_color}$(__git_ps1 "[%s]")${reset_color}" + # Git information (status symbol) + PS1+=" ${git_color}$(__git_ps1 "[%s]")${reset_color}" - if [ $time_taken -gt 0 ]; then - PS1+=" ${time_color}took ${time_taken}ms" # time taken in milliseconds - fi + if [ $time_taken -gt 0 ]; then + PS1+=" ${time_color}took ${time_taken}ms" # time taken in milliseconds + fi - PS1+="\n${prompt_symbol_color}╰─λ${reset_color} " # red color for the prompt symbol, reset color after + PS1+="\n${prompt_symbol_color}╰─λ${reset_color} " # red color for the prompt symbol, reset color after } PROMPT_COMMAND='start_time=$(date +%s%3N); set_prompt' From 092b1ea9373a4a9a51cd0787747404f7e2e248d4 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Thu, 7 Nov 2024 11:54:59 +0200 Subject: [PATCH 65/66] linting the bats --- test/plugins/cmd-returned-notify.plugin.bats | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/plugins/cmd-returned-notify.plugin.bats b/test/plugins/cmd-returned-notify.plugin.bats index d8aa9248ff..19965032aa 100644 --- a/test/plugins/cmd-returned-notify.plugin.bats +++ b/test/plugins/cmd-returned-notify.plugin.bats @@ -9,8 +9,9 @@ function local_setup_file() { } @test "plugins cmd-returned-notify: notify after elapsed time" { - export NOTIFY_IF_COMMAND_RETURNS_AFTER=0 - export COMMAND_DURATION_START_SECONDS="$(_shell_duration_en)" + NOTIFY_IF_COMMAND_RETURNS_AFTER=0 + COMMAND_DURATION_START_SECONDS="$(_shell_duration_en)" + export COMMAND_DURATION_START_SECONDS NOTIFY_IF_COMMAND_RETURNS_AFTER sleep 1 run precmd_return_notification assert_success @@ -18,8 +19,9 @@ function local_setup_file() { } @test "plugins cmd-returned-notify: do not notify before elapsed time" { - export NOTIFY_IF_COMMAND_RETURNS_AFTER=10 - export COMMAND_DURATION_START_SECONDS="$(_shell_duration_en)" + NOTIFY_IF_COMMAND_RETURNS_AFTER=10 + COMMAND_DURATION_START_SECONDS="$(_shell_duration_en)" + export COMMAND_DURATION_START_SECONDS NOTIFY_IF_COMMAND_RETURNS_AFTER sleep 1 run precmd_return_notification assert_success From 9df0c64a4936843a6907de1bbf5bf1e03c1f3027 Mon Sep 17 00:00:00 2001 From: Ira Abramov Date: Thu, 7 Nov 2024 11:58:10 +0200 Subject: [PATCH 66/66] linting the bats --- aliases/available/git.aliases.bash | 6 +++--- test/plugins/battery.plugin.bats | 1 + themes/base.theme.bash | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/aliases/available/git.aliases.bash b/aliases/available/git.aliases.bash index f56675e66d..829505ddfd 100644 --- a/aliases/available/git.aliases.bash +++ b/aliases/available/git.aliases.bash @@ -83,7 +83,7 @@ alias ggup='git log --branches --not --remotes --no-walk --decorate --oneline' # alias gll='git log --graph --pretty=oneline --abbrev-commit' alias gnew='git log HEAD@{1}..HEAD@{0}' # Show commits since last pull, see http://blogs.atlassian.com/2014/10/advanced-git-aliases/ alias gwc='git whatchanged' -alias ghist='git log --pretty=format:'\''%h %ad | %s%d [%an]'\'' --graph --date=short' # Use it to be fast and without color. +alias ghist='git log --pretty=format:'\''%h %ad | %s%d [%an]'\'' --graph --date=short' # Use it to be fast and without color. alias gprogress='git log --pretty=format:'\''%C(yellow)%h %Cblue%ad %Creset%s%Cgreen [%cn] %Cred%d'\'' --decorate --date=short' #Usually use "git progress" in the file .gitconfig. The new alias from Git friends will be truly welcome. # ls-files @@ -153,8 +153,8 @@ alias grma='GIT_SEQUENCE_EDITOR=: git rebase $(get_default_branch) -i --autosqu alias gprom='git fetch origin $(get_default_branch) && git rebase origin/$(get_default_branch) && git update-ref refs/heads/$(get_default_branch) origin/$(get_default_branch)' # Rebase with latest remote # reset -alias gus='git reset HEAD' # read as: 'git unstage' -alias grh='git reset' # equivalent to: git reset HEAD +alias gus='git reset HEAD' # read as: 'git unstage' +alias grh='git reset' # equivalent to: git reset HEAD alias grh!='git reset --hard' alias gpristine='git reset --hard && git clean -dfx' diff --git a/test/plugins/battery.plugin.bats b/test/plugins/battery.plugin.bats index 49199ef27c..6665207f3a 100644 --- a/test/plugins/battery.plugin.bats +++ b/test/plugins/battery.plugin.bats @@ -271,6 +271,7 @@ function setup_ioreg { percent="$1" function ioreg { + # shellcheck disable=SC2317 printf "\"MaxCapacity\" = 100\n\"CurrentCapacity\" = %s" "${percent}" } } diff --git a/themes/base.theme.bash b/themes/base.theme.bash index e25014f86b..d78baa6adf 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -416,9 +416,9 @@ function node_version_prompt() { _log_debug "node: using version strategy '$NODE_VERSION_STRATEGY'" if [ "$NODE_VERSION_STRATEGY" == "nvm" ]; then - nvm_version_prompt + nvm_version_prompt elif [ "$NODE_VERSION_STRATEGY" == "node" ]; then - node_native_version_prompt + node_native_version_prompt fi }