Skip to content

Instantly share code, notes, and snippets.

@MahouShoujoMivutilde
Last active May 14, 2025 18:28
Show Gist options
  • Save MahouShoujoMivutilde/b1fa83bc234b68dd164cb6e843965d75 to your computer and use it in GitHub Desktop.
Save MahouShoujoMivutilde/b1fa83bc234b68dd164cb6e843965d75 to your computer and use it in GitHub Desktop.
fzf as dmenu replacement

fzf as dmenu replacement

Why? ...Because it's faster.

So you'll need:

  1. terminal that launches fast and supports custom class or window name. St fits the bill perfectly.

  2. window manager with an option to automatically put windows in center based on class or name. Most seem to have it.

#!/usr/bin/env bash
# fzfmenu - fzf as dmenu replacement
input=$(mktemp -u --suffix .fzfmenu.input)
output=$(mktemp -u --suffix .fzfmenu.output)
mkfifo $input
mkfifo $output
chmod 600 $input $output
# it's better to use st here (starts a lot faster than pretty much everything else)
# the ugly printf | sed thing is here to make args with quotes work.
# (e.g. --preview='echo {1}')
# sadly we can't use "$@" here directly because we are inside sh -c "..." call
# already
st -c fzfmenu -n fzfmenu -e sh -c "cat $input | fzf $(printf -- " '%s'" "$@" | sed "s/^ ''$//") | tee $output" & disown
# handle ctrl+c outside child terminal window
trap "kill $! 2>/dev/null; rm -f $input $output" EXIT
cat > $input
cat $output
@RayZ0rr
Copy link

RayZ0rr commented Sep 29, 2023

@eylles

alongwith this script I have been using another one like this:

fzfmenu

#!/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 floating-terminal bash -c "fzf-tmux -m $* < /proc/$$/fd/0 | awk '{print}' > /proc/$$/fd/1"

Here, floating-terminal is the floating-terminal from Seirdy but I modified to take optional class name for the terminal

#!/usr/bin/env bash

class_name="Fzf-Menu"
if [[ "$1" == "class" ]]; then
    class_name="$2"
fi

# This is the terminal program that term-dmenu runs. Some examples:
# alacritty --class $class_name -e "$@"
# kitty --class $class_name "$@"
# These examples give the window the "$class_name" class so you can make your window
# manager float anything with class "$class_name"

if [[ -z "$FLOATING_TERMINAL" ]]; then
  # find_alt() prints the first parameter recognized by `command -v`
  find_alt() {
    for i; do
      command -v "${i%% *}" >/dev/null && {
	echo "$i"
	      return 0
	    }
    done
    return 1
  }
  FLOATING_TERMINAL=$(find_alt "foot -a $class_name" "havoc" "alacritty --class=$class_name -e" "kitty --class=$class_name" "konsole" "gnome-terminal" "termite" "st -c $class_name" "xterm" "wezterm start --class=$class_name")
fi

if [[ "$1" == "class" ]]; then
    $FLOATING_TERMINAL "${@:2}"
else
    $FLOATING_TERMINAL "${@}"
fi

# vim:ft=sh

I use it as : <input args> | FzfMenu | <use output>. Eg:

find . -type f | fzfmenu | xargs -I{} nvim {}
dmenu_path | fzfmenu | bash

@eylles
Copy link

eylles commented Sep 29, 2023

@RayZ0rr interesting, i have a repo that sees occasional commits https://github.com/eylles/fzfmenu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment