mirror of
https://github.com/jimeh/dotify.git
synced 2026-02-19 10:06:39 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user