Skip to content
This repository
Newer
Older
100755 43 lines (37 sloc) 0.936 kb
22b433a3 » Frédéric Perrin
2011-08-29 Don't assume that bash is in /bin
1 #!/usr/bin/env bash
2
fccc6851 » MLstate
2011-06-21 Initial open-source release
3 # Include in your scripts to detect the host platform and have appropriate
4 # aliases set for some commands (eg use the GNU versions on a mac)
5 # Example:
6 # $ . platform_helper.sh
7 # $ if [ "$IS_LINUX" ]; then echo "I am Linux"; fi
8
9 IS_LINUX=""
10 IS_MAC=""
11 IS_WINDOWS=""
12
13 case $(uname) in
14 CYGWIN*) IS_WINDOWS=1;;
15 Darwin*) IS_MAC=1;;
7de4ee06 » Frédéric Perrin
2011-09-12 New platform: `FreeBSD'
16 Linux*|GNU/kFreeBSD) IS_LINUX=1;;
17 FreeBSD) IS_FREEBSD=1;;
fccc6851 » MLstate
2011-06-21 Initial open-source release
18 *)
19 echo "Error: could not detect OS. Defaulting to Linux" >&2
20 IS_LINUX=1
21 esac
22
23 # Defining aliases for a few commands
24
25 if [ -n "$IS_MAC" ]; then
26 SED=gsed
27 TAIL=gtail
28 MKTEMP=gmktemp
29 SORT=gsort
30 READLINK=greadlink
31 else
32 SED=sed
33 TAIL=tail
34 MKTEMP=mktemp
35 SORT=sort
36 READLINK=readlink
37 fi
38
39 tail() { command "$TAIL" "$@"; }
40 mktemp() { command "$MKTEMP" "$@"; }
41 sed() { command "$SED" "$@"; }
42 sort() { command "$SORT" "$@"; }
43 readlink() { command "$READLINK" "$@"; }
Something went wrong with that request. Please try again.