From 3e129a1267886cc8145ab6d337f35d14b4ff953e Mon Sep 17 00:00:00 2001 From: Konstantin Nazarov Date: Wed, 20 Nov 2024 07:08:16 +0000 Subject: [PATCH] Add an alternative action with alt-enter --- q | 13 ++++++++----- q-bookmarks | 6 +++--- q-browse | 4 ++-- q-calc | 4 ++-- q-cam | 2 +- q-clipboard | 2 +- q-notes | 4 +++- q-pass | 2 +- q-run | 2 +- 9 files changed, 22 insertions(+), 17 deletions(-) diff --git a/q b/q index 8119aa4..19e98c8 100755 --- a/q +++ b/q @@ -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 diff --git a/q-bookmarks b/q-bookmarks index 48e6308..4e71c28 100755 --- a/q-bookmarks +++ b/q-bookmarks @@ -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 diff --git a/q-browse b/q-browse index dc4bfe7..278d588 100755 --- a/q-browse +++ b/q-browse @@ -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 diff --git a/q-calc b/q-calc index 5a05d4b..f0fe2d7 100755 --- a/q-calc +++ b/q-calc @@ -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-)" diff --git a/q-cam b/q-cam index 6866794..816c87f 100755 --- a/q-cam +++ b/q-cam @@ -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 diff --git a/q-clipboard b/q-clipboard index e2692c2..cc94c9f 100755 --- a/q-clipboard +++ b/q-clipboard @@ -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 diff --git a/q-notes b/q-notes index b4ee37a..5d5b2c2 100755 --- a/q-notes +++ b/q-notes @@ -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 diff --git a/q-pass b/q-pass index 9ad66e6..d7ad096 100755 --- a/q-pass +++ b/q-pass @@ -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 diff --git a/q-run b/q-run index 2d45df5..9d47dbc 100755 --- a/q-run +++ b/q-run @@ -18,5 +18,5 @@ elif [[ "$1" == "--preview" ]]; then echo "Will run $1" elif [[ "$1" == "--run" ]]; then shift - setsid -f "$1" + setsid -f "$2" fi