]> Sergey Matveev's repositories - nnn.git/commitdiff
nuke: use macOS open when GUI enabled (#705)
authorGregory Anders <github@gpanders.com>
Thu, 20 Aug 2020 09:21:26 +0000 (03:21 -0600)
committerGitHub <noreply@github.com>
Thu, 20 Aug 2020 09:21:26 +0000 (14:51 +0530)
* nuke: use macOS open when GUI enabled

* nuke: use is_mac function to test for macOS

This is consistent with how the imgur plugin does detection.

* Add macOS open command to plugins

* pskill: only execute if input is non-empty

plugins/fzopen
plugins/imgview
plugins/nuke
plugins/pskill

index 677ea26a97390bcac1ab6b825c34b277097bd2e4..fa44e0fc3845e323f6c8caff60a6b895b510e532 100755 (executable)
@@ -29,5 +29,10 @@ case "$(file -biL "$entry")" in
     *text*)
         "${VISUAL:-$EDITOR}" "$entry" ;;
     *)
-        xdg-open "$entry" >/dev/null 2>&1 ;;
+        if uname | grep -q "Darwin"; then
+            open "$entry" >/dev/null 2>&1
+        else
+            xdg-open "$entry" >/dev/null 2>&1
+        fi
+        ;;
 esac
index 4bbff2df42416526dc8ceeceae307f3b02773070..16d483be2e2e176a8643142d5460a2e5fa17b984 100755 (executable)
@@ -39,7 +39,11 @@ if [ -z "$1" ] || ! [ -s "$1" ]; then
     exit 1
 fi
 
-if command -v imvr >/dev/null 2>&1; then
+if uname | grep -q "Darwin"; then
+    if [ -f "$1" ]; then
+        open "$1" >/dev/null 2>&1 &
+    fi
+elif command -v imvr >/dev/null 2>&1; then
     if [ -f "$1" ]; then
         view_dir imvr "$1" >/dev/null 2>&1 &
     elif [ -d "$1" ] || [ -h "$1" ]; then
index f2abe65c15823d6b6fc5c86ae0355b14428d203e..b7836330ed8533e2df2c127f1278c794e66b763b 100755 (executable)
@@ -79,12 +79,19 @@ FNAME=$(basename "$1")
 EDITOR="${EDITOR:-vi}"
 PAGER="${PAGER:-less -R}"
 ext="${FNAME##*.}"
-if ! [ -z "$ext" ]; then
+if [ -n "$ext" ]; then
     ext="$(printf "%s" "${ext}" | tr '[:upper:]' '[:lower:]')"
 fi
 
+is_mac() {
+    uname | grep -q "Darwin"
+}
+
 handle_pdf() {
-    if [ "$GUI" -ne 0 ] && which zathura >/dev/null 2>&1; then
+    if [ "$GUI" -ne 0 ] && is_mac; then
+        open "${FPATH}" >/dev/null 2>&1 &
+        exit 0
+    elif [ "$GUI" -ne 0 ] && which zathura >/dev/null 2>&1; then
         zathura "${FPATH}" >/dev/null 2>&1 &
         exit 0
     elif which pdftotext >/dev/null 2>&1; then
@@ -120,7 +127,10 @@ handle_audio() {
 }
 
 handle_video() {
-    if [ "$GUI" -ne 0 ] && which smplayer >/dev/null 2>&1; then
+    if [ "$GUI" -ne 0 ] && is_mac; then
+        open "${FPATH}" >/dev/null 2>&1 &
+        exit 0
+    elif [ "$GUI" -ne 0 ] && which smplayer >/dev/null 2>&1; then
         smplayer "${FPATH}" >/dev/null 2>&1 &
         exit 0
     elif [ "$GUI" -ne 0 ] && which mpv >/dev/null 2>&1; then
@@ -294,7 +304,10 @@ handle_multimedia() {
 
         ## Image
         image/*)
-            if [ "$GUI" -ne 0 ] && which imvr >/dev/null 2>&1; then
+            if [ "$GUI" -ne 0 ] && is_mac; then
+                open "${FPATH}" >/dev/null 2>&1 &
+                exit 0
+            elif [ "$GUI" -ne 0 ] && which imvr >/dev/null 2>&1; then
                 load_dir imvr "${FPATH}" >/dev/null 2>&1 &
                 exit 0
             elif [ "$GUI" -ne 0 ] && which sxiv >/dev/null 2>&1; then
index 063be3520a25afe4e66f433f37dbfa381fe194b9..979492aba16560c029f7c20a5798e35c75d0fc96 100755 (executable)
@@ -29,5 +29,7 @@ if ! [ -z "$psname" ]; then
     fi
 
     cmd="$(ps -ax | grep -iw "$psname" | "$fuzzy" | sed -e 's/^[ \t]*//' | cut -d' ' -f1)"
-    $sucmd kill -9 "$cmd"
+    if [ -n "$cmd" ]; then
+        $sucmd kill -9 "$cmd"
+    fi
 fi