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() { run_command() {
COMMAND="$@" INPUT="$1"
COMMAND="$2"
FIRST=${COMMAND%%" "*} FIRST=${COMMAND%%" "*}
REST=${COMMAND#*" "} REST=${COMMAND#*" "}
SCRIPTS="$(get_scripts_for_cmd "$REST")" SCRIPTS="$(get_scripts_for_cmd "$INPUT")"
if [ -z "$SCRIPTS" ] || \ if [ -z "$SCRIPTS" ] || \
[ "$(echo "$SCRIPTS" | wc -w)" -gt "1" ]; then [ "$(echo "$SCRIPTS" | wc -w)" -gt "1" ]; then
echo "Scripts matched: $SCRIPTS" echo "Scripts matched: $SCRIPTS"
exit 0 exit 0
fi fi
"$Q_SCRIPT_DIR/$SCRIPTS" --run "$FIRST" "$REST" "$Q_SCRIPT_DIR/$SCRIPTS" --run "$INPUT" "$FIRST" "$REST"
} }
run_command_cli() { run_command_cli() {
@ -164,7 +165,7 @@ while (( "$#" )); do
if [[ -z "$@" ]]; then if [[ -z "$@" ]]; then
exit 0 exit 0
fi fi
run_command "$@" run_command "$1" "$2"
exit 0 exit 0
;; ;;
-p|--preview) -p|--preview)
@ -203,7 +204,9 @@ if [[ -z "$COMMAND" ]]; then
--preview "$SELF -p {}" \ --preview "$SELF -p {}" \
--with-nth="2..-1" \ --with-nth="2..-1" \
--preview-window wrap \ --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 else
run_command_cli "$COMMAND" run_command_cli "$COMMAND"
fi fi

View file

@ -5,19 +5,19 @@ if [[ -z "$@" ]]; then
elif [[ "$1" == "--hint" ]]; then elif [[ "$1" == "--hint" ]]; then
shift shift
if [[ -f ~/.bookmarks.txt ]]; then 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 fi
elif [[ "$1" == "--complete" ]]; then elif [[ "$1" == "--complete" ]]; then
shift shift
if [[ -f ~/.bookmarks.txt ]]; then 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 fi
elif [[ "$1" == "--preview" ]]; then elif [[ "$1" == "--preview" ]]; then
shift shift
echo "$1" echo "$1"
elif [[ "$1" == "--run" ]]; then elif [[ "$1" == "--run" ]]; then
shift shift
xdg-open "$1" xdg-open "$2"
else else
echo "Unexpected arguments: $@" echo "Unexpected arguments: $@"
fi fi

View file

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

4
q-calc
View file

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

2
q-cam
View file

@ -26,7 +26,7 @@ elif [[ "$1" == "--preview" ]]; then
elif [[ "$1" == "--run" ]]; then elif [[ "$1" == "--run" ]]; then
shift 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 else
echo "Unexpected arguments: $@" echo "Unexpected arguments: $@"
fi fi

View file

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

View file

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

2
q-pass
View file

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

2
q-run
View file

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