-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathcross-platform-utils.bashlib
More file actions
77 lines (64 loc) · 1.87 KB
/
Copy pathcross-platform-utils.bashlib
File metadata and controls
77 lines (64 loc) · 1.87 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Bash utility functions for BSD (Mac) and GNU (Linux, Mingw, CygWin)
# that shouldn't be necessary to reimplement
#
# We use aliases defined at startup rather than functions to avoid
# repeating the overhead of runtime detection each time a command is invoked
#
# Depends on is_mac from the startup functions
# marker that can be used to avoid re-import
export XPLATFORM_UTILS=1
# to make aliases expand in non-interactive sub-shells
shopt -s expand_aliases
# @returns 0 if running on mac, 1 if not
function is_mac() {
local cmd=`which uname`
if [ -z $cmd ];then
return 1
else
# dynamically redefines the function definition to avoid recomputing
if $cmd |grep Darwin 1>/dev/null; then
is_mac(){ return 0; };
else
is_mac(){ return 1; };
fi
is_mac
fi
}
function is_linux() {
local cmd=`which uname`
# no point in checking further if uname is not present
if [ -z $cmd ];then
return 1
fi
# dynamically redefines the function definition to avoid recomputing
if [[ $(uname) == "Linux" ]]; then
is_linux(){ return 0; }
else
is_linux(){ return 1; }
fi
}
# Check if running Windows Subsystem for Linux
# @returns 0 if running WSL, 1 if not
function is_wsl() {
if ! is_linux;then
return 1
fi
# dynamically redefines the function definition to avoid recomputing
if uname -a | grep microsoft 1>/dev/null; then
is_wsl(){ return 0; };
else
is_wsl(){ return 1; };
fi
is_wsl
}
if ! is_mac; then
# Interpret regular expressions as extended (modern) regular expressions
# rather than basic regular expressions (BRE's). The re_format(7) manual page fully describes both formats.
alias util.esed='sed -r '
# size in bytes
alias util.size='stat -c %s -- '
else
alias util.esed='sed -E '
alias util.size='stat -Lf %z -- '
fi
# vim: ft=sh