From 1185ab1d5e501a228e0164899600e028e6428165 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Thu, 16 Sep 2021 21:38:47 +0200 Subject: [PATCH] Refactoring: Extract hasCustomAction() --- todo.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/todo.sh b/todo.sh index fb8d4bc..37eca5e 100755 --- a/todo.sh +++ b/todo.sh @@ -1036,6 +1036,11 @@ listWordsWithSigil() | sort -u } +hasCustomAction() +{ + [ -d "${1:?}" ] && [ -x "${1:?}/${2:?}" ] +} + export -f cleaninput getPrefix getTodo getNewtodo shellquote filtercommand _list listWordsWithSigil getPadding _format die # == HANDLE ACTION == @@ -1051,11 +1056,11 @@ then shift ## Reset action to new first argument 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 "$TODO_ACTIONS_DIR/$action/$action" "$@" exit $? -elif [ -d "$TODO_ACTIONS_DIR" ] && [ -x "$TODO_ACTIONS_DIR/$action" ] +elif hasCustomAction "$TODO_ACTIONS_DIR" "$action" then "$TODO_ACTIONS_DIR/$action" "$@" exit $?