Adding preexec as a vendored library

Added a vendored lib loading routine in bash-it.sh
Added documentation on how to vendor libs in bash-it
Added and fixed plugins using preexec
Added tests for two plugins
Removed the old preexec lib
This commit is contained in:
buhl
2021-01-08 23:51:37 +01:00
parent 5ad497924c
commit 29855ed1e6
12 changed files with 252 additions and 260 deletions

0
test/fixtures/plugin/xterm/files/arg0 vendored Normal file
View File

0
test/fixtures/plugin/xterm/files/arg1 vendored Normal file
View File

View File

@@ -0,0 +1,47 @@
#!/usr/bin/env bats
load ../test_helper
load ../../lib/helpers
load ../../lib/composure
load ../../plugins/available/cmd-returned-notify.plugin
@test "plugins cmd-returned-notify: notify after elapsed time" {
export NOTIFY_IF_COMMAND_RETURNS_AFTER=0
export LAST_COMMAND_TIME=$(date +%s)
sleep 1
run precmd_return_notification
assert_success
assert_output $'\a'
}
@test "plugins cmd-returned-notify: do not notify before elapsed time" {
export NOTIFY_IF_COMMAND_RETURNS_AFTER=10
export LAST_COMMAND_TIME=$(date +%s)
sleep 1
run precmd_return_notification
assert_success
assert_output $''
}
@test "plugins cmd-returned-notify: preexec no output" {
export LAST_COMMAND_TIME=
run preexec_return_notification
assert_success
assert_output ""
}
@test "plugins cmd-returned-notify: preexec no output env set" {
export LAST_COMMAND_TIME=$(date +%s)
run preexec_return_notification
assert_failure
assert_output ""
}
@test "plugins cmd-returned-notify: preexec set LAST_COMMAND_TIME" {
export LAST_COMMAND_TIME=
assert_equal "${LAST_COMMAND_TIME}" ""
NOW=$(date +%s)
preexec_return_notification
assert_equal "${LAST_COMMAND_TIME}" "${NOW}"
}

View File

@@ -0,0 +1,54 @@
#!/usr/bin/env bats
load ../test_helper
load ../../lib/composure
load ../../plugins/available/xterm.plugin
function local_setup {
setup_test_fixture
# Copy the test fixture to the Bash-it folder
if command_exists -v rsync
then
rsync -a "$BASH_IT/test/fixtures/plugin/xterm/" "$BASH_IT/"
else
find "$BASH_IT/test/fixtures/plugin/xterm" \
-mindepth 1 -maxdepth 1 \
-exec cp -r {} "$BASH_IT/" \;
fi
}
@test "plugins xterm: shorten command output" {
export 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
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
run _short-dirname
assert_success
assert_output "$(basename $PWD)"
}
@test "plugins xterm: full dirname output" {
export SHORT_TERM_LINE=false
run _short-dirname
assert_success
assert_output $PWD
}
@test "plugins xterm: set xterm title" {
run set_xterm_title title
assert_success
assert_output $'\033]0;title\007'
}