aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Hamann <invalid>2019-12-17 09:23:06 +0100
committerSebastian Hamann <invalid>2019-12-17 09:23:06 +0100
commit1d5bce7e42ca853301719137b8d497d3051bf96a (patch)
treef339b7aec447fd7790bc9ddff5271d4b6dc11228
parente45f50830062ec5dcfd1325c511051b039eea634 (diff)
downloadsway-launcher-desktop-1d5bce7e42ca853301719137b8d497d3051bf96a.tar.gz
sway-launcher-desktop-1d5bce7e42ca853301719137b8d497d3051bf96a.zip
Support switching between different provider configs
-rw-r--r--README.md5
-rwxr-xr-xsway-launcher-desktop.sh12
2 files changed, 13 insertions, 4 deletions
diff --git a/README.md b/README.md
index 5e0de3e..6442d41 100644
--- a/README.md
+++ b/README.md
@@ -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. \ No newline at end of file
+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/`.
diff --git a/sway-launcher-desktop.sh b/sway-launcher-desktop.sh
index 59cce1b..becf7ba 100755
--- a/sway-launcher-desktop.sh
+++ b/sway-launcher-desktop.sh
@@ -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}
@@ -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"