forked from niclin/dotfile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
176 lines (150 loc) · 4.98 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
DEFAULT_USER=" Jimmy"
export PATH="$HOME/.tmuxifier/bin:$PATH"
export ZSH="$HOME/.oh-my-zsh"
export EDITOR=vim
export LANG=en_US.UTF-8
# RabbitMQ Config
export PATH=$PATH:/usr/local/sbin
ZSH_THEME="agnoster"
plugins=(git)
source $ZSH/oh-my-zsh.sh
#disable START/STOP output control (<C-S>, <C-Q>)
stty -ixon
# 重啟 puma
#
# - rpu → 啟動或重啟(如果已有 pid)
# - rpu kill → 殺掉 process,不重啟
rpu() {
emulate -L zsh
if [[ -d tmp ]]; then
local action=$1
local pid
local animal
if [[ -f config/puma.rb ]]; then
animal='puma'
else
echo "No puma directory, aborted."
return 1
fi
if [[ -r tmp/pids/server.pid && -n $(ps h -p `cat tmp/pids/server.pid` | tr -d ' ') ]]; then
pid=`cat tmp/pids/server.pid`
fi
if [[ -n $action ]]; then
case "$action" in
pry)
if [[ -n $pid ]]; then
kill -9 $pid && echo "Process killed ($pid)."
fi
rserver_restart $animal
;;
kill)
if [[ -n $pid ]]; then
kill -9 $pid && echo "Process killed ($pid)."
else
echo "No process found."
fi
;;
*)
if [[ -n $pid ]]; then
# TODO: control unicorn
pumactl -p $pid $action
else
echo 'ERROR: "No running PID (tmp/pids/server.pid).'
fi
esac
else
if [[ -n $pid ]]; then
# Alternatives:
# pumactl -p $pid restart
# kill -USR2 $pid && echo "Process killed ($pid)."
# kill -9 (SIGKILL) for force kill
kill -9 $pid && echo "Process killed ($pid)."
rserver_restart $animal $([[ "$animal" == 'puma' ]])
else
rserver_restart $animal $([[ "$animal" == 'puma' ]])
fi
fi
else
echo 'ERROR: "tmp" directory not found.'
fi
}
# 這是 rpu 會用到的 helper function
rserver_restart() {
case "$1" in
puma)
shift
bundle exec puma -C config/puma.rb config.ru --pidfile "tmp/pids/server.pid"
;;
*)
echo 'invalid argument'
esac
}
# Something new for me was using command utility to call the OS's default touch command when we are overriding it.
touch () {
mkdir -p "$(dirname "$1")"
command touch "$1"
}
export GITHUB_UPSTREAM='otcbtc'
#function pr_for_sha {
#git log --merges --ancestry-path --oneline $1..master | grep 'pull request' | tail -n1 | awk '{print $5}' | cut -c2- | xargs -I % open https://github.com/$GITHUB_UPSTREAM/${PWD##*/}/pull/%
#}
pr_otc_sha() {
current_branch = git branch | grep \* | cut -d ' ' -f2
git log --merges --ancestry-path --oneline $1..$current_branch | grep 'pull request' | tail -n1 | awk '{print $5}' | cut -c2- | xargs -I % open https://github.com/$GITHUB_UPSTREAM/${PWD##*/}/pull/%
}
export GITHUB_UPSTREAM_1='caibaoshuo'
pr_cai_sha() {
current_branch = git branch | grep \* | cut -d ' ' -f2
git log --merges --ancestry-path --oneline $1..$current_branch | grep 'pull request' | tail -n1 | awk '{print $5}' | cut -c2- | xargs -I % open https://github.com/$GITHUB_UPSTREAM_1/${PWD##*/}/pull/%
}
# [rails]
alias jim='pwd'
alias rs='rails s'
alias rc='rails c'
alias bi='bundle install'
alias besr='bundle exec spring rspec'
alias ram='rake annotate_models'
alias rlog='tail -f log/development.log'
alias bsl='brew services list'
alias bsr='brew services restart '
alias bss='brew services start --all' #開啟所有 brew 相關 services
alias lsps='ps -elf | grep'
# history | awk '{a[$2]++}END{for(i in a){print a[i]" "i}}' | sort -rn | head
# [git]
alias gre='git remote -v'
alias gs='git status'
alias gotowork='tmuxifier load-window example'
alias rbb='rubocop -a'
# [eslint-alias] standard
stn() {
standard | grep "$1" | snazzy
}
# [tmux]
alias ttl='tmux ls'
alias tt='tmux attach -t '
alias ttk='tmux kill-session -t'
alias ttka='tmux list-sessions | grep -v attached | cut -d: -f1 | xargs -t -n1 tmux kill-session -t'
# 常用 alias
alias ll='ls -al'
alias z='vim ~/.zshrc'
alias zx='cat ~/.zshrc'
alias nrd='npm run dev'
alias blog='cd ~/Dropbox/jimmy_de_blog/hexo-blog'
alias fjo='cd ~/Project2018/forjob/otcbtc'
alias fjc='cd ~/Project2018/forjob/caibaoshuo'
alias fje='cd ~/Project2018/forjob/exchange-client'
alias ffd='cd ~/Project2018/forfun/dd3'
alias ff='cd ~/Project2018/forfun/'
alias fj='cd ~/Project2020/forjob/'
alias rmf='rm -rf'
alias docker on='docker-compose up -d'
alias docker off='docker-compose stop'
alias fv='defaults write com.apple.finder AppleShowAllFiles TRUE;\killall Finder'
alias fh='defaults write com.apple.finder AppleShowAllFiles FALSE;\killall Finder'
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
source /usr/local/opt/nvm/nvm.sh
# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"