-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
197 lines (166 loc) · 5.8 KB
/
.zshrc
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# KTRAVERS ZSHRC
# https://github.com/ktravers/dotfiles/blob/master/.zshrc
# ======================
# Plugins
# =====================
plugins=(
bundler
capistrano
copyfile
docker
dotenv
gpg-agent
mix
macos
sublime
)
# Prompt
# =====================
PROMPT='
%F{cyan}%D{%Y-%m-%d} %* %F{magenta}%n@%m: %{$reset_color%}%1d ($(git_current_branch))
🏄♀️ '
# Helper Functions
# =====================
# A function to CD into my development directory from anywhere
function development () {
cd /Users/$USER/Development/$@
}
# A function to CD into my local blog directory from anywhere
function blog () {
cd /Users/$USER/Development/ktravers.github.io/$@
}
# A function to bring local rails project completely up to date
# USE: cd into repo first, then run command
function railsup () {
git checkout master # checkout master branch
git pull origin master --rebase --prune # pull latest from master + prune unused branches
git gc # compress
bundle # run bundler to install/update gems
yarn install # run yarn install to install/update packages
bin/rails db:migrate db:test:prepare # run db migrations
git checkout -- db/schema.rb # discard db schema changes
}
# A function to bring local phoenix project completely up to date
# USE: cd into repo first, then run command
function mixup () {
git checkout master # checkout master branch
git pull origin master --rebase --prune # pull latest from master + prune unused branches
git gc # compress
mix deps.get # update elixir deps
cd apps/*/assets/ && npm install && cd - # update js deps
mix ecto.migrate # run dev db migrations
mix ecto.migrate MIX_ENV=test # run test db migrations
}
# A function to easily grep for a matching process
# USE: findbyname postgres
function findbyname {
FIRST=`echo $1 | sed -e 's/^\(.\).*/\1/'`
REST=`echo $1 | sed -e 's/^.\(.*\)/\1/'`
ps aux | grep "[$FIRST]$REST"
}
# A function to easily grep for a matching process via lsof
# USE: findbyport 8127
# USE: findbyport ruby
function findbyport {
FIRST=`echo $1 | sed -e 's/^\(.\).*/\1/'`
REST=`echo $1 | sed -e 's/^.\(.*\)/\1/'`
lsof -n -i | grep "[$FIRST]$REST"
}
# A function to git clone a repo, cd into the newly created directory,
# and open all the repo's files in Sublime Text 3
# USE: gcsubl [email protected]:ktravers/crowdfunding-sql-lab-ruby-007.git
# credit: Jeremy Sklarsky (http://jeremysklarsky.github.io/)
function gcsubl () {
git clone $1;
cd `basename $1 .git`;
subl .
}
# Checkout next commit on current branch
# Source: https://stackoverflow.com/a/23172256/3880374
function next () {
CURRENT_BRANCH=`git for-each-ref --format='%(refname:short)' refs/heads --contains`
NEXT_COMMIT=`git log --format=%H --reverse --ancestry-path HEAD.."$CURRENT_BRANCH" | head -1`
git checkout "$NEXT_COMMIT"
}
# Checkout previous commit on current branch
# Source: https://stackoverflow.com/a/23172256/3880374
function prev () {
git checkout HEAD~
}
# Magical banner for pasting into Slack
# USE: banner "hello world" wave globe
# Source: @drewprice & @notactuallypagemcconnell
function banner() {
figlet -f banner "$1" | sed -e"s/#/:$2:/g" | sed -e"s/ /:$3:/g" | pbcopy
}
# Aliases
# =====================
# Git
alias gbdall="git branch | grep -v 'master' | xargs git branch -D"
alias gbv="git branch -v"
alias gca!='git commit --amend --no-edit'
alias gcm="git checkout master"
alias gco="git checkout"
alias glp="git --paginate log --pretty=format:'%C(auto)%h%Creset %s%C(auto)%d%Creset %C(magenta bold)(%cr)%Creset %C(cyan)<%aN>%Creset' -10"
alias glr="git pull --rebase --prune && git gc"
alias grh="git reset HEAD"
alias gst="git status"
alias gsv="git status -vv"
alias repush="git pull --rebase && git push"
alias stash="git stash -u"
# Homebrew
alias brewup='brew update; brew upgrade; brew prune; brew cleanup; brew doctor'
# GitHub CLI
# https://github.com/cli/cli
alias newpr="gh pr create -d"
# Rails
alias rs='rails s'
alias rc='rails c'
alias rcs='rails c --sandbox'
# Ruby
# credit: James Coglan "Building Git" https://shop.jcoglan.com/building-git/
alias inflate='ruby -r zlib -e "STDOUT.write Zlib::Inflate.inflate(STDIN.read)"'
# Environment Variables
# =====================
# Git
# https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables
export GIT_MERGE_AUTOEDIT="no"
export GIT_AUTHOR_NAME="Kate Travers"
export GIT_AUTHOR_EMAIL="[email protected]"
export GIT_COMMITTER_NAME="Kate Travers"
export GIT_COMMITTER_EMAIL="[email protected]"
# Editors
# Tells your shell that when a program requires various editors, use sublime.
# The -w flag tells your shell to wait until sublime exits
export VISUAL="subl -w"
export SVN_EDITOR="subl -w"
export GIT_EDITOR="subl -w"
export EDITOR="subl -w"
# Codespaces (gh/gh)
# Sets required ENV variables and increases open file limits
# See https://github.com/github/codespaces#working-on-codespaces
export CODESPACES_SPN_CLIENT_SECRET="SECRET"
export CODESPACES_REGISTRY_PASSWORD="PASSWORD"
ulimit -n 200000
ulimit -u 2048
# Path to your oh-my-zsh installation.
export ZSH="/Users/$USER/.oh-my-zsh"
# Build PATH
# =====================
# Add current directory bin
export USR_PATHS="bin"
# Add system local
export USR_PATHS="$USR_PATHS:/usr/local"
# Add homebrew's bin and sbin
export USR_PATHS="$USR_PATHS:/usr/local/bin"
export USR_PATHS="$USR_PATHS:/usr/local/sbin"
# Add system bin
export USR_PATHS="$USR_PATHS:/usr/bin"
export PATH="$USR_PATHS:$PATH"
# Final setup
# =====================
export GPG_TTY=$(tty)
eval "$(direnv hook zsh)"
source $ZSH/oh-my-zsh.sh
. /usr/local/opt/asdf/asdf.sh
. /usr/local/opt/asdf/etc/bash_completion.d/asdf.bash