forked from rachelbaker/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.functions
More file actions
165 lines (147 loc) · 6.21 KB
/
Copy path.functions
File metadata and controls
165 lines (147 loc) · 6.21 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Start an HTTP server from a directory, optionally specifying the port
function server() {
local port="${1:-8000}"
open "http://0.0.0.0:${port}/"
python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port"
}
# Run a local HTTP server with Ruby
function rserv() {
ruby -run -e httpd . -p5000
}
# Go to a project directory
dev() {
cd $HOME/dev/$1;
}
# Go to a project directory and open in text editor
function devwork () {
cd $HOME/dev/$1;
e .;
}
# Go to Vagrant directory, start Vagrant, and open project in text editor
function vvwork () {
cd $HOME/dev/vagrant-local;
vagrant up;
cd www/$1;
e .;
}
# Create a new symlink to ~/dotfiles
function symlink () {
print "Creating symlink to $1 in home directory.";
ln -s ~/dotfiles/$1 ~/$1
}
# Append new localhost configuration to hosts file.
function newhost () {
[ -n "$1" ]
sudo bash -c "printf '\n\n127.0.0.1 $1 \n127.0.0.1 www.$1' >> /etc/hosts" | dscacheutil -flushcache
}
# Append new 0.0.0.0 configuration to hosts file.
function newzerohost () {
[ -n "$1" ]
sudo bash -c "printf '\n\n0.0.0.0 $1 \n0.0.0.0 www.$1' >> /etc/hosts" | dscacheutil -flushcache
}
# Create a directory and change into it at the same time.
function md () {
[ -n "$1" ]
mkdir -p "$1" && cd "$1";
}
function tree() {
find . ! -name ".DS_Store" -print | sed -e 's;[^/]*/;|__;g;s;__|; |;g'
}
exip() {
# gather external ip address
echo -n "Current External IP: "
curl -s -m 5 http://myip.dk | grep "ha4" | sed -e 's/.*ha4">//g' -e 's/<\/span>.*//g'
}
ips() {
# determine local IP address
ifconfig | grep "inet " | awk '{ print $2 }'
}
# take this repo and copy it to somewhere else minus the .git stuff.
function gitexport (){
mkdir -p "$1"
git archive master | tar -x -C "$1"
}
# Credit: https://github.com/LambdaDriver/Solar-Flair
# Usage: solarALT [light | dark]
# Description: SolarALT color schemes for NVAlt
function solarALT () {
case $1 in
'dark')
osascript -e 'tell application "nvALT" to quit'
defaults write net.elasticthreads.nv ColorScheme 2
defaults write net.elasticthreads.nv BackgroundTextColor "<040b7374 7265616d 74797065 6481e803 84014084 8484074e 53436f6c 6f720084 84084e53 4f626a65 63740085 84016301 84046666 666683e6 73823c83 b38e013e 835a8723 3e0186>"
defaults write net.elasticthreads.nv ForegroundTextColor "<040b7374 7265616d 74797065 6481e803 84014084 8484074e 53436f6c 6f720084 84084e53 4f626a65 63740085 84016301 84046666 666683bc 93e13e83 1177023f 83ce5004 3f0186>"
defaults write net.elasticthreads.nv SearchTermHighlightColor "<040b7374 7265616d 74797065 6481e803 84014084 8484074e 53436f6c 6f720084 84084e53 4f626a65 63740085 84016301 84046666 666683b2 4d213d83 92f5233e 83be174b 3e0186>"
osascript -e 'tell application "nvALT" to launch'
;;
'light')
osascript -e 'tell application "nvALT" to quit'
defaults write net.elasticthreads.nv ColorScheme 2
defaults write net.elasticthreads.nv BackgroundTextColor "<040b7374 7265616d 74797065 6481e803 84014084 8484074e 53436f6c 6f720084 84084e53 4f626a65 63740085 84016301 84046666 6666838f 4b7d3f83 d03b753f 8306335d 3f0186>"
defaults write net.elasticthreads.nv ForegroundTextColor "<040b7374 7265616d 74797065 6481e803 84014084 8484074e 53436f6c 6f720084 84084e53 4f626a65 63740085 84016301 84046666 666683bc 93e13e83 1177023f 83ce5004 3f0186>"
defaults write net.elasticthreads.nv SearchTermHighlightColor "<040b7374 7265616d 74797065 6481e803 84014084 8484074e 53436f6c 6f720084 84084e53 4f626a65 63740085 84016301 84046666 6666833a 866a3f83 dad7633f 83583d4c 3f0186>"
osascript -e 'tell application "nvALT" to launch'
;;
*)
echo "Usage: $(basename $0) [light|dark]"
echo "Switches nvALT color schemes between Solarized Light and Dark"
;;
esac
}
# credit: http://nparikh.org/notes/zshrc.txt
# Usage: extract <file>
# Description: extracts archived files / mounts disk images
# Note: .dmg/hdiutil is Mac OS X-specific.
extract () {
if [ -f $1 ]; then
case $1 in
*.tar.bz2) tar -jxvf $1 ;;
*.tar.gz) tar -zxvf $1 ;;
*.bz2) bunzip2 $1 ;;
*.dmg) hdiutil mount $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar -xvf $1 ;;
*.tbz2) tar -jxvf $1 ;;
*.tgz) tar -zxvf $1 ;;
*.zip) unzip $1 ;;
*.ZIP) unzip $1 ;;
*.pax) cat $1 | pax -r ;;
*.pax.Z) uncompress $1 --stdout | pax -r ;;
*.Z) uncompress $1 ;;
*) echo "'$1' cannot be extracted/mounted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# Credit: http://dotfiles.org/~_why/.zshrc
# Description: Sets the window title nicely no matter where you are
title() {
# escape '%' chars in $1, make nonprintables visible
a=${(V)1//\%/\%\%}
# Truncate command, and join lines.
a=$(print -Pn "%40>...>$a" | tr -d "\n")
case $TERM in
screen)
print -Pn "\ek$a:$3\e\\" # screen title (in ^A")
;;
xterm*|rxvt)
print -Pn "\e]2;$2\a" # plain xterm title ($3 for pwd)
;;
esac
}
# animated gifs from any video
# from alex sexton gist.github.com/SlexAxton/4989674
gifify () {
if [[ -n "$1" ]]; then
if [[ $2 == '--good' ]]; then
ffmpeg -i $1 -r 10 -vcodec png out-static-%05d.png
time convert -verbose +dither -layers Optimize -resize 600x600\> out-static*.png GIF:- | gifsicle --colors 128 --delay=5 --loop --optimize=3 --multifile - > $1.gif
rm out-static*.png
else
ffmpeg -i $1 -s 600x400 -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > $1.gif
fi
else
echo "proper usage: gifify <input_movie.mov>. You DO need to include extension."
fi
}