mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-15 14:53:47 -05:00
Add improved script for i3 menu (give focus to window, and don't spawn multiple instances)
32
Examples.md
32
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.
|
||||
|
||||
Reference in New Issue
Block a user