changeset 154:cfbaaeb8b71d

This makes 'hgs' work nicer on Linux, still may be more tweaks to do
author Steve Huston <huston@astro.princeton.edu>
date Mon, 10 Apr 2017 15:31:48 -0400
parents 1dc2b14d4f02
children 5ab127dd2d89
files .bash_aliases
diffstat 1 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/.bash_aliases	Wed Mar 15 11:40:14 2017 -0400
+++ b/.bash_aliases	Mon Apr 10 15:31:48 2017 -0400
@@ -246,18 +246,25 @@
 }
 
 hgs() {
-  # Currently works on Macs, I should write a version for Linux as well
-  # someday
+  # We assume here that if the host is a Mac, we're going to open the
+  # connection automatically, otherwise we echo the URL to the terminal to be
+  # opened
   ROOT=`hg root`
   if [ "$1" == "end" -a -e $ROOT/.hg/hgserve-PID ] ; then
     kill `cat $ROOT/.hg/hgserve-PID`
     rm $ROOT/.hg/hgserve-PID
-  elif [ -e $ROOT/.hg/hgserve-PID ] ; then
-    P=`cat $ROOT/.hg/hgserve-PID`
-    URL=`lsof -p $P | grep LISTEN | awk '{print $9}'`
-    open http://$URL/
   else
-    hg serve -a localhost -d -p 0 --pid-file $ROOT/.hg/hgserve-PID | sed 's#.*bound to \(.*\))#http://\1/#' | xargs open
+    if [ -e $ROOT/.hg/hgserve-PID ] ; then
+      P=`cat $ROOT/.hg/hgserve-PID`
+      URL=`lsof -n -p $P | grep LISTEN | awk '{print $9}'`
+    else
+      URL=`hg serve -a localhost -d -p 0 --pid-file $ROOT/.hg/hgserve-PID | sed 's#.*bound to \(.*\))#\1#'`
+    fi
+    if [ -z "$DARWIN" ] ; then
+      echo hg serve on http://$URL/
+    else
+      open http://$URL/
+    fi
   fi
 }