From 2c0d74ef879f79ac61dbe364ec7be7768045d07f Mon Sep 17 00:00:00 2001 From: HernanIbarraMejia <72063731+HernanIbarraMejia@users.noreply.github.com> Date: Sat, 24 May 2025 08:56:39 +0100 Subject: [PATCH] Add improved script for i3 menu (give focus to window, and don't spawn multiple instances) --- Examples.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Examples.md b/Examples.md index 2494eaa..a36dc7a 100644 --- a/Examples.md +++ b/Examples.md @@ -2154,6 +2154,38 @@ This, however, will likely not use `FZF_DEFAULT_OPTIONS` because i3-dmenu-deskto ``` bindsym $mod+d exec --no-startup-id urxvt -title 'fzf-menu' -e i3-dmenu-desktop --dmenu='zsh -i -c fzf' ``` +Better, but not good enough: +- Focus is sometimes not given to the menu, particularly if your workspace is in full screen +- Pressing this key more than once (maybe because focus was not given and we don't realise the menu was actually open) will spawn many instances of the menu, which we don't want. It would be better to give focus to the running instance instead. + +Solving both problems: +```zsh +#!/usr/bin/env zsh + +# WARN: Some zshisms here won't work in bash. +# Maybe some basher can provide an equivalent bash script. + +focus_fmenu() { i3-msg --quiet '[title="fmenu"] focus' } + +focus_fmenu && exit 0 + +# Extra safety in case the window exists but i3 can't focus for some reason. +# Can be left out if you don't have/want to install xdotool +xdotool search --name fmenu && exit 1 + +urxvt -title 'fmenu' -e i3-dmenu-desktop --dmenu='zsh -i -c fzf' &| + +# Attempt to focus newly created window +repeat 5; do + focus_fmenu && exit 0 + sleep 0.2 +done +``` +Put the above script in your PATH under the name fmenu. Don't forget to include these lines in your i3 config: +``` +bindsym $mod+d exec fmenu +for_window [title="fmenu"] floating enable +``` ### Man pages Quickly display a man page using fzf and fd.