Fix default argument handling

This commit is contained in:
Konstantin Nazarov 2024-11-20 07:45:08 +00:00
parent 3e129a1267
commit 0ebd7c228c
Signed by: knazarov
GPG key ID: 4CFE0A42FA409C22

11
q
View file

@ -115,7 +115,16 @@ run_command() {
COMMAND="$2"
FIRST=${COMMAND%%" "*}
REST=${COMMAND#*" "}
SCRIPTS="$(get_scripts_for_cmd "$INPUT")"
if [ ! -z "$REST" ]; then
# This branch is taken in most cases when an existing
# item is selected in fzf
SCRIPTS="$(get_scripts_for_cmd "$REST")"
else
# In case when zero items have matched, but a command
# has support for a default action to take (e.g. creating
# a new entry) - use the actual user's input
SCRIPTS="$(get_scripts_for_cmd "$INPUT")"
fi
if [ -z "$SCRIPTS" ] || \
[ "$(echo "$SCRIPTS" | wc -w)" -gt "1" ]; then
echo "Scripts matched: $SCRIPTS"