diff options
| author | Moritz Meißelbach <arbelzapf@gmail.com> | 2021-01-21 23:31:58 +0100 |
|---|---|---|
| committer | Moritz Meißelbach <arbelzapf@gmail.com> | 2021-01-21 23:31:58 +0100 |
| commit | 1ac6d768619aab8e80c63d47e69aa65f27aa47ce (patch) | |
| tree | f183a7ead12a5f985219e93436ad09f6271b4b59 | |
| parent | 0c6cc8103834f6ac3ec91cbec2e5eae69fd2a9e4 (diff) | |
| download | sway-launcher-desktop-1ac6d768619aab8e80c63d47e69aa65f27aa47ce.tar.gz sway-launcher-desktop-1ac6d768619aab8e80c63d47e69aa65f27aa47ce.zip | |
#31 #27 #28 Allow arbitrary commands
| -rw-r--r-- | README.md | 1 | ||||
| -rwxr-xr-x | sway-launcher-desktop.sh | 15 |
2 files changed, 14 insertions, 2 deletions
@@ -14,6 +14,7 @@ Despite its name, it does not (read: no longer) depend on the Sway window manage - Colored output and glyphs for the different entry types - Entries are lazily piped into fzf eliminating any lag during startup - Optional support for the XDG Autostart specification +- Executes arbitrary custom commands (if there are no other matches) ## Installation diff --git a/sway-launcher-desktop.sh b/sway-launcher-desktop.sh index 351aaa5..df25e92 100755 --- a/sway-launcher-desktop.sh +++ b/sway-launcher-desktop.sh @@ -51,6 +51,7 @@ else HIST_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/${0##*/}-history.txt" fi fi +PROVIDERS['user']="exit${DEL}exit${DEL}{1}" # Fallback provider that simply executes the exact command if there were no matches if [[ -n "${HIST_FILE}" ]]; then mkdir -p "${HIST_FILE%/*}" && touch "$HIST_FILE" @@ -255,8 +256,9 @@ for PROVIDER_NAME in "${!PROVIDERS[@]}"; do (bash -c "${0} provide ${PROVIDER_NAME}" >>"$FZFPIPE") & done -COMMAND_STR=$( +readarray -t COMMAND_STR <<<$( fzf --ansi +s -x -d '\034' --nth ..3 --with-nth 3 \ + --print-query \ --preview "$0 describe {2} {1}" \ --preview-window=up:2:noborder \ --no-multi --cycle \ @@ -265,10 +267,19 @@ COMMAND_STR=$( --color='16,gutter:-1' \ <"$FZFPIPE" ) || exit 1 +# Get the last line of the fzf output. If there were no matches, it contains the query which we'll treat as a custom command +# If there were matches, it contains the selected item +COMMAND_STR=$(printf '%s\n' "${COMMAND_STR[@]: -1}") +# We still need to format the query to conform to our fallback provider. +# We check for the presence of field separator character to determine if we're dealing with a custom command +if [[ $COMMAND_STR != *$'\034'* ]]; then + COMMAND_STR="${COMMAND_STR}"$'\034user\034'"${COMMAND_STR}"$'\034' + SKIP_HIST=1 # I chose not to include custom commands in the history. If this is a bad idea, open an issue please +fi [ -z "$COMMAND_STR" ] && exit 1 -if [[ -n "${HIST_FILE}" ]]; then +if [[ -n "${HIST_FILE}" && ! "$SKIP_HIST" ]]; then # update history for i in "${!HIST_LINES[@]}"; do if [[ "${HIST_LINES[i]}" == *" $COMMAND_STR"$'\n' ]]; then |
