Add support for SunOS
[guilt/mob.git] / os.Darwin
blob470f5fbbc0b6d388089e4fbab853ef3e6f9949cc
1 # usage: touch_date <unix ts> <file>
2 touch_date()
4         touch -t `date -r $1 +%Y%m%d%H%M.%S` "$2"
7 # usage: last_modified <file>
8 last_modified()
10         stat -f "%m" "$1"
13 # usage: format_last_modified <file>
14 format_last_modified()
16         stat -f "%Sm" -t "%Y-%m-%d %H:%M:%S %z" "$1"
19 # usage: head_n [count]
20 head_n()
22         if [ "$1" -gt 0 ]; then
23                 head -n "$1"
24         fi
27 # usage: sha1 [file]
28 sha1()
30         openssl dgst -sha1 "$1" | sed "s,SHA1.\(.*\).= \(.*\),\2  \1,"
33 # usage: cp_a <src> <dst>
34 cp_a()
36         cp -pR "$1" "$2"
39 # usage: _tac
40 _tac()
42         sed -e '1!G;h;$!d'
45 _seq()
47         (
48                 if [ $# -eq 1 ]
49                 then
50                         /usr/bin/jot $1
51                 elif [ $# -eq 2 ]
52                 then
53                         n1=$((${2} - ${1} + 1))
54                         n2=$1
55                         /usr/bin/jot $n1 $n2
56                 elif [ $# -eq 3 ]
57                 then
58                         num1=$1
59                         incr=$2
60                         num2=$3
61                         /usr/bin/awk -v n1=$num1 -v n2=$num2 -v add=$incr 'BEGIN{ for(i=n1; i<=n2; i+=add) print i;}' | /usr/bin/sed -E '/e/s/^.+e.+$/0/'
62                 fi
63         )
64         return 0