From f4437682601eb433ec709b19540f3cdd55cdc4b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Sj=C3=B6berg?= Date: Fri, 11 Jun 2021 11:46:51 +0200 Subject: [PATCH] Support opening regular text files on macOS --- plugins/README.md | 4 ++-- plugins/fzopen | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/plugins/README.md b/plugins/README.md index e8abf17a..a30b95cf 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -27,7 +27,7 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina | [fixname](fixname) | Clean filename to be more shell-friendly [✓] | bash | sed | | [fzcd](fzcd) | Fuzzy search multiple dirs (or `$PWD`) and visit file | sh | fzf, (fd) | | [fzhist](fzhist) | Fuzzy-select a cmd from history, edit in `$EDITOR` and run | sh | fzf, mktemp | -| [fzopen](fzopen) | Fuzzy find file(s) in subtree to edit/open/pick | sh | fzf, xdg-open | +| [fzopen](fzopen) | Fuzzy find file(s) in subtree to edit/open/pick | sh | fzf, xdg-open/open | | [fzplug](fzplug) | Fuzzy find, preview and run other plugins | sh | fzf | | [fzz](fzz) | Change to any directory in the z database with fzf | sh | fzf, z | | [getplugs](getplugs) | Update plugins to installed `nnn` version | sh | curl | @@ -35,7 +35,7 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina | [gutenread](gutenread) | Browse, download, read from Project Gutenberg | sh | curl, unzip, w3m
[epr](https://github.com/wustho/epr) (optional) | | [imgresize](imgresize) | Resize images in dir to screen resolution | sh | [imgp](https://github.com/jarun/imgp) | | [imgur](imgur) | Upload an image to imgur (from [imgur-screenshot](https://github.com/jomo/imgur-screenshot)) | bash | - | -| [imgview](imgview) | View (thumbnail)images, set wallpaper, [rename](https://github.com/jarun/nnn/wiki/Basic-use-cases#browse-rename-images) and [more](https://wiki.archlinux.org/index.php/Sxiv#Assigning_keyboard_shortcuts)| sh | [imv](https://github.com/eXeC64/imv)/[sxiv](https://github.com/muennich/sxiv)/[viu](https://github.com/atanunq/viu)/
[ucollage](https://github.com/ckardaris/ucollage)/[catimg](https://github.com/posva/catimg)/[lsix](https://github.com/hackerb9/lsix)| +| [imgview](imgview) | View (thumbnail)images, set wallpaper, [rename](https://github.com/jarun/nnn/wiki/Basic-use-cases#browse-rename-images) and [more](https://wiki.archlinux.org/index.php/Sxiv#Assigning_keyboard_shortcuts)| sh | _see in-file docs_ | | [ipinfo](ipinfo) | Fetch external IP address and whois information | sh | curl, whois | | [kdeconnect](kdeconnect) | Send selected files to an Android device [✓] | sh | kdeconnect-cli | | [launch](launch) | GUI application launcher | sh | fzf | diff --git a/plugins/fzopen b/plugins/fzopen index 95ae9be4..6039d306 100755 --- a/plugins/fzopen +++ b/plugins/fzopen @@ -12,7 +12,7 @@ # Leaves untouched if no file is picked. # Works with single/multiple files selected. # -# Dependencies: fd/find, fzf/skim, xdg-open +# Dependencies: fd/find, fzf/skim, xdg-open/open (on macOS) # # Shell: POSIX compliant # Author: Arun Prakash Jana @@ -52,14 +52,19 @@ if [ "$3" ]; then fi # Open the file (works for a single file only) -case "$(file -biL "$entry")" in +cmd_file="" +cmd_open="" +if uname | grep -q "Darwin"; then + cmd_file="file -bIL" + cmd_open="open" +else + cmd_file="file -biL" + cmd_open="xdg-open" +fi + +case "$($cmd_file "$entry")" in *text*) "${VISUAL:-$EDITOR}" "$entry" ;; *) - if uname | grep -q "Darwin"; then - open "$entry" >/dev/null 2>&1 - else - xdg-open "$entry" >/dev/null 2>&1 - fi - ;; + $cmd_open "$entry" >/dev/null 2>&1 ;; esac