From b82c0978cc38f429377af25d64a57408b802cd99 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <github@thinkyhead.com>
Date: Tue, 1 Oct 2019 22:03:59 -0500
Subject: [PATCH] Patch up OPEN command in git scripts

---
 buildroot/share/git/firstpush |  8 +++++---
 buildroot/share/git/mfdoc     |  8 +++++---
 buildroot/share/git/mfpr      |  8 +++++---
 buildroot/share/git/mfpub     | 16 ++++++++++------
 4 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/buildroot/share/git/firstpush b/buildroot/share/git/firstpush
index 443166088c..132795b617 100755
--- a/buildroot/share/git/firstpush
+++ b/buildroot/share/git/firstpush
@@ -16,13 +16,15 @@ BRANCH=${INFO[5]}
 
 git push --set-upstream origin $BRANCH
 
-TOOL=$(which gnome-open xdg-open open | awk '{ print $1 }')
+which xdg-open >/dev/null && TOOL=xdg-open
+which gnome-open >/dev/null && TOOL=gnome-open
+which open >/dev/null && TOOL=open
 URL="https://github.com/$FORK/$REPO/commits/$BRANCH"
 
-if [ -z "$TOOL" ]; then
+if [ -z "$OPEN" ]; then
   echo "Can't find a tool to open the URL:"
   echo $URL
 else
   echo "Viewing commits on $BRANCH..."
-  "$TOOL" "$URL"
+  "$OPEN" "$URL"
 fi
diff --git a/buildroot/share/git/mfdoc b/buildroot/share/git/mfdoc
index eba599c612..f2a2b08204 100755
--- a/buildroot/share/git/mfdoc
+++ b/buildroot/share/git/mfdoc
@@ -16,14 +16,16 @@ BRANCH=${INFO[5]}
 [[ $ORG == "MarlinFirmware" && $REPO == "MarlinDocumentation" ]] || { echo "Wrong repository." 1>&2; exit 1; }
 
 opensite() {
-  TOOL=$(which gnome-open xdg-open open | awk '{ print $1 }')
+  which xdg-open >/dev/null && TOOL=xdg-open
+  which gnome-open >/dev/null && TOOL=gnome-open
+  which open >/dev/null && TOOL=open
   URL="http://127.0.0.1:4000/"
-  if [ -z "$TOOL" ]; then
+  if [ -z "$OPEN" ]; then
     echo "Can't find a tool to open the URL:"
     echo $URL
   else
     echo "Opening preview site in the browser..."
-    "$TOOL" "$URL"
+    "$OPEN" "$URL"
   fi
 }
 
diff --git a/buildroot/share/git/mfpr b/buildroot/share/git/mfpr
index 73af049ab1..0220c0aa8e 100755
--- a/buildroot/share/git/mfpr
+++ b/buildroot/share/git/mfpr
@@ -23,15 +23,17 @@ OLDBRANCH=${INFO[5]}
 # See if it's been pushed yet
 if [ -z "$(git branch -vv | grep ^\* | grep \\[origin)" ]; then firstpush; fi
 
-TOOL=$(which gnome-open xdg-open open | awk '{ print $1 }')
+which xdg-open >/dev/null && TOOL=xdg-open
+which gnome-open >/dev/null && TOOL=gnome-open
+which open >/dev/null && TOOL=open
 URL="https://github.com/$ORG/$REPO/compare/$TARG...$FORK:$BRANCH?expand=1"
 
-if [ -z "$TOOL" ]; then
+if [ -z "$OPEN" ]; then
   echo "Can't find a tool to open the URL:"
   echo $URL
 else
   echo "Opening a New PR Form..."
-  "$TOOL" "$URL"
+  "$OPEN" "$URL"
 fi
 
 [[ $BRANCH != $OLDBRANCH ]] && git checkout $OLDBRANCH
diff --git a/buildroot/share/git/mfpub b/buildroot/share/git/mfpub
index 29eb0543d7..f77b923656 100755
--- a/buildroot/share/git/mfpub
+++ b/buildroot/share/git/mfpub
@@ -77,15 +77,17 @@ else
     git push -f origin
   fi
 
-  TOOL=$(which gnome-open xdg-open open | awk '{ print $1 }')
+  which xdg-open >/dev/null && TOOL=xdg-open
+  which gnome-open >/dev/null && TOOL=gnome-open
+  which open >/dev/null && TOOL=open
   URL="https://github.com/$ORG/$REPO/compare/$TARG...$FORK:$BRANCH?expand=1"
 
-  if [ -z "$TOOL" ]; then
+  if [ -z "$OPEN" ]; then
     echo "Can't find a tool to open the URL:"
     echo $URL
   else
     echo "Opening a New PR Form..."
-    "$TOOL" "$URL"
+    "$OPEN" "$URL"
   fi
 
 fi
@@ -116,14 +118,16 @@ git checkout gh-pages || { echo "Something went wrong!"; exit 1; }
 rsync -av ${TMPFOLDER}/ ./
 
 opensite() {
-  TOOL=$(which gnome-open xdg-open open | awk '{ print $1 }')
+  which xdg-open >/dev/null && TOOL=xdg-open
+  which gnome-open >/dev/null && TOOL=gnome-open
+  which open >/dev/null && TOOL=open
   URL="http://marlinfw.org/"
-  if [ -z "$TOOL" ]; then
+  if [ -z "$OPEN" ]; then
     echo "Can't find a tool to open the URL:"
     echo $URL
   else
     echo "Opening the site in the browser..."
-    "$TOOL" "$URL"
+    "$OPEN" "$URL"
   fi
 }