Add an alternative action with alt-enter

This commit is contained in:
Konstantin Nazarov 2024-11-20 07:08:16 +00:00
parent c4dba18172
commit 3e129a1267
Signed by: knazarov
GPG key ID: 4CFE0A42FA409C22
9 changed files with 22 additions and 17 deletions

13
q
View file

@ -111,16 +111,17 @@ complete_command() {
}
run_command() {
COMMAND="$@"
INPUT="$1"
COMMAND="$2"
FIRST=${COMMAND%%" "*}
REST=${COMMAND#*" "}
SCRIPTS="$(get_scripts_for_cmd "$REST")"
SCRIPTS="$(get_scripts_for_cmd "$INPUT")"
if [ -z "$SCRIPTS" ] || \
[ "$(echo "$SCRIPTS" | wc -w)" -gt "1" ]; then
echo "Scripts matched: $SCRIPTS"
exit 0
fi
"$Q_SCRIPT_DIR/$SCRIPTS" --run "$FIRST" "$REST"
"$Q_SCRIPT_DIR/$SCRIPTS" --run "$INPUT" "$FIRST" "$REST"
}
run_command_cli() {
@ -164,7 +165,7 @@ while (( "$#" )); do
if [[ -z "$@" ]]; then
exit 0
fi
run_command "$@"
run_command "$1" "$2"
exit 0
;;
-p|--preview)
@ -203,7 +204,9 @@ if [[ -z "$COMMAND" ]]; then
--preview "$SELF -p {}" \
--with-nth="2..-1" \
--preview-window wrap \
--tiebreak=index | xargs -o "$SELF" -r
--tiebreak=index \
--print-query \
--bind 'alt-enter:print-query' | xargs -o -d "\n" -n 2 "$SELF" -r
else
run_command_cli "$COMMAND"
fi

View file

@ -5,19 +5,19 @@ if [[ -z "$@" ]]; then
elif [[ "$1" == "--hint" ]]; then
shift
if [[ -f ~/.bookmarks.txt ]]; then
cat ~/.bookmarks.txt | awk '{print $1 " b " $2}'
cat ~/.bookmarks.txt | awk '{printf("%s b", $1); for (i=2; i<=NF; i++) printf(" %s", $i); print("");}'
fi
elif [[ "$1" == "--complete" ]]; then
shift
if [[ -f ~/.bookmarks.txt ]]; then
cat ~/.bookmarks.txt | awk '{print $1 " b " $2}'
cat ~/.bookmarks.txt | awk '{printf("%s b", $1); for (i=2; i<=NF; i++) printf(" %s", $i); print("");}'
fi
elif [[ "$1" == "--preview" ]]; then
shift
echo "$1"
elif [[ "$1" == "--run" ]]; then
shift
xdg-open "$1"
xdg-open "$2"
else
echo "Unexpected arguments: $@"
fi

View file

@ -13,6 +13,6 @@ elif [[ "$1" == "--preview" ]]; then
echo "Will open '$URL' in firefox"
elif [[ "$1" == "--run" ]]; then
shift
URL="$(echo "$@" | cut -d ' ' -f3-)"
setsid -f xdg-open "$URL"
URL="$(echo "$1" | cut -d ' ' -f2-)"
setsid -f firefox "$URL"
fi

4
q-calc
View file

@ -23,8 +23,8 @@ elif [[ "$1" == "--preview" ]]; then
echo "$1"
elif [[ "$1" == "--run" ]]; then
shift
echo "$1"
echo "$1" | (setsid -f wl-copy)
echo "$2"
echo "$2" | (setsid -f wl-copy)
elif [[ "$1" == "--cli" ]]; then
shift
calc "$(echo "$@" | cut -d ' ' -f2-)"

2
q-cam
View file

@ -26,7 +26,7 @@ elif [[ "$1" == "--preview" ]]; then
elif [[ "$1" == "--run" ]]; then
shift
echo "file://$CAMERA_DIR/$1" | setsid -f wl-copy -t text/uri-list
echo "file://$CAMERA_DIR/$2" | setsid -f wl-copy -t text/uri-list
else
echo "Unexpected arguments: $@"
fi

View file

@ -17,7 +17,7 @@ elif [[ "$1" == "--preview" ]]; then
echo "$1" | base64 -d
elif [[ "$1" == "--run" ]]; then
shift
TEXT="$(echo "$1" | base64 -d)"
TEXT="$(echo "$2" | base64 -d)"
echo "$TEXT"
echo -n "$TEXT" | (setsid -f wl-copy)
else

View file

@ -16,7 +16,9 @@ elif [[ "$1" == "--preview" ]]; then
notes.sh -p "$1"
elif [[ "$1" == "--run" ]]; then
shift
setsid -f foot "$NOTES_SH" -e "$1"
INPUT="$(echo "$1" | sed 's/^n //g')"
setsid -f foot "$NOTES_SH" -f "$INPUT" "$2"
else
echo "Unexpected arguments: $@"
fi

2
q-pass
View file

@ -25,6 +25,6 @@ elif [[ "$1" == "--run" ]]; then
# This will be triggered when enter is pressed on
# one of the options. We now decrypt the password
# and place it to the clipboard.
NAME="$1"
NAME="$2"
pass "$NAME" | (setsid -f wl-copy)
fi

2
q-run
View file

@ -18,5 +18,5 @@ elif [[ "$1" == "--preview" ]]; then
echo "Will run $1"
elif [[ "$1" == "--run" ]]; then
shift
setsid -f "$1"
setsid -f "$2"
fi