]> Sergey Matveev's repositories - nnn.git/commitdiff
Support opening regular text files on macOS
authorKevin Sjöberg <mail@kevinsjoberg.com>
Fri, 11 Jun 2021 09:46:51 +0000 (11:46 +0200)
committerArun Prakash Jana <engineerarun@gmail.com>
Fri, 11 Jun 2021 10:05:03 +0000 (15:35 +0530)
plugins/README.md
plugins/fzopen

index e8abf17a0ad526f4cc6a22bd551d6e4ce7ff5a66..a30b95cf137f854e0e14acc3ca4510a1d73831cd 100644 (file)
@@ -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<br>[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)/<br>[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 |
index 95ae9be4835f1afb33ad4d0ca70995985658cf24..6039d306de38cd97fd608936a3de6ee483ce331f 100755 (executable)
@@ -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