forked from matschaffer/profile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.conf
62 lines (55 loc) · 1.21 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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> -iname *<search>*
flike() {
local search path
if [ -z "$2" ]; then
search="$1"
path=.
else
search="$2"
path="$1"
fi
find "${path}" -iname "*${search}*"
}
# Shortcut for: find -iname *<search>* -print0 | xargs -0 grep <grepfor>
ffg() {
local search grepfor
if [ -z "$2" ]; then
grepfor="$1"
search=
else
grepfor="$2"
search="$1"
fi
gfind -iname "*${search}*" -print0|xargs -0 grep "${grepfor}"
}
# 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"
}