Skip to content

Commit

Permalink
Merge pull request #30 from amiaopensource/check_connection
Browse files Browse the repository at this point in the history
check if web connected
  • Loading branch information
Ethan Gates authored Aug 25, 2017
2 parents 0614f70 + cfa1a1f commit e9ff00a
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions cable-bible
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
#!/usr/bin/env bash

# This allows to open the online version of the Cable Bible, when the computer
# is connected to the Web, and the local version otherwise.

if [[ "$(uname -s)" = "Darwin" ]] ; then
default_browser=$(plutil -convert json ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist -r -o - | grep https -b1 | tail -n1 | cut -d'"' -f4)
if [ -d /usr/local/Cellar/cable-bible ] ; then
cablebible_path=$(find /usr/local/Cellar/cable-bible -iname 'index.html' | sort -M | tail -n1)
fi
if [ -z "${cablebible_path}" ] ; then
cablebible_path='https://amiaopensource.github.io/cable-bible/'
fi
if [ -n "${default_browser}" ] ; then
open -b "${default_browser}" "${cablebible_path}"
else
open "${cablebible_path}"
fi
default_browser=$(plutil -convert json ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist -r -o - | grep https -b1 | tail -n1 | cut -d'"' -f4)
if ping -c 1 amiaopensource.github.io >/dev/null 2>&1 ; then
cablebible_path='https://amiaopensource.github.io/cable-bible/'
else
cablebible_path=$(find /usr/local/Cellar/cable-bible -iname 'index.html' | sort -M | tail -n1)
fi
if [ -n "${default_browser}" ] ; then
open -b "${default_browser}" "${cablebible_path}"
else
open "${cablebible_path}"
fi
elif [[ "$(uname -s)" = "Linux" ]] ; then
if [ -d ~/.linuxbrew/Cellar/cable-bible ] ; then
cablebible_path=$(find ~/.linuxbrew/Cellar/cable-bible -iname 'index.html' | sort -M | tail -n1)
fi
if [ -z "${cablebible_path}" ] ; then
cablebible_path='https://amiaopensource.github.io/cable-bible/'
fi
xdg-open "${cablebible_path}"
if ping -c 1 amiaopensource.github.io >/dev/null 2>&1 ; then
cablebible_path='https://amiaopensource.github.io/cable-bible/'
else
cablebible_path=$(find ~/.linuxbrew/Cellar/cable-bible -iname 'index.html' | sort -M | tail -n1)
fi
xdg-open "${cablebible_path}"
fi

0 comments on commit e9ff00a

Please sign in to comment.