Make arguments simpler to deal with in action functions

<source> was an optional argument, and the second out of three passed,
meaning when only two arguments were given, the action functions would
have to know to use the second argument as <target>, instead of the the
third. Now the second argument is always <target>, and the <source>
argument is always the third, if given.
This commit is contained in:
2014-03-08 13:32:24 +00:00
parent e0f0177301
commit e49c930771
2 changed files with 24 additions and 7 deletions

View File

@@ -1,17 +1,26 @@
dotify-action() {
local action="$1"
local source="$2"
local target="$3"
if [ $# -lt 3 ]; then
local target="$2"
else
local source="$2"
local target="$3"
fi
if [ "$action" == "default" ]; then
action="$DOTIFY_OPT_DEFAULT_ACTION"
fi
! valid_action="$(command -v "dotify-action-${action}")"
! local valid_action="$(command -v "dotify-action-${action}")"
if [ -z "$valid_action" ]; then
echo "ERROR: \"$action\" is not a valid action." >&2
return 1
fi
dotify-action-${action} "$source" "$target"
if [ -n "$source" ]; then
dotify-action-${action} "$DOTIFY_RUN_MODE" "$target" "$source"
else
dotify-action-${action} "$DOTIFY_RUN_MODE" "$target"
fi
}