Skip to content

Instantly share code, notes, and snippets.

@chriscorwin
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save chriscorwin/a9a66a58b80d8fc7234e to your computer and use it in GitHub Desktop.

Select an option

Save chriscorwin/a9a66a58b80d8fc7234e to your computer and use it in GitHub Desktop.
#noshebang;source-this
##
# This is a simple script to figure out what sort of system the user is running. These
# exported environmental variables can then be used for system-agnostic scripts. This
# script MUST be sourced in order to have access to the variables afterwards.
##
# get uname info
export _ENV_UNAME=$(uname -s)
# Unix-y vars
export _ENV_UNIX=
export _ENV_LINUX=
export _ENV_OSX=
# Windows-y vars
export _ENV_WINDOWS=
export _ENV_CYGWIN=
export _ENV_MSYSGIT=
# var that will be echoed if -e is passed. if it's already been set, just echo it.
_ENV_SUMMARY=
case $_ENV_UNAME in
Linux*)
export _ENV_UNIX=true
export _ENV_LINUX=true
_ENV_SUMMARY="unix-linux"
;;
Darwin*)
export _ENV_UNIX=true
export _ENV_OSX=true
_ENV_SUMMARY="unix-osx"
;;
CYGWIN*)
export _ENV_WINDOWS=true
export _ENV_CYGWIN=true
_ENV_SUMMARY="windows-cygwin"
;;
MINGW32*)
export _ENV_WINDOWS=true
export _ENV_MSYSGIT=true
_ENV_SUMMARY="windows-msysgit"
;;
*)
export _ENV_OTHER=true
_ENV_SUMMARY="other"
;;
esac
export _ENV_SUMMARY
if [ "$1" = "-e" ]; then
echo $_ENV_SUMMARY
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment