This repository has been archived by the owner on Sep 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zsh-alias
130 lines (100 loc) · 3.42 KB
/
zsh-alias
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
# Send a growl notification after a long–running command finishes
function alert() {
"$@" && growlnotify -a iTerm -m "Completed with exit code $?" "$@";
}
# count lines
alias count="sort | uniq -c | sort -n"
# One Command To Rule Them All
alias edit=$EDITOR
# flush DNS cache (Mac OS X)
alias flushdns="dscacheutil -flushcache"
alias dnsflush="flushdns"
# clear autocorrect cache
alias fix-autocorrect='hash -rf'
# fucking postgres
alias gimmeafuckingpostgresqlprompt="psql -h localhost"
alias pg=gimmeafuckingpostgresqlprompt
# github-git integration
[[ -x `which hub` ]] && alias git=hub
# quickly edit the hosts file
alias hosts="edit /etc/hosts"
# get the IP address for a domain
function ipfor(){
dig +short $1 | grep -E '^[0-9.]+$' | head -1
}
# make ls suck less
alias ls='ls -1p'
# CD to projects
function p {
if [[ -n "$1" ]] && [[ -d ~/Projects/$1 ]]; then
cd ~/Projects/$1;
return;
fi
if [[ -x `which selecta` ]]; then
cd $(find ~/Projects -maxdepth 1 -type d | selecta)
return;
fi
cd ~/Projects;
}
# open files in vim
function vimf () {
vim -o $(find * -type f | selecta)
}
# fix and shrink png files. pass infile and outfile.
alias pngfix="pngcrush -rem gAMA -rem cHRM -rem iCCP -rem sRGB $1 $2"
# quicklook a file
alias quicklook='qlmanage -p "$@" >& /dev/null'
# reload zsh config
alias reload='source ~/.zshrc'
# `repeatchar x 10` => `xxxxxxxxxx`
function repeatchar () {
printf "%${2}s" "" | tr " " $1;
}
# lazy ruby/git stuff
alias be='bundle exec'
alias g=git
alias r=rails
# quickly open Xcode projects and workspaces
function xcode {
# get an array of .xcworkspace and .xcodeproj files
workspaces=(`ls -d1 *.(xcworkspace|xcodeproj) | sed -e "s/\///g"`) &> /dev/null
filenames=(`ls -d1 *.(xcworkspace|xcodeproj) | sed -e "s/\..*$//g"`) &> /dev/null
if [[ ${#workspaces} == 0 ]]; then
echo "No Xcode projects or workspaces were found."
return
fi
# if there's just one matching file, open it.
if [[ ${#workspaces} == 1 ]]; then
`open $workspaces[1] -a /Applications/Xcode.app`
return
fi
# if there's just and xcodeproj and xcworkspace with the same name,
# open the xcworkspace - it's probably a Cocoapods setup.
if [[ ${#workspaces} == 2 ]]; then
if [[ $filenames[1] == $filenames[2] ]]; then
`open $workspaces[2] -a /Applications/Xcode.app`
return
fi
fi
# present a list of projects/workspaces, de-duped by name
counter=1
echo "Multiple choice currently isn't enabled. Available workspaces:"
for workspace in workspaces; do
echo "$counter. $workspace"
set counter += 1
done
}
# fucking Xcode
# http://www.mikeash.com/pyblog/solving-simulator-bootstrap-errors.html
alias xcode-unfuck-bootstrap="launchctl list|grep UIKitApplication|awk '{print $3}'|xargs launchctl remove"
# http://inessential.com/2012/04/23/ded
alias xcode-unfuck-deriveddata="rm -rf ~/Library/Developer/Xcode/DerivedData"
# fucking Finder.app
# http://www.leancrew.com/all-this/2013/02/getting-rid-of-open-with-duplicates/
alias fixopenwith='/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user'
# because I will literally never be able to remember this
alias unixtime="date +%s"
# install vim bundles for the first time
alias vim-install-bundles='vim -u ~/.vim/vundle.vim +BundleInstall +q'
# use: "wifi on" or "wifi off"
alias wifi='networksetup -setairportpower airport'