diff --git a/tests/actions-test-lib.sh b/tests/actions-test-lib.sh index 2928261..6d77170 100644 --- a/tests/actions-test-lib.sh +++ b/tests/actions-test-lib.sh @@ -16,3 +16,21 @@ echo "custom action $1" EOF chmod +x ".todo.actions.d/$1" } + +make_action_in_folder() +{ + unset TODO_ACTIONS_DIR + [ -d .todo.actions.d ] || mkdir .todo.actions.d + mkdir .todo.actions.d/$1 + cat > ".todo.actions.d/$1/$1" < "${1}/$contained/$contained" + chmod u+x "${1}/$contained/$contained" + done + set +e } removeCustomActions() { set -e rmdir "${1}/subdir" + + for contained in $CONTAINED + do + rm "${1}/$contained/$contained" + rmdir "${1}/$contained" + done + rm "${1:?}/"* rmdir "$1" set +e @@ -46,8 +64,8 @@ removeCustomActions() # Test resolution of the default TODO_ACTIONS_DIR. # makeCustomActions "$HOME/.todo.actions.d" -test_todo_completion 'all arguments' 'todo.sh ' "$ACTIONS $ADDONS $OPTIONS" -test_todo_completion 'all arguments after option' 'todo.sh -a ' "$ACTIONS $ADDONS $OPTIONS" +test_todo_completion 'all arguments' 'todo.sh ' "$ACTIONS $ADDONS $CONTAINED $OPTIONS" +test_todo_completion 'all arguments after option' 'todo.sh -a ' "$ACTIONS $ADDONS $CONTAINED $OPTIONS" test_todo_completion 'all arguments beginning with b' 'todo.sh b' 'bar baz' test_todo_completion 'all arguments beginning with f after options' 'todo.sh -a -v f' 'foobar' test_todo_completion 'nothing after addon action' 'todo.sh foobar ' '' @@ -58,7 +76,7 @@ removeCustomActions "$HOME/.todo.actions.d" # mkdir "$HOME/.todo" makeCustomActions "$HOME/.todo/actions" -test_todo_completion 'all arguments with actions from .todo/actions/' 'todo.sh ' "$ACTIONS $ADDONS $OPTIONS" +test_todo_completion 'all arguments with actions from .todo/actions/' 'todo.sh ' "$ACTIONS $ADDONS $CONTAINED $OPTIONS" removeCustomActions "$HOME/.todo/actions" # @@ -68,7 +86,7 @@ makeCustomActions "$HOME/addons" cat >> todo.cfg <<'EOF' export TODO_ACTIONS_DIR="$HOME/addons" EOF -test_todo_completion 'all arguments with actions from addons/' 'todo.sh ' "$ACTIONS $ADDONS $OPTIONS" +test_todo_completion 'all arguments with actions from addons/' 'todo.sh ' "$ACTIONS $ADDONS $CONTAINED $OPTIONS" removeCustomActions "$HOME/addons" test_done diff --git a/tests/t8010-listaddons.sh b/tests/t8010-listaddons.sh index ed0cb05..b4e89aa 100755 --- a/tests/t8010-listaddons.sh +++ b/tests/t8010-listaddons.sh @@ -41,4 +41,44 @@ ls quux EOF +make_action_in_folder "chuck" +# Add a bit of cruft in the action folders in order to ensure that we only +# care about the executables with the same name as the folder in which they +# reside. +touch .todo.actions.d/chuck/mc_hammer # can't touch this +chmod u+x .todo.actions.d/chuck/mc_hammer # better run, better run run +touch .todo.actions.d/chuck/README + +make_action_in_folder "norris" + +test_todo_session 'custom actions in subfolders' <>> test -f .todo.actions.d/chuck/README +=== 0 + +>>> test -x .todo.actions.d/chuck/mc_hammer +=== 0 + +>>> todo.sh listaddons +bar +chuck +ls +norris +quux +EOF + +# nthorne: shamelessly stolen from above.. +chmod -x .todo.actions.d/norris/norris +# On Cygwin, clearing the executable flag may have no effect, as the Windows ACL +# may still grant execution rights. In this case, we skip the test. +if [ -x .todo.actions.d/norris/norris ]; then + SKIP_TESTS="${SKIP_TESTS}${SKIP_TESTS+ }t8010.8" +fi +test_todo_session 'nonexecutable action in subfolder' <>> todo.sh listaddons +bar +chuck +ls +quux +EOF + test_done diff --git a/todo.sh b/todo.sh index 6d7d549..1aa7293 100755 --- a/todo.sh +++ b/todo.sh @@ -302,6 +302,14 @@ addonHelp() didPrintAddonActionsHeader=1 fi "$action" usage + elif [ -d "$action" -a -x "$action/$(basename $action)" ]; then + if [ ! "$didPrintAddonActionsHeader" ]; then + cat <<-EndAddonActionsHeader + Add-on Actions: + EndAddonActionsHeader + didPrintAddonActionsHeader=1 + fi + "$action/$(basename $action)" usage fi done fi @@ -314,6 +322,8 @@ actionUsage() action="${TODO_ACTIONS_DIR}/${actionName}" if [ -f "$action" -a -x "$action" ]; then "$action" usage + elif [ -d "$action" -a -x "$action/$(basename $action)" ]; then + "$action/$(basename $action)" usage else builtinActionUsage=$(actionsHelp | sed -n -e "/^ ${actionName//\//\\/} /,/^\$/p" -e "/^ ${actionName//\//\\/}$/,/^\$/p") if [ "$builtinActionUsage" ]; then @@ -964,6 +974,10 @@ then shift ## Reset action to new first argument action=$( printf "%s\n" "$1" | tr 'A-Z' 'a-z' ) +elif [ -d "$TODO_ACTIONS_DIR/$action" -a -x "$TODO_ACTIONS_DIR/$action/$action" ] +then + "$TODO_ACTIONS_DIR/$action/$action" "$@" + exit $? elif [ -d "$TODO_ACTIONS_DIR" -a -x "$TODO_ACTIONS_DIR/$action" ] then "$TODO_ACTIONS_DIR/$action" "$@" @@ -1405,6 +1419,8 @@ note: PRIORITY must be anywhere from A to Z." do if [ -f "$action" -a -x "$action" ]; then echo "$action" + elif [ -d "$action" -a -x "$action/$action" ]; then + echo "$action" fi done fi