Add a custom launcher based on fzf
This commit is contained in:
parent
ccb984b063
commit
54c262eca2
6 changed files with 84 additions and 10 deletions
11
README.md
11
README.md
|
@ -1,10 +1,17 @@
|
|||
Sway sesktop configuration
|
||||
Sway desktop configuration
|
||||
--------------------------
|
||||
|
||||
This repository contain all configuration for my desktop : [sway][l_sway] (and
|
||||
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
|
||||
|
|
64
bin/launcher.sh
Executable file
64
bin/launcher.sh
Executable file
|
@ -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"
|
||||
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<Paste>
|
||||
|
||||
# switch to workspace
|
||||
bindsym $mod+1 workspace $ws1
|
||||
bindsym $mod+2 workspace $ws2
|
||||
|
|
|
@ -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"
|
||||
|
|
Reference in a new issue