Refactoring: Extract hasCustomAction()

This commit is contained in:
Ingo Karkat
2021-09-16 21:38:47 +02:00
parent 7792006853
commit 1185ab1d5e

View File

@@ -1036,6 +1036,11 @@ listWordsWithSigil()
| sort -u | sort -u
} }
hasCustomAction()
{
[ -d "${1:?}" ] && [ -x "${1:?}/${2:?}" ]
}
export -f cleaninput getPrefix getTodo getNewtodo shellquote filtercommand _list listWordsWithSigil getPadding _format die export -f cleaninput getPrefix getTodo getNewtodo shellquote filtercommand _list listWordsWithSigil getPadding _format die
# == HANDLE ACTION == # == HANDLE ACTION ==
@@ -1051,11 +1056,11 @@ then
shift shift
## Reset action to new first argument ## Reset action to new first argument
action=$( printf "%s\n" "$1" | tr '[:upper:]' '[:lower:]' ) action=$( printf "%s\n" "$1" | tr '[:upper:]' '[:lower:]' )
elif [ -d "$TODO_ACTIONS_DIR/$action" ] && [ -x "$TODO_ACTIONS_DIR/$action/$action" ] elif hasCustomAction "$TODO_ACTIONS_DIR/$action" "$action"
then then
"$TODO_ACTIONS_DIR/$action/$action" "$@" "$TODO_ACTIONS_DIR/$action/$action" "$@"
exit $? exit $?
elif [ -d "$TODO_ACTIONS_DIR" ] && [ -x "$TODO_ACTIONS_DIR/$action" ] elif hasCustomAction "$TODO_ACTIONS_DIR" "$action"
then then
"$TODO_ACTIONS_DIR/$action" "$@" "$TODO_ACTIONS_DIR/$action" "$@"
exit $? exit $?