-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.functions
55 lines (48 loc) · 1.73 KB
/
.functions
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
# ------------------------------------------------------------
# 1. UTILS
# ------------------------------------------------------------
# backup: Backup given file(s)
# ------------------------------------------------------------
backup() {
for f in "$@"
# Don't follow symlink, preserves attributes, recursively
do
backupname="$f".$(date +%Y%m%d%H%M)
cp -a "$f" "$backupname"
backupsize=$(stat -f "%z" "$backupname")
echo "$backupname created ($backupsize bytes)"
done
}
# -----------------------------------------------------------
# 2. SEARCHING
# -----------------------------------------------------------
# spotlight: Search for a file using MacOS Spotlight's metadata
# -----------------------------------------------------------
spotlight () { mdfind "kMDItemDisplayName == '$@'wc"; }
# ---------------------------
# 3. PROCESS MANAGEMENT
# ---------------------------
# findPid: find out the pid of a specified process
# ------------------------------------------------------------
# Note that the command name can be specified via a regex
# E.g. findPid '/d$/' finds pids of all processes with names ending in 'd'
# Without the 'sudo' it will only find processes of the current user
# ------------------------------------------------------------
findPid () { lsof -t -c "$@" ; }
# my_ps: List processes owned by my user
# ------------------------------------------------------------
my_ps () { ps $@ -u $USER -o pid,%cpu,%mem,start,time,bsdtime,command ; }
# restart: restart Mac OS process
# ------------------------------------------------------------
restart () {
case "$1" in
Finder| finder)
killall Finder
;;
Dock| dock)
killall Dock
;;
*)
;;
esac
}