aboutsummaryrefslogtreecommitdiffstats
path: root/sway-launcher-desktop.sh
diff options
context:
space:
mode:
Diffstat (limited to 'sway-launcher-desktop.sh')
-rwxr-xr-xsway-launcher-desktop.sh74
1 files changed, 57 insertions, 17 deletions
diff --git a/sway-launcher-desktop.sh b/sway-launcher-desktop.sh
index 4b21c7d..3f00794 100755
--- a/sway-launcher-desktop.sh
+++ b/sway-launcher-desktop.sh
@@ -16,13 +16,44 @@ 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"
# Provider config entries are separated by the field separator \034 and have the following structure:
-# list_cmd,launch_cmd
+# list_cmd,preview_cmd,launch_cmd
declare -A PROVIDERS
-PROVIDERS['desktop']="${0} list-entries${DEL}${0} generate-command"
-PROVIDERS['command']="${0} list-commands${DEL}${0} command-line"
+if [ -f "${CONFIG_DIR}/providers.conf" ]; then
+ PARSED=$( awk -F= '
+ BEGINFILE{ provider=""; }
+ /^\[.*\]/{sub("^\\[", "");sub("\\]$", "");provider=$0}
+ /^(launch|list|preview)_cmd/{st = index($0,"=");providers[provider][$1] = substr($0,st+1)}
+ ENDFILE{
+ for (key in providers){
+ if(!("list_cmd" in providers[key])){continue;}
+ if(!("launch_cmd" in providers[key])){continue;}
+ if(!("preview_cmd" in providers[key])){continue;}
+ for (entry in providers[key]){
+ # gsub(/\$/,"\\$", providers[key][entry])
+ # gsub(/"/,"\\\"", providers[key][entry])
+ # gsub("\047",sq, providers[key][entry])
+ # gsub("\x27",sq, providers[key][entry])
+ # gsub(/\047/,sq, providers[key][entry])
+ gsub(/[\x27,\047]/,"\x27\"\x27\"\x27", providers[key][entry])
+ # gsub(/\047/,"DURR", providers[key][entry])
+ }
+ 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")
+ echo "$PARSED"
+ eval "$PARSED"
+else
+ PROVIDERS['desktop']="${0} list-entries${DEL}${0} describe-desktop${DEL}${0} generate-command"
+ PROVIDERS['command']="${0} list-commands${DEL}${0} describe-command${DEL}${0} command-line"
+fi
+#for i in "${!PROVIDERS[@]}"; do
+# echo "${i}=${PROVIDERS[$i]}"
+#done
+#exit
touch "$HIST_FILE"
readarray HIST_LINES <"$HIST_FILE"
@@ -30,20 +61,27 @@ function command-line() {
echo "${TERMINAL_COMMAND} ${1}"
}
function describe() {
- if [[ $2 == 'command' ]]; then
- title=$1
- readarray arr < <(whatis -l "$1" 2>/dev/null)
- description="${arr[0]}"
- description="${description%*-}"
- else
- title=$(sed -ne '/^Name=/{s/^Name=//;p;q}' "$1")
- description=$(sed -ne '/^Comment=/{s/^Comment=//;p;q}' "$1")
- fi
+ # shellcheck disable=SC2086
+ readarray -d ${DEL} -t PROVIDER_ARGS <<<${PROVIDERS[${1}]}
+ # shellcheck disable=SC2086
+ [ -n "${PROVIDER_ARGS[1]}" ] && eval "${PROVIDER_ARGS[1]} ${2}"
+}
+function describe-desktop() {
+ description=$(sed -ne '/^Comment=/{s/^Comment=//;p;q}' "$1")
+ echo -e "\033[33m$(sed -ne '/^Name=/{s/^Name=//;p;q}' "$1")\033[0m"
+ echo "${description:-No description}"
+}
+function describe-command() {
+ title=$1
+ readarray arr < <(whatis -l "$1" 2>/dev/null)
+ description="${arr[0]}"
+ description="${description%*-}"
echo -e "\033[33m$title\033[0m"
echo "${description:-No description}"
}
function provide() {
+ # shellcheck disable=SC2086
readarray -d ${DEL} -t PROVIDER_ARGS <<<${PROVIDERS[$1]}
eval "${PROVIDER_ARGS[0]}"
}
@@ -128,7 +166,7 @@ function generate-command() {
# 3. We see an Exec= line during search: remove field codes and set variable
# 3. We see a Path= line during search: set variable
# 4. Finally, build command line
- awk -v pattern="${PATTERN}" -v terminal_command="${TERMINAL_COMMAND}" -F= '
+ awk -v pattern="${PATTERN}" -v terminal_cmd="${TERMINAL_COMMAND}" -F= '
BEGIN{a=0;exec=0;path=0}
/^\[Desktop/{
if(a){
@@ -162,14 +200,14 @@ function generate-command() {
printf "cd " path " && "
}
if (terminal){
- printf terminal_command " "
+ printf terminal_cmd " "
}
print exec
}' "$1"
}
case "$1" in
-describe | entries | list-entries | list-commands | command-line | generate-command | provide)
+describe | describe-desktop | describe-command | entries | list-entries | list-commands | command-line | generate-command | provide)
"$@"
exit
;;
@@ -183,11 +221,13 @@ trap 'rm "$FZFPIPE"' EXIT INT
(printf '%s' "${HIST_LINES[@]#* }" >>"$FZFPIPE") &
# Iterate over providers and run their list-command
-for PROVIDER_NAME in "${!PROVIDERS[@]}"; do (bash -c "${0} provide ${PROVIDER_NAME}" >>"$FZFPIPE") & done
+for PROVIDER_NAME in "${!PROVIDERS[@]}"; do
+ (bash -c "${0} provide ${PROVIDER_NAME}" >>"$FZFPIPE") &
+done
COMMAND_STR=$(
fzf +s -x -d '\034' --nth ..3 --with-nth 3 \
- --preview "$0 describe {1} {2}" \
+ --preview "$0 describe {2} {1}" \
--preview-window=up:3:wrap --ansi \
<"$FZFPIPE"
) || exit 1