Minor fixes identified through shellcheck and other tools (#350)
* fix whitespace * fix spelling * fix whitespace * unify headers of tests * fix some issues in tests, identified by shellcheck * fix bash completions bash completion files are not supposed to be executable * fix some issues identified by shellcheck Co-authored-by: Ali Karbassi <ali@karbassi.com>
This commit is contained in:
@@ -147,7 +147,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
### Changed
|
||||
|
||||
- Changed odd tabs to spaces.
|
||||
- Faster help/useage document outputs.
|
||||
- Faster help/usage document outputs.
|
||||
- Consolidated `TODOTXT_VERBOSE` tests.
|
||||
- Refactored various add functionality to one function.
|
||||
- Updated `_list()` output to match updated `addto`.
|
||||
@@ -436,7 +436,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
|
||||
### Added
|
||||
|
||||
- `list` is case insenstive. ie, `todo list Mac` will match lines with "mac" and "Mac"
|
||||
- `list` is case insensitive. ie, `todo list Mac` will match lines with "mac" and "Mac"
|
||||
|
||||
### Changed
|
||||
|
||||
|
||||
@@ -34,5 +34,3 @@ test "$VN" = "$VC" || {
|
||||
echo >&2 "VERSION=$VN"
|
||||
echo "VERSION=$VN" >$VF
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ See [CHANGELOG.md][CHANGELOG]
|
||||
|
||||
## Contributing
|
||||
|
||||
We welcome all contributations. First read our [Contributor Code of Conduct][CODE_OF_CONDUCT] and then get started [contributing][CONTRIBUTING].
|
||||
We welcome all contributions. First read our [Contributor Code of Conduct][CODE_OF_CONDUCT] and then get started [contributing][CONTRIBUTING].
|
||||
|
||||
## License
|
||||
|
||||
@@ -94,7 +94,7 @@ GNU General Public License v3.0 © [todo.txt org][github]
|
||||
|
||||
|
||||
[release]: https://github.com/todotxt/todo.txt-cli/releases
|
||||
[website]: http://todotxt.org
|
||||
[website]: http://todotxt.org/
|
||||
[github]: https://github.com/todotxt
|
||||
[USAGE]: ./USAGE.md
|
||||
[CHANGELOG]: ./CHANGELOG.md
|
||||
|
||||
2
USAGE.md
2
USAGE.md
@@ -104,7 +104,7 @@ todo.sh help [ACTION...]
|
||||
Displays all tasks that contain TERM(s) sorted by priority with line numbers. Each task must match all TERM(s) (logical AND); to display tasks that contain any TERM (logical OR), use `"TERM1\|TERM2\|..."` (with quotes), or `TERM1\\|TERM2` (unquoted). Hides all tasks that contain TERM(s) preceded by a minus sign (i.e. `-TERM`).
|
||||
|
||||
If no TERM specified, lists entire todo.txt.
|
||||
|
||||
|
||||
```shell
|
||||
todo.sh list [TERM...]
|
||||
todo.sh ls [TERM...]
|
||||
|
||||
@@ -266,7 +266,7 @@ and the dates and timestamps will be artificially fixed.
|
||||
Then the session can be used to make a unit test thanks to
|
||||
test_todo_session, see the existing tests as examples.
|
||||
|
||||
Be careful to replace all occurences of the full path to the test
|
||||
Be careful to replace all occurrences of the full path to the test
|
||||
directory by $HOME as testshell.sh will explain you when you execute it
|
||||
otherwise the tests will work properly only on your own computer.
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ make_action_in_folder()
|
||||
{
|
||||
unset TODO_ACTIONS_DIR
|
||||
[ -d .todo.actions.d ] || mkdir .todo.actions.d
|
||||
mkdir .todo.actions.d/$1
|
||||
mkdir ".todo.actions.d/$1"
|
||||
cat > ".todo.actions.d/$1/$1" <<EOF
|
||||
#!/bin/bash
|
||||
[ "\$1" = "usage" ] && {
|
||||
|
||||
@@ -15,7 +15,7 @@ case "$1" in
|
||||
esac
|
||||
|
||||
if test -n "$color"; then
|
||||
say_color () {
|
||||
say_color() {
|
||||
(
|
||||
export TERM
|
||||
case "$1" in
|
||||
@@ -67,15 +67,15 @@ do
|
||||
'')
|
||||
continue ;;
|
||||
fixed)
|
||||
fixed=$(($fixed + $value)) ;;
|
||||
fixed=$((fixed + $value)) ;;
|
||||
success)
|
||||
success=$(($success + $value)) ;;
|
||||
success=$((success + $value)) ;;
|
||||
failed)
|
||||
failed=$(($failed + $value)) ;;
|
||||
failed=$((failed + $value)) ;;
|
||||
broken)
|
||||
broken=$(($broken + $value)) ;;
|
||||
broken=$((broken + $value)) ;;
|
||||
total)
|
||||
total=$(($total + $value)) ;;
|
||||
total=$((total + $value)) ;;
|
||||
esac
|
||||
done <"$file"
|
||||
done
|
||||
|
||||
@@ -20,12 +20,12 @@ test_expect_success 'no config file' '
|
||||
'
|
||||
|
||||
# All the below tests will output the usage message.
|
||||
cat > expect << EOF
|
||||
cat > expect <<EOF
|
||||
Usage: todo.sh [-fhpantvV] [-d todo_config] action [task_number] [task_description]
|
||||
Try 'todo.sh -h' for more information.
|
||||
EOF
|
||||
|
||||
cat > test.cfg << EOF
|
||||
cat > test.cfg <<EOF
|
||||
export TODO_DIR=.
|
||||
export TODO_FILE="\$TODO_DIR/todo.txt"
|
||||
export DONE_FILE="\$TODO_DIR/done.txt"
|
||||
@@ -79,7 +79,7 @@ test_expect_success 'config file (env variable)' '
|
||||
test_cmp expect output && test -f used_config
|
||||
'
|
||||
|
||||
cat > minimal.cfg << EOF
|
||||
cat > minimal.cfg <<EOF
|
||||
export TODO_DIR=.
|
||||
touch used_config
|
||||
EOF
|
||||
|
||||
@@ -59,7 +59,6 @@ test_expect_success 'null list filter' '
|
||||
todo.sh listall filter > output && test_cmp expect output
|
||||
'
|
||||
|
||||
|
||||
#
|
||||
# lsc|listcon
|
||||
#
|
||||
|
||||
@@ -7,11 +7,11 @@ This test just makes sure that todo.sh can locate custom actions.
|
||||
. ./test-lib.sh
|
||||
|
||||
# All the below tests will output the custom action message
|
||||
cat > expect << EOF
|
||||
cat > expect <<EOF
|
||||
TODO: foo
|
||||
EOF
|
||||
|
||||
cat > foo << EOF
|
||||
cat > foo <<EOF
|
||||
echo "TODO: foo"
|
||||
EOF
|
||||
chmod +x foo
|
||||
|
||||
@@ -45,7 +45,7 @@ grow some corn
|
||||
thrash some hay
|
||||
chase the chickens
|
||||
EOF
|
||||
test_todo_session 'replace error' << EOF
|
||||
test_todo_session 'replace error' <<EOF
|
||||
>>> todo.sh replace 10 "hej!"
|
||||
=== 1
|
||||
TODO: No task 10.
|
||||
@@ -82,7 +82,7 @@ TODO: Replaced task with:
|
||||
EOF
|
||||
|
||||
echo 'jump on hay' > todo.txt
|
||||
test_todo_session 'replace with &' << EOF
|
||||
test_todo_session 'replace with &' <<EOF
|
||||
>>> todo.sh replace 1 "thrash the hay & thrash the wheat"
|
||||
1 jump on hay
|
||||
TODO: Replaced task with:
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
test_description='list functionality
|
||||
|
||||
@@ -162,7 +161,6 @@ TODO: 1 of 5 tasks shown
|
||||
TODO: 1 of 5 tasks shown
|
||||
EOF
|
||||
|
||||
|
||||
#
|
||||
# check the x command line option
|
||||
#
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
test_description='listcon functionality
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
test_description='listproj functionality
|
||||
|
||||
@@ -117,7 +116,6 @@ test_todo_session 'listproj with context special cases' <<EOF
|
||||
+sunflowers
|
||||
EOF
|
||||
|
||||
|
||||
cat > todo.txt <<EOF
|
||||
+prj01 -- Some project 1 task
|
||||
EOF
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
test_description='list highlighting
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
test_description='list with escape sequences
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
test_description='highlighting projects and contexts
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
test_description='highlighting date, item numbers and metadata
|
||||
|
||||
@@ -32,7 +31,6 @@ test_todo_session 'highlighting for date, item numbers and metadata' <<'EOF'
|
||||
TODO: 3 of 3 tasks shown
|
||||
EOF
|
||||
|
||||
|
||||
test_todo_session 'suppressing highlighting for date, item numbers and metadata' <<'EOF'
|
||||
>>> todo.sh -p -d "$TEST_TODO_LABEL_COLORS" ls
|
||||
1 2018-11-11 task with date
|
||||
|
||||
@@ -83,4 +83,5 @@ TODO: 3 marked as done.
|
||||
>>> todo.sh -a do 3
|
||||
TODO: 3 is already marked done.
|
||||
EOF
|
||||
|
||||
test_done
|
||||
|
||||
@@ -17,7 +17,7 @@ test_todo_session 'append usage' <<EOF
|
||||
usage: todo.sh append ITEM# "TEXT TO APPEND"
|
||||
EOF
|
||||
|
||||
test_todo_session 'append error' << EOF
|
||||
test_todo_session 'append error' <<EOF
|
||||
>>> todo.sh append 10 "hej!"
|
||||
=== 1
|
||||
TODO: No task 10.
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
test_description='basic move functionality
|
||||
'
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
test_description='help functionality
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
test_description='shorthelp functionality
|
||||
|
||||
@@ -36,7 +35,6 @@ test_todo_session 'shorthelp output with custom action' <<EOF
|
||||
See "help" for more details.
|
||||
EOF
|
||||
|
||||
|
||||
# Verify that custom configuration is actually processed (when the -d option
|
||||
# precedes the -h option) by specifying a different actions directory and moving
|
||||
# our custom action there. The help output should mention the "Add-On Actions".
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
test_description='todo.sh configuration with a sole todo.txt data file.
|
||||
|
||||
@@ -8,7 +7,7 @@ checks that no such empty files are created.
|
||||
'
|
||||
. ./test-lib.sh
|
||||
|
||||
cat > test.cfg << EOF
|
||||
cat > test.cfg <<EOF
|
||||
export TODO_DIR=.
|
||||
export TODO_FILE="\$TODO_DIR/todo.txt"
|
||||
export DONE_FILE=/dev/null
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
test_description='Bash completion functionality
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
test_description='Bash context completion functionality
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
test_description='Bash project completion functionality
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
test_description='Bash task number completion functionality
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
test_description='Bash todo file completion functionality
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
test_description='Bash add-on action completion functionality
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
test_description='Bash add-on action file completion functionality
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
test_description='Bash completion with different path functionality
|
||||
|
||||
@@ -28,8 +27,6 @@ _todo2()
|
||||
|
||||
test_todo_custom_completion _todo2 'all todo2 contexts' 'todo2 list @' '@garden @outdoor @outside'
|
||||
|
||||
|
||||
|
||||
# Remove the test environment's bin directory from the PATH, so that our test
|
||||
# executable must be launched with an explicit path.
|
||||
PATH=${PATH##"${PWD}/bin:"}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
test_description='Bash completion with different aliases functionality
|
||||
|
||||
@@ -46,7 +45,6 @@ test_todo_session 'todo 1 and 2 contexts' <<EOF
|
||||
@oriental
|
||||
EOF
|
||||
|
||||
|
||||
# Define a second completion function that injects the different configuration
|
||||
# file. In real use, this would be installed via
|
||||
# complete -F _todo2 todo2
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
|
||||
test_description='Bash help completion functionality
|
||||
|
||||
|
||||
@@ -172,12 +172,12 @@ test_set_editor () {
|
||||
# the text_expect_* functions instead.
|
||||
|
||||
test_ok_ () {
|
||||
test_success=$(($test_success + 1))
|
||||
test_success=$((test_success + 1))
|
||||
say_color "" " ok $test_count: $@"
|
||||
}
|
||||
|
||||
test_failure_ () {
|
||||
test_failure=$(($test_failure + 1))
|
||||
test_failure=$((test_failure + 1))
|
||||
say_color error "FAIL $test_count: $1"
|
||||
shift
|
||||
echo "$@"
|
||||
@@ -185,12 +185,12 @@ test_failure_ () {
|
||||
}
|
||||
|
||||
test_known_broken_ok_ () {
|
||||
test_fixed=$(($test_fixed+1))
|
||||
test_fixed=$((test_fixed + 1))
|
||||
say_color "" " FIXED $test_count: $@"
|
||||
}
|
||||
|
||||
test_known_broken_failure_ () {
|
||||
test_broken=$(($test_broken+1))
|
||||
test_broken=$((test_broken + 1))
|
||||
say_color skip " still broken $test_count: $@"
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ test_run_ () {
|
||||
}
|
||||
|
||||
test_skip () {
|
||||
test_count=$(($test_count+1))
|
||||
test_count=$((test_count + 1))
|
||||
to_skip=
|
||||
for skp in $SKIP_TESTS
|
||||
do
|
||||
@@ -364,7 +364,7 @@ test_external_without_stderr () {
|
||||
test_ok_ "$descr"
|
||||
else
|
||||
if [ "$verbose" = t ]; then
|
||||
output=`echo; echo Stderr is:; cat "$stderr"`
|
||||
output=$(echo; echo Stderr is:; cat "$stderr")
|
||||
else
|
||||
output=
|
||||
fi
|
||||
@@ -428,7 +428,7 @@ test_done () {
|
||||
if test "$test_broken" != 0
|
||||
then
|
||||
say_color error "still have $test_broken known breakage(s)"
|
||||
msg="remaining $(($test_count-$test_broken)) test(s)"
|
||||
msg="remaining $((test_count - test_broken)) test(s)"
|
||||
else
|
||||
msg="$test_count test(s)"
|
||||
fi
|
||||
@@ -471,7 +471,7 @@ rm -fr "$test" || {
|
||||
test_init_todo () {
|
||||
test "$#" = 1 ||
|
||||
error "bug in the test script: not 1 parameter to test_init_todo"
|
||||
owd=`pwd`
|
||||
owd=$(pwd)
|
||||
root="$1"
|
||||
mkdir -p "$root"
|
||||
cd "$root" || error "Cannot setup todo dir in $root"
|
||||
@@ -548,7 +548,7 @@ test_init_todo () {
|
||||
|
||||
# Usage: test_tick [increment]
|
||||
test_tick () {
|
||||
TODO_TEST_TIME=$(($TODO_TEST_TIME + ${1:-86400}))
|
||||
TODO_TEST_TIME=$((TODO_TEST_TIME + ${1:-86400}))
|
||||
}
|
||||
|
||||
# Generate and run a series of tests based on a transcript.
|
||||
@@ -581,14 +581,14 @@ test_todo_session () {
|
||||
status=${line#=== }
|
||||
;;
|
||||
"")
|
||||
if [ ! -z "$cmd" ]; then
|
||||
if [ $status = 0 ]; then
|
||||
if [ -n "$cmd" ]; then
|
||||
if [ "$status" = 0 ]; then
|
||||
test_expect_output "$1 $subnum" "$cmd"
|
||||
else
|
||||
test_expect_code_and_output "$status" "$1 $subnum" "$cmd"
|
||||
fi
|
||||
|
||||
subnum=$(($subnum + 1))
|
||||
subnum=$((subnum + 1))
|
||||
cmd=""
|
||||
status=0
|
||||
> expect
|
||||
@@ -602,8 +602,8 @@ test_todo_session () {
|
||||
;;
|
||||
esac
|
||||
done
|
||||
if [ ! -z "$cmd" ]; then
|
||||
if [ $status = 0 ]; then
|
||||
if [ -n "$cmd" ]; then
|
||||
if [ "$status" = 0 ]; then
|
||||
test_expect_output "$1 $subnum" "$cmd"
|
||||
else
|
||||
test_expect_code_and_output "$status" "$1 $subnum" "$cmd"
|
||||
@@ -645,7 +645,7 @@ test_todo_custom_completion () {
|
||||
SAVEIFS=$IFS
|
||||
IFS=' ' set -- $2
|
||||
COMP_WORDS=("$@")
|
||||
COMP_CWORD=$(($# - $offset))
|
||||
COMP_CWORD=$(($# - offset))
|
||||
IFS=' ' eval "set -- $expected"
|
||||
EXPECT=("$@")
|
||||
|
||||
|
||||
7
todo.sh
7
todo.sh
@@ -134,7 +134,6 @@ $indentedJoinedConfigFileLocations
|
||||
-x
|
||||
Disables TODOTXT_FINAL_FILTER
|
||||
|
||||
|
||||
EndOptionsHelp
|
||||
|
||||
[ "$TODOTXT_VERBOSE" -gt 1 ] && cat <<-'EndVerboseHelp'
|
||||
@@ -156,7 +155,6 @@ $indentedJoinedConfigFileLocations
|
||||
TODOTXT_SIGIL_VALID_PATTERN=.* tweak the allowed chars for +p and @c
|
||||
TODOTXT_SIGIL_AFTER_PATTERN="" optionally allow chars after +p / @c
|
||||
|
||||
|
||||
EndVerboseHelp
|
||||
actionsHelp
|
||||
addonHelp
|
||||
@@ -710,7 +708,6 @@ do
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
if [ -z "$TODO_ACTIONS_DIR" ] || [ ! -d "$TODO_ACTIONS_DIR" ]
|
||||
then
|
||||
TODO_ACTIONS_DIR="$HOME/.todo/actions"
|
||||
@@ -788,7 +785,7 @@ ACTION=${1:-$TODOTXT_DEFAULT_ACTION}
|
||||
|
||||
if [ $TODOTXT_PLAIN = 1 ]; then
|
||||
for clr in ${!PRI_@}; do
|
||||
export "$clr"=$NONE
|
||||
export "$clr"="$NONE"
|
||||
done
|
||||
PRI_X=$NONE
|
||||
DEFAULT=$NONE
|
||||
@@ -1093,7 +1090,7 @@ case $action in
|
||||
SAVEIFS=$IFS
|
||||
IFS=$'\n'
|
||||
|
||||
# Treat each line seperately
|
||||
# Treat each line separately
|
||||
for line in $input ; do
|
||||
_addto "$TODO_FILE" "$line"
|
||||
done
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#!/bin/bash source-this-script
|
||||
[ "$BASH_VERSION" ] || return
|
||||
# bash completion for todo.txt-cli
|
||||
|
||||
# Check for bash
|
||||
[ -z "$BASH_VERSION" ] && return
|
||||
|
||||
_todo()
|
||||
{
|
||||
@@ -18,7 +20,7 @@ _todo()
|
||||
|
||||
local _todo_sh=${_todo_sh:-todo.sh}
|
||||
local completions
|
||||
if [ $COMP_CWORD -eq 1 ]; then
|
||||
if [ "$COMP_CWORD" -eq 1 ]; then
|
||||
completions="$COMMANDS $(eval TODOTXT_VERBOSE=0 $_todo_sh command listaddons 2>/dev/null) $OPTS"
|
||||
elif [[ $COMP_CWORD -gt 2 && ( \
|
||||
"${COMP_WORDS[COMP_CWORD-2]}" =~ ^($MOVE_COMMAND_PATTERN${_todo_file2_actions:+|${_todo_file2_actions}})$ || \
|
||||
|
||||
Reference in New Issue
Block a user