forked from ajmalsiddiqui/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.functions.Darwin
64 lines (54 loc) · 1.92 KB
/
.functions.Darwin
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
# This is a temporary solution to seperate the OS specific stuff out
# TODO: Either make this solution robust or find something else
# Open a project in the TEXT_EDITOR
workon () {
if [ $# -lt 1 ] ; then
echo "Specify a project"
return 1
fi
if [ ! -d "$PATH_TO_PROJECTS/$1" ] ; then
echo "This project does not exist"
return 1
fi
open -a "$TEXT_EDITOR" "$PATH_TO_PROJECTS/$1"
#cd "$PATH_TO_PROJECTS/$1"
echo "Working on $1"
}
# Open a playground in the TEXT_EDITOR
playwith () {
if [ $# -lt 1 ] ; then
echo "Specify a playground" && return 1
fi
if [ ! -d "$PATH_TO_PLAYGROUND/$1" ] ; then
echo "This playground does not exist" && return 1
fi
open -a "$TEXT_EDITOR" "$PATH_TO_PLAYGROUND/$1"
echo "Playing with $1"
}
# OSX Specific Script to get battery details
# I'll probably use this while building my prompt
battery () {
# Grep options: -o output only matched part, -E use extended syntax
# regex [^ ]+$ matches the last word (not a space followed by 1+ chars to end)
# Battery remaining mAh is last word
charge=$( system_profiler SPPowerDataType | grep 'Charge Remaining' | grep -oE '[^ ]+$' )
# Full charge
full_charge=$( system_profiler SPPowerDataType | grep 'Full Charge Capacity' | grep -oE '[^ ]+$' )
# Is charging?
charging=$( system_profiler SPPowerDataType | grep 'Charging' | tail -n 1 | grep -oE '[^ ]+$' )
# Percentage calculation
#percent=$( echo "scale=4; $charge / $full_charge * 100" | bc )
percent=$(( $charge * 100 / $full_charge ))
echo "$charge $full_charge $percent $charging"
}
# OSX specific script (uses AppleScripts) to ask me to take a break every hour
# Run this function as a background process using &
# alert &
alert () {
while true ; do
# 3600 seconds is 1 hour
sleep 3600
osascript -e 'tell app "System Events" to display dialog "Take a break! You have been staring at the screen for far too long "' 1>&/dev/null
done
exit 0
}