-
Notifications
You must be signed in to change notification settings - Fork 50
/
utils.conf
48 lines (43 loc) · 969 Bytes
/
utils.conf
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
# Grabs the n-th field out of each line.
# Example, show all the running PIDs: ps wuax | nth_field 2
nth_field() {
awk "{print \$$1}"
}
# Converts a list of millisecond timestamps to ISO-8601 format
# Handy when dealing with Java and JavaScript
to_iso_time() {
while [ -n "$1" ]; do
ruby -e "require 'time'; puts Time.at($1 / 1000).utc.iso8601"
shift
done
}
# Shortcut for: find <dir> -name *<search>*
flike() {
local search path
if [ -z "$2" ]; then
search="$1"
path=.
else
search="$2"
path="$1"
fi
find "${path}" -iname "*${search}*"
}
# Go up one directory every . in the argument.
# For example, to go up 4 directories (cd ../../../..)
# type: .. ....
..() {
local times
times=$(echo $1 | wc -c)
for ((i = 1; i < $times ; i++)); do
cd ..
done
}
# Get the response of a URL as tidy'd XML.
curlx() {
curl $@ | tidy -q -xml -i
}
# Get a human readable date string
human_date() {
date "+%Y-%m-%d_%H-%M-%S"
}