forked from MLstate/opalang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplatform_helper.sh
executable file
·43 lines (37 loc) · 936 Bytes
/
platform_helper.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env bash
# Include in your scripts to detect the host platform and have appropriate
# aliases set for some commands (eg use the GNU versions on a mac)
# Example:
# $ . platform_helper.sh
# $ if [ "$IS_LINUX" ]; then echo "I am Linux"; fi
IS_LINUX=""
IS_MAC=""
IS_WINDOWS=""
case $(uname) in
CYGWIN*) IS_WINDOWS=1;;
Darwin*) IS_MAC=1;;
Linux*|GNU/kFreeBSD) IS_LINUX=1;;
FreeBSD) IS_FREEBSD=1;;
*)
echo "Error: could not detect OS. Defaulting to Linux" >&2
IS_LINUX=1
esac
# Defining aliases for a few commands
if [ -n "$IS_MAC" ]; then
SED=gsed
TAIL=gtail
MKTEMP=gmktemp
SORT=gsort
READLINK=greadlink
else
SED=sed
TAIL=tail
MKTEMP=mktemp
SORT=sort
READLINK=readlink
fi
tail() { command "$TAIL" "$@"; }
mktemp() { command "$MKTEMP" "$@"; }
sed() { command "$SED" "$@"; }
sort() { command "$SORT" "$@"; }
readlink() { command "$READLINK" "$@"; }