xdgdefault plugin: add dmenu support (#1112)

* xdgdefault plugin: add dmenu support

use fzf if available. otherwise, if available, use dmenu.
should be possible to use rofi as well, but i don't use rofi nor do i
have it installed for testing.

* xdgdefault plugin: add GUI flag

* update xdgdefault requirement
This commit is contained in:
N-R-K 2021-07-23 17:36:19 +06:00 committed by GitHub
parent 0150c69844
commit 3a98dfb0b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View file

@ -62,7 +62,7 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina
| [upload](upload) | Upload to Firefox Send or ix.io (text) or file.io (bin) | sh | [ffsend](https://github.com/timvisee/ffsend), curl, jq, tr | | [upload](upload) | Upload to Firefox Send or ix.io (text) or file.io (bin) | sh | [ffsend](https://github.com/timvisee/ffsend), curl, jq, tr |
| [wallpaper](wall) | Set wallpaper or change colorscheme | sh | nitrogen/pywal | | [wallpaper](wall) | Set wallpaper or change colorscheme | sh | nitrogen/pywal |
| [x2sel](x2sel) | Copy file list from system clipboard to selection | sh | _see in-file docs_ | | [x2sel](x2sel) | Copy file list from system clipboard to selection | sh | _see in-file docs_ |
| [xdgdefault](xdgdefault) | Set the default app for the hovered file type | sh | xdg-utils, fzf | | [xdgdefault](xdgdefault) | Set the default app for the hovered file type | sh | xdg-utils, fzf/dmenu |
Note: Note:

View file

@ -5,12 +5,21 @@
# defaults if unset, as specified in XDG Base Directory Specification # defaults if unset, as specified in XDG Base Directory Specification
# - http://specifications.freedesktop.org/basedir-spec/. # - http://specifications.freedesktop.org/basedir-spec/.
# #
# Dependencies: xdg-utils, fzf # Dependencies: xdg-utils, fzf or dmenu (GUI)
# #
# Shell: POSIX compliant # Shell: POSIX compliant
# Author: lwnctd # Author: lwnctd
if [ -z "$1" ] || ! command -v fzf > /dev/null 2>& 1; then # set to 1 to enable GUI apps
GUI="${GUI:-0}"
if [ "$GUI" -ne 0 ] && command -v dmenu >/dev/null 2>& 1; then
menu="dmenu -l 7"
elif command -v fzf > /dev/null 2>& 1; then
menu="fzf -e --tiebreak=begin"
fi
if [ -z "$1" ] || [ -z "$menu" ] > /dev/null 2>& 1; then
exit 1 exit 1
fi fi
@ -36,7 +45,7 @@ app=$(find "$@" -iname '*.desktop' -exec grep '^Name=' {} + \
| sed -E 's;.+/(.+desktop):Name=(.+);\2:\1;' \ | sed -E 's;.+/(.+desktop):Name=(.+);\2:\1;' \
| sort -t ':' -k 1,1 \ | sort -t ':' -k 1,1 \
| column -t -s ':' -o "$(printf '\t')" \ | column -t -s ':' -o "$(printf '\t')" \
| fzf -e --tiebreak=begin \ | $menu \
| cut -f 2) | cut -f 2)
if [ -n "$app" ]; then if [ -n "$app" ]; then