From d152572889c2b77ac18a223e69d5cd043fb72f08 Mon Sep 17 00:00:00 2001 From: RayZ0rr <96843787+RayZ0rr@users.noreply.github.com> Date: Mon, 22 Aug 2022 04:36:10 +0530 Subject: [PATCH] Add fzfmenu selector which accepts piped arguments in a floating window like dmenu/rofi --- Examples.md | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/Examples.md b/Examples.md index 3bd3c19..fbda92d 100644 --- a/Examples.md +++ b/Examples.md @@ -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