This repository has been archived by the owner on Aug 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
S91_utils
96 lines (88 loc) · 2.41 KB
/
S91_utils
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
function zsh_build() {
if [ -e "setup.py" ]; then
nosetests -x -w tests
elif [ -e "SConstruct" ]; then
scons
elif [ -e "Makefile" ]; then
make
fi
}
function inplace() {
if [ "$#" -lt 2 ]; then
echo "usage: $0 <filename> <command> [<arg> [<arg> ... ]]"
return 2
fi
if [ ! -f "$1" ]; then
echo "$0: $1: no such file"
return 1
fi
filename="$1"
shift
if ! isexe "$1"; then
echo "$0: $1: command not found"
return 1
fi
tempfile="$(mktemp /tmp/.inplace-XXXXXX)"
if [ $? -ne 0 ]; then
echo "$0: can't create tempfile"
return 1
fi
"$@" < "$filename" > "$tempfile"
if [ $? -ne 0 ]; then
echo "$0: command failed; $tempfile remains for your examination"
return 1
fi
mv -f "$tempfile" "$filename" 2>/dev/null # errors could include chown errors since mktemp is setuid
if [ $? -ne 0 ]; then
echo "$0: mv failed; $tempfile remains for your examination"
return 1
fi
}
function freq() {
sort | uniq -c | sort -n
}
function spacecrush() {
sed -e 's/ */ /g'
}
function linecrush() {
grep -v '^$'
}
function oneline() {
local delimeter="$1"
[ -z "$delimeter" ] && delimeter=" "
tr '\n' "$delimeter" ; echo
}
function multiline() {
local delimeter="$1"
[ -z "$delimeter" ] && delimeter=" "
striplines | tr "$delimeter" '\n'
}
function highlight() {
case "$1" in
--red) shift ; local _grep_colors="mt=01;31";;
--blue) shift ; local _grep_colors="mt=01;34";;
--yellow) shift ; local _grep_colors="mt=01;33";;
--green) shift ; local _grep_colors="mt=01;32";;
esac
keyword="$1"
shift
GREP_COLORS="$_grep_colors" egrep "$@" --color=always \(^\|"$keyword"\)
}
function saneperms() {
local dir=${1:-.}
local uid=${SANEPERMS_USER:-$UID}
local gid=${SANEPERMS_GROUP:-$GID}
sudo true
sudo find . -mindepth 1 -print0 | sudo xargs --null --no-run-if-empty chown $uid:$gid
sudo find . -mindepth 1 -type f -print0 | sudo xargs --null --no-run-if-empty chmod 644
sudo find . -mindepth 1 -type d -print0 | sudo xargs --null --no-run-if-empty chmod 2755
}
function rmdsstore() {
local dir=${1:-.}
find $dir -name '.DS_Store' -delete
find $dir -name '._.DS_Store' -delete
}
function rmemptydirs() {
local dir=${1:-.}
find $dir -type d -delete 2>&1 >/dev/null | grep -v 'Directory not empty'
}