Skip to content

Commit

Permalink
Merge branch 's-hamann-switchable-providers'
Browse files Browse the repository at this point in the history
  • Loading branch information
Biont committed Dec 17, 2019
2 parents d475d74 + 53197d2 commit 7ba43fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,7 @@ The `list_cmd` generated the list of entries. For each entry, it has to print th

The `preview_cmd` renders the contents of the `fzf` preview panel. You can use the template variable `{1}` in your command, which will be substituted with the value of the selected item.

The `launch_cmd` is fired when the user has selected one of the provider's entries.
The `launch_cmd` is fired when the user has selected one of the provider's entries.

Note: Pass the environment variable `PROVIDERS_FILE` to read custom providers from another file than the default `providers.conf`.
The path in `PROVIDERS_FILE` can either be absolute or relative to `${HOME}/.config/sway-launcher-desktop/`.
12 changes: 9 additions & 3 deletions sway-launcher-desktop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ DEL=$'\34'
TERMINAL_COMMAND="${TERMINAL_COMMAND:="urxvt -e"}"
GLYPH_COMMAND=""
GLYPH_DESKTOP=""
HIST_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/${0##*/}-history.txt"
CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/sway-launcher-desktop"
PROVIDERS_FILE="${PROVIDERS_FILE:=providers.conf}"
if [[ "${PROVIDERS_FILE#/}" == "${PROVIDERS_FILE}" ]]; then
# $PROVIDERS_FILE is a relative path, prepend $CONFIG_DIR
PROVIDERS_FILE="${CONFIG_DIR}/${PROVIDERS_FILE}"
fi

# Provider config entries are separated by the field separator \034 and have the following structure:
# list_cmd,preview_cmd,launch_cmd
declare -A PROVIDERS
if [ -f "${CONFIG_DIR}/providers.conf" ]; then
if [ -f "${PROVIDERS_FILE}" ]; then
eval "$(awk -F= '
BEGINFILE{ provider=""; }
/^\[.*\]/{sub("^\\[", "");sub("\\]$", "");provider=$0}
Expand All @@ -36,10 +40,12 @@ if [ -f "${CONFIG_DIR}/providers.conf" ]; then
}
print "PROVIDERS[\x27" key "\x27]=\x27" providers[key]["list_cmd"] "\034" providers[key]["preview_cmd"] "\034" providers[key]["launch_cmd"] "\x27\n"
}
}' "${CONFIG_DIR}/providers.conf")"
}' "${PROVIDERS_FILE}")"
HIST_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/${0##*/}-${PROVIDERS_FILE##*/}-history.txt"
else
PROVIDERS['desktop']="${0} list-entries${DEL}${0} describe-desktop '{1}'${DEL}${0} run-desktop '{1}' {2}"
PROVIDERS['command']="${0} list-commands${DEL}${0} describe-command {1}${DEL}${TERMINAL_COMMAND} {1}"
HIST_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/${0##*/}-history.txt"
fi

touch "$HIST_FILE"
Expand Down

0 comments on commit 7ba43fb

Please sign in to comment.