mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 03:41:27 +00:00
Add the xdgdefault plugin (#1003)
This commit is contained in:
parent
dd02afc58b
commit
9cbb7f540c
|
@ -72,6 +72,7 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina
|
||||||
| [vidthumb](vidthumb) | Show video thumbnails in terminal | sh | [ffmpegthumbnailer](https://github.com/dirkvdb/ffmpegthumbnailer),<br>[lsix](https://github.com/hackerb9/lsix) |
|
| [vidthumb](vidthumb) | Show video thumbnails in terminal | sh | [ffmpegthumbnailer](https://github.com/dirkvdb/ffmpegthumbnailer),<br>[lsix](https://github.com/hackerb9/lsix) |
|
||||||
| [wall](wall) | Set wallpaper or change colorscheme | sh | nitrogen/pywal |
|
| [wall](wall) | Set wallpaper or change colorscheme | sh | nitrogen/pywal |
|
||||||
| [x2sel](x2sel) | Copy `\n`-separated file list from system clipboard to sel | sh | _see in-file docs_ |
|
| [x2sel](x2sel) | Copy `\n`-separated file list from system clipboard to sel | sh | _see in-file docs_ |
|
||||||
|
| [xdgdefault](xdgdefault) | Set the default app for the hovered file type | sh | xdg-utils, fzf |
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
|
|
||||||
|
|
44
plugins/xdgdefault
Executable file
44
plugins/xdgdefault
Executable file
|
@ -0,0 +1,44 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
# Description: Sets the xdg-open's default application for the current entry's
|
||||||
|
# file type. ${XDG_DATA_DIRS} and ${XDG_DATA_HOME} are set to the recommended
|
||||||
|
# defaults if unset, as specified in XDG Base Directory Specification,
|
||||||
|
# [ http://specifications.freedesktop.org/basedir-spec/ ].
|
||||||
|
#
|
||||||
|
# Dependencies: xdg-utils, fzf
|
||||||
|
#
|
||||||
|
# Shell: POSIX
|
||||||
|
# Author: lwnctd
|
||||||
|
|
||||||
|
if [ -z "$1" ] || ! command -v fzf > /dev/null 2>& 1; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
ftype=$(xdg-mime query filetype "$2/$1")
|
||||||
|
|
||||||
|
if [ -z "$ftype" ]; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
dirs=${XDG_DATA_DIRS:-/usr/local/share:/usr/share}
|
||||||
|
dirs=${dirs}:${XDG_DATA_HOME:-$HOME/.local/share}:
|
||||||
|
|
||||||
|
while [ -n "$dirs" ]; do
|
||||||
|
d=${dirs%%:*}
|
||||||
|
if [ -n "$d" ] && [ -d "$d"/applications ]; then
|
||||||
|
set -- "$@" "$d"/applications
|
||||||
|
fi
|
||||||
|
dirs=${dirs#*:}
|
||||||
|
done
|
||||||
|
|
||||||
|
app=$(find "$@" -iname '*.desktop' -exec grep '^Name=' {} + \
|
||||||
|
| sort -u -t ':' -k 1,1 \
|
||||||
|
| sed -E 's;.+/(.+desktop):Name=(.+);\2:\1;' \
|
||||||
|
| sort -t ':' -k 1,1 \
|
||||||
|
| column -t -s ':' -o "$(printf '\t')" \
|
||||||
|
| fzf -e --tiebreak=begin \
|
||||||
|
| cut -f 2)
|
||||||
|
|
||||||
|
if [ -n "$app" ]; then
|
||||||
|
xdg-mime default "$app" "$ftype"
|
||||||
|
fi
|
Loading…
Reference in a new issue