From 54c262eca2d22735cdcc5b69b16b330d818b740a Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Sat, 7 Sep 2019 01:04:15 +0200 Subject: [PATCH] Add a custom launcher based on fzf --- README.md | 13 +++++-- bin/launcher.sh | 64 +++++++++++++++++++++++++++++++++ conf/gtk-2.0/gtkfilechooser.ini | 8 ++--- conf/sway/conf.d/morty.config | 3 +- conf/sway/config | 4 ++- install.sh | 2 +- 6 files changed, 84 insertions(+), 10 deletions(-) create mode 100755 bin/launcher.sh diff --git a/README.md b/README.md index 31e3fb2..5cf58fb 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,17 @@ -Sway sesktop configuration +Sway desktop configuration -------------------------- -This repository contain all configuration for my desktop : [sway][l_sway] (and -swaylock, swayidle), [mako][l_mako] and [waybar][l_waybar]. Execute +This repository contain all configurations for my desktop : [sway][l_sway] (and +swaylock, swayidle), [mako][l_mako] and [waybar][l_waybar]. Execute `install.sh` install it properly. +## Launcher + +I use a custom launcher based on fzf with a script taken from +[FlyingWombat][l_won] with some light modifications. + [l_sway]:https://swayvm.org [l_mako]:https://wayland.emersion.fr/mako/ [l_waybar]:https://github.com/Alexays/Waybar +[l_fzf]: https://gitlab.com/FlyingWombat/my-scripts/blob/master/sway-launcher +[l_won]: https://gitlab.com/FlyingWombat/my-scripts/blob/master/sway-launcher diff --git a/bin/launcher.sh b/bin/launcher.sh new file mode 100755 index 0000000..21ca1cd --- /dev/null +++ b/bin/launcher.sh @@ -0,0 +1,64 @@ +#!/bin/sh +# terminal application launcher for sway, using fzf +# original command: +# Based on: https://github.com/swaywm/sway/issues/1367 +# bindsym $altkey+space exec termite --name=launcher -e \ +# "bash -c 'compgen -c | sort -u | fzf --no-extended --print-query | \ +# tail -n1 | xargs -r swaymsg -t command exec'" + +HIST_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/sway-launcher-history.txt" +FZF_OPTIONS="--layout=reverse --no-extended --print-query --no-sort" + +# Get shell command list +# This may include the occasional non-executable file +# command_list=$({ IFS=:; ls -H $PATH; } | grep -v '/.*' | sort -u) +command_list=$(find $(echo $PATH | tr ':' ' ') -type f -executable -printf "\n%f") +# read existing command history +if [ -f "$HIST_FILE" ]; then + command_history=$(cat "$HIST_FILE") +else + command_history="" +fi + +# search command list +command_str=$(printf "%s\n" "${command_history}" "${command_list}" | \ + sed -E 's/^[0-9]+ (.+)$/\1/' | \ + fzf $FZF_OPTIONS | \ + tail -n1) || exit 1 + +if [ "$command_str" = "" ]; then + exit 1 +fi +# echo "Command: $command_str" + +# using \E flag from perl regex +test "${command_str#*\\E}" != "$command_str" && echo "command can't contain '\E'" +test "${command_str#*\\E}" != "$command_str" && exit 1 + +# get full line from history (with count number) +hist_line=$(echo "$command_history" | grep -Pe "^[0-9]+ \Q$command_str\E$") +# echo "Hist Line: $hist_line" + +if [ "$hist_line" = "" ]; then + hist_count=1 +else + # Increment usage count + hist_count=$(echo "$hist_line" | sed -E 's/^([0-9]+) .+$/\1/') + hist_count=$((hist_count + 1)) + # delete line, to add updated later + # echo "Hist Before: $command_history" + command_history=$(echo "$command_history" | \ + grep --invert-match -Pe "^[0-9]+ \Q$command_str\E$") + # echo "Hist After: $command_history" +fi + +# update history +update_line="${hist_count} ${command_str}" +printf "%s\n" "${update_line}" "${command_history}" | \ + sort --numeric-sort --reverse > "$HIST_FILE" +# echo "$update_line" + +# execute command +echo "$command_str" +swaymsg -t command exec "$command_str" + diff --git a/conf/gtk-2.0/gtkfilechooser.ini b/conf/gtk-2.0/gtkfilechooser.ini index b4e0459..c522196 100644 --- a/conf/gtk-2.0/gtkfilechooser.ini +++ b/conf/gtk-2.0/gtkfilechooser.ini @@ -2,10 +2,10 @@ LocationMode=filename-entry ShowHidden=false ShowSizeColumn=true -GeometryX=0 -GeometryY=0 -GeometryWidth=640 -GeometryHeight=516 +GeometryX=282 +GeometryY=194 +GeometryWidth=876 +GeometryHeight=538 SortColumn=name SortOrder=descending StartupMode=recent diff --git a/conf/sway/conf.d/morty.config b/conf/sway/conf.d/morty.config index bd5229d..29675b7 100644 --- a/conf/sway/conf.d/morty.config +++ b/conf/sway/conf.d/morty.config @@ -1,3 +1,4 @@ set $term termite -output * bg ~/Documents/ressources/wallpapers/building_cyberpunk.jpg fill +set $menu exec $term --name=launcher -e launcher.sh +output * bg ~/Documents/ressources/wallpapers/building_cyberpunk.jpg fill diff --git a/conf/sway/config b/conf/sway/config index f5fd9c3..3b29722 100644 --- a/conf/sway/config +++ b/conf/sway/config @@ -3,7 +3,7 @@ set $left h set $down j set $up k set $right l -set $menu rofi -location 0 -show combi ~/.config/i3/rofi.config + gaps inner 5 @@ -60,6 +60,8 @@ assign [app_id="^firefox$"] $ws3 assign [class="keepassxc"] $ws3 assign [app_id="org.remmina.*"] $ws5 +for_window [app_id="^launcher$"] floating enable, border none + # switch to workspace bindsym $mod+1 workspace $ws1 bindsym $mod+2 workspace $ws2 diff --git a/install.sh b/install.sh index ea1c98a..90c6b9b 100755 --- a/install.sh +++ b/install.sh @@ -1,6 +1,6 @@ #!/bin/bash -required="sway swayidle swaylock waybar" +required="sway swayidle swaylock waybar fzf" BIN_FOLDER="$HOME/.local/bin" printf "Checking required programs :\n"