Skip to content

Instantly share code, notes, and snippets.

@danielsource
Created February 3, 2026 13:54
Show Gist options
  • Select an option

  • Save danielsource/71dd0d3cb42e5793b83aa31949d1a1f9 to your computer and use it in GitHub Desktop.

Select an option

Save danielsource/71dd0d3cb42e5793b83aa31949d1a1f9 to your computer and use it in GitHub Desktop.
dmenu file opener
#!/bin/sh
set -ef
cachedir=${XDG_CACHE_HOME:-$HOME/.cache}
cache=$cachedir/files.txt
getpaths() {
[ ! -e "$cachedir" ] && mkdir -p "$cachedir"
if [ -e "$cache" ]; then
cat "$cache"
else
eval "find . \( ${FIND_PRUNE:--path '*.git/*'} \) -prune -o -print" | sort | tee "$cache"
fi
}
cd ~
file=$({ echo '!refresh'; getpaths; } | dmenu -i -l 32 "$@")
case $file in
'!refresh')
cd "$OLDPWD"
rm -f "$cache"
exec "$0" "$@" ;;
*) ;;
esac
cmd=$(dmenu_path | dmenu -p "open $(basename -- "$file") with" "$@")
if [ ! -t 1 ] && echo "$cmd" | grep -qFx mpv; then
exec mpv --force-window --keep-open -- "$file"
else
exec $cmd -- "$file"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment