From 6eb70a002377fa466703aacd444719e7fc9bf546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20Mei=C3=9Felbach?= Date: Mon, 14 Oct 2019 08:40:49 +0000 Subject: --- gistfile1.txt | 97 ------------------------------------------------ sway-launcher-desktop.sh | 97 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 97 deletions(-) delete mode 100644 gistfile1.txt create mode 100644 sway-launcher-desktop.sh diff --git a/gistfile1.txt b/gistfile1.txt deleted file mode 100644 index 8ceec7d..0000000 --- a/gistfile1.txt +++ /dev/null @@ -1,97 +0,0 @@ -#!/bin/sh -# terminal application launcher for sway, using fzf -# Based on: https://gitlab.com/FlyingWombat/my-scripts/blob/master/sway-launcher - -HIST_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/sway-launcher-history.txt" - -DIRS=( -/usr/share/applications -~/.local/share/applications -/usr/local/share/applications -) - -GLYPH_COMMAND=" " -GLYPH_DESKTOP=" " - -touch $HIST_FILE -# Filter DIRS array for directories that actually exist. Append *.desktop to remaining elements -for i in "${!DIRS[@]}" ; do [[ ! -d "${DIRS[i]}" ]] && unset -v 'DIRS[$i]' || DIRS[$i]="${DIRS[i]}/*.desktop" ; done -DIRS=("${DIRS[@]}") - -HIST_FILE_CONTENT=$(cat "$HIST_FILE") -HIST_ENTRIES=$(echo "$HIST_FILE_CONTENT" | sed -n -e 's/^[0-9]* //p') - -function createPreview(){ - DESCRIPTION='No description' - if [[ $2 == 'command' ]]; then - TITLE=$1 - DESCRIPTION=$(whatis -l $1 2>/dev/null | head -n1 | sed -n -e 's/^.*\(.*\).*\-//p') - else - TITLE=$(cat $1 | grep ^Name= | head -n1 | awk -F= '{print $2}') - DESCRIPTION=$(cat $1 | grep Comment= | awk -F= '{print $2}') - fi - echo -e "\033[33m $TITLE \033[0m" - echo "$DESCRIPTION" -} -export -f createPreview - -FZFPIPE=$(mktemp) - -# Append Launcher History, removing usage count -(echo "$HIST_FILE_CONTENT" | sed -n -e 's/^[0-9]* //p' >> $FZFPIPE )& - -# Load and append Desktop entries -(grep -roP "Type=Application" ${DIRS[@]} | - awk -F : '{print $1}' | - sort -u | - xargs -d "\n" grep -oP "(?<=Name=).*" | - awk -F : -v pre="$GLYPH_DESKTOP" '{print $1 "|desktop|\033[33m" pre "\033[0m" $2}' >> $FZFPIPE )& - -# Load and append command list -({ IFS=:; ls -H $PATH; } | grep -v '/.*' | sort -u | awk -v pre="$GLYPH_COMMAND" '{print $1 "|command|\033[31m" pre "\033[0m" $1 }' >> $FZFPIPE )& - -command_str=$((tail -f $FZFPIPE & echo $! > pid) | - fzf +x +s -d '\|' --nth ..3 --with-nth 3.. --preview 'createPreview {1} {2}' --preview-window=up:3:wrap --ansi ; kill -9 $( "$HIST_FILE" - -command='echo "nope"' - -case $(echo $command_str | awk -F'|' '{print $2}') in -desktop) - file=$(echo $command_str | awk -F '|' '{print $1}') - command=$(cat $file | grep Exec | awk -F'=' '{print $2}') - ;; - -command) - command=$(echo $command_str | awk -F '|' '{print $1}') - ;; - -esac - -swaymsg -t command exec "$command" diff --git a/sway-launcher-desktop.sh b/sway-launcher-desktop.sh new file mode 100644 index 0000000..8ceec7d --- /dev/null +++ b/sway-launcher-desktop.sh @@ -0,0 +1,97 @@ +#!/bin/sh +# terminal application launcher for sway, using fzf +# Based on: https://gitlab.com/FlyingWombat/my-scripts/blob/master/sway-launcher + +HIST_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/sway-launcher-history.txt" + +DIRS=( +/usr/share/applications +~/.local/share/applications +/usr/local/share/applications +) + +GLYPH_COMMAND=" " +GLYPH_DESKTOP=" " + +touch $HIST_FILE +# Filter DIRS array for directories that actually exist. Append *.desktop to remaining elements +for i in "${!DIRS[@]}" ; do [[ ! -d "${DIRS[i]}" ]] && unset -v 'DIRS[$i]' || DIRS[$i]="${DIRS[i]}/*.desktop" ; done +DIRS=("${DIRS[@]}") + +HIST_FILE_CONTENT=$(cat "$HIST_FILE") +HIST_ENTRIES=$(echo "$HIST_FILE_CONTENT" | sed -n -e 's/^[0-9]* //p') + +function createPreview(){ + DESCRIPTION='No description' + if [[ $2 == 'command' ]]; then + TITLE=$1 + DESCRIPTION=$(whatis -l $1 2>/dev/null | head -n1 | sed -n -e 's/^.*\(.*\).*\-//p') + else + TITLE=$(cat $1 | grep ^Name= | head -n1 | awk -F= '{print $2}') + DESCRIPTION=$(cat $1 | grep Comment= | awk -F= '{print $2}') + fi + echo -e "\033[33m $TITLE \033[0m" + echo "$DESCRIPTION" +} +export -f createPreview + +FZFPIPE=$(mktemp) + +# Append Launcher History, removing usage count +(echo "$HIST_FILE_CONTENT" | sed -n -e 's/^[0-9]* //p' >> $FZFPIPE )& + +# Load and append Desktop entries +(grep -roP "Type=Application" ${DIRS[@]} | + awk -F : '{print $1}' | + sort -u | + xargs -d "\n" grep -oP "(?<=Name=).*" | + awk -F : -v pre="$GLYPH_DESKTOP" '{print $1 "|desktop|\033[33m" pre "\033[0m" $2}' >> $FZFPIPE )& + +# Load and append command list +({ IFS=:; ls -H $PATH; } | grep -v '/.*' | sort -u | awk -v pre="$GLYPH_COMMAND" '{print $1 "|command|\033[31m" pre "\033[0m" $1 }' >> $FZFPIPE )& + +command_str=$((tail -f $FZFPIPE & echo $! > pid) | + fzf +x +s -d '\|' --nth ..3 --with-nth 3.. --preview 'createPreview {1} {2}' --preview-window=up:3:wrap --ansi ; kill -9 $( "$HIST_FILE" + +command='echo "nope"' + +case $(echo $command_str | awk -F'|' '{print $2}') in +desktop) + file=$(echo $command_str | awk -F '|' '{print $1}') + command=$(cat $file | grep Exec | awk -F'=' '{print $2}') + ;; + +command) + command=$(echo $command_str | awk -F '|' '{print $1}') + ;; + +esac + +swaymsg -t command exec "$command" -- cgit v1.2.3