m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-16 23:33:39 -05:00

Add fzfmenu selector which accepts piped arguments in a floating window like dmenu/rofi

RayZ0rr
2022-08-22 04:36:10 +05:30
parent 9f44f48dd0
commit d152572889

@@ -44,6 +44,7 @@ Table of Contents
* [dictcc translation](#dictcc-translation)
* [kubectl](#kubectl)
* Moving from other tools
* [fzf as selector menu (pipe entries like dmenu/rofi)](#fzf-as-selector-menu)
* [fzf as rofi replacement](#fzf-as-rofi-replacement)
* [fzf as dmenu replacement](#fzf-as-dmenu-replacement)
* [ctags](#ctags)
@@ -1773,6 +1774,59 @@ fbehave() {
--bind 'tab:execute(echo {} | cut -f1 | awk "{\$1=\$1};1" | pbcopy )'
}
```
### fzf as selector menu
Make a script like this (`~/.local/bin/fzfmenu`):
```bash
#!/usr/bin/env bash
export FZF_DEFAULT_OPTS="--height=100% --layout=reverse --border --no-sort --prompt=\"~ \" --color=dark,hl:red:regular,fg+:white:regular,hl+:red:regular:reverse,query:white:regular,info:gray:regular,prompt:red:bold,pointer:red:bold"
exec alacritty --class="fzf-menu" -e bash -c "fzf-tmux -m $* < /proc/$$/fd/0 | awk 'BEGIN {ORS=\" \"} {print}' > /proc/$$/fd/1"
# For st instead
# st -c fzf-menu -n fzf-menu -e bash -c "fzf-tmux -m $* < /proc/$$/fd/0 | awk 'BEGIN {ORS=\" \"} {print}' > /proc/$$/fd/1"
```
1. Then to run as app launcher, use [sxhkd](https://github.com/baskerville/sxhkd) and put in `~/.config/sxhkdrc`
```
# run apps launcher
control + alt + s ; r
dmenu_path | ~/.local/bin/fzfmenu | bash
```
( You can use anything other than `dmenu_path` that gets a list of entries in `$PATH` too.)
2. To use for `Ctrl-t` for a floating menu from terminal
**For bash**
```bash
__fzfmenu__() {
local cmd="fd -tf --max-depth=1"
eval "$cmd" | ~/.local/bin/fzfmenu
}
__fzf-menu__() {
local selected="$(__fzfmenu__)"
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}"
READLINE_POINT=$(( READLINE_POINT + ${#selected} ))
}
bind -x '"\C-t":"__fzf-menu__"'
```
**For zsh**
```zsh
__fzfmenu__(){
local cmd="fd -tf --max-depth=1"
eval $cmd | ~/.local/bin/fzfmenu
}
__fzf-menu__() {
LBUFFER="${LBUFFER}$(__fzfmenu__)"
local ret=$?
zle reset-prompt
return $ret
}
zle -N __fzf-menu__
bindkey -M emacs '^T^G' __fzf-menu__
bindkey -M vicmd '^T^G' __fzf-menu__
bindkey -M viins '^T^G' __fzf-menu__
```
## fzf as rofi replacement
https://github.com/gotbletu/shownotes/blob/master/fzf_nova/fzf-nova