-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
227 lines (192 loc) · 7.47 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
PROMPT="%D{%T} %~ $ "
source ~/.aliases
export EDITOR=vim
export SHELL=zsh
export LANG=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
LC_ALL=en_US.UTF-8
[ -f ~/.tmux/plugins/tmuxinator/completion ] && source ~/.tmux/plugins/tmuxinator/completion
##############################################################################
# History Configuration
##############################################################################
HISTSIZE=10000 #How many lines of history to keep in memory
HISTFILE=~/.zsh_history #Where to save history to disk
SAVEHIST=15000 #Number of history entries to save to disk
HISTDUP=erase #Erase duplicates in the history file
setopt appendhistory #Append history to the history file (no overwriting)
setopt sharehistory #Share history across terminals
setopt incappendhistory #Immediately append to the history file, not just when a term is killed
############################################################
# personal
function c() { cd ~/code/$@; }
function h() { cd ~/$@; }
function v() { vim $@; }
function f() { grep -r $@ .;}
function gamend() {git commit --amend -m "$*";}
function ga() {git add "*$@*";}
function gl() {git log --pretty=oneline;}
function gcp() {git add -A && git commit -m "$*" && git push;}
function opendiff () { vim -p $(git status -s | awk '{print $2}') }
function youtube-mp3() { youtube-dl --extract-audio --audio-format mp3 $@; }
function showPATH() { echo $PATH | tr ":" "\n" }
export PATH=/usr/local/bin:$PATH
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$HOME/go/bin
export PATH=$PATH:$HOME/.local/bin
##############################################################################
# vi-mode
##############################################################################
# enable vi mode
zle -N edit-command-line
bindkey -v
# allow v to edit the command line (standard behaviour)
autoload -Uz edit-command-line
bindkey -M vicmd 'v' edit-command-line
# allow ctrl-p, ctrl-n for navigate history (standard behaviour)
bindkey '^P' up-history
bindkey '^N' down-history
# allow ctrl-h, ctrl-w, ctrl-? for char and word deletion (standard behaviour)
bindkey '^?' backward-delete-char
bindkey '^h' backward-delete-char
bindkey '^w' backward-kill-word
# allow ctrl-a and ctrl-e to move to beginning/end of line
bindkey '^a' beginning-of-line
bindkey '^e' end-of-line
##############################################################################
##############################################################################
# fzf (this needs to be after vi-mode to avoid being overwritten)
case "$(uname -s)" in
Darwin)
[ -f ~/.fzf.zsh.osx ] && source ~/.fzf.zsh.osx
;;
Linux)
[ -f ~/.fzf.zsh.linux ] && source ~/.fzf.zsh.linux
;;
*)
;;
esac
# hit CTRL + z to go to background and foreground
fancy-ctrl-z () {
if [[ $#BUFFER -eq 0 ]]; then
BUFFER="fg"
zle accept-line
else
zle push-input
zle clear-screen
fi
}
zle -N fancy-ctrl-z
bindkey '^Z' fancy-ctrl-z
# No arguments: `git status`
# With arguments: acts like `git`
g() {
if [[ $# -gt 0 ]]; then
git "$@"
else
git status
fi
}
##############################################################################
# git prompt
##############################################################################
setopt prompt_subst
autoload -U colors && colors # Enable colors in prompt
# Modify the colors and symbols in these variables as desired.
GIT_PROMPT_SYMBOL="%{$fg[blue]%}±"
GIT_PROMPT_PREFIX=""
GIT_PROMPT_SUFFIX=" "
GIT_PROMPT_AHEAD="%{$fg[red]%}ANUM%{$reset_color%}"
GIT_PROMPT_BEHIND="%{$fg[cyan]%}BNUM%{$reset_color%}"
GIT_PROMPT_MERGING="%{$fg[magenta]%}⚡︎%{$reset_color%}"
GIT_PROMPT_UNTRACKED="%{$fg[red]%}●%{$reset_color%}"
GIT_PROMPT_MODIFIED="%{$fg[yellow]%}●%{$reset_color%}"
GIT_PROMPT_STAGED="%{$fg[green]%}●%{$reset_color%}"
# Show Git branch/tag, or name-rev if on detached head
parse_git_branch() {
(git symbolic-ref -q HEAD || git name-rev --name-only --no-undefined --always HEAD) 2> /dev/null
}
# Show different symbols as appropriate for various Git repository states
parse_git_state() {
# Compose this value via multiple conditional appends.
local GIT_STATE=""
local NUM_AHEAD="$(git log --oneline @{u}.. 2> /dev/null | wc -l | tr -d ' ')"
if [ "$NUM_AHEAD" -gt 0 ]; then
GIT_STATE=$GIT_STATE${GIT_PROMPT_AHEAD//NUM/$NUM_AHEAD}
fi
local NUM_BEHIND="$(git log --oneline ..@{u} 2> /dev/null | wc -l | tr -d ' ')"
if [ "$NUM_BEHIND" -gt 0 ]; then
GIT_STATE=$GIT_STATE${GIT_PROMPT_BEHIND//NUM/$NUM_BEHIND}
fi
local GIT_DIR="$(git rev-parse --git-dir 2> /dev/null)"
if [ -n $GIT_DIR ] && test -r $GIT_DIR/MERGE_HEAD; then
GIT_STATE=$GIT_STATE$GIT_PROMPT_MERGING
fi
if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
GIT_STATE=$GIT_STATE$GIT_PROMPT_UNTRACKED
fi
if ! git diff --quiet 2> /dev/null; then
GIT_STATE=$GIT_STATE$GIT_PROMPT_MODIFIED
fi
if ! git diff --cached --quiet 2> /dev/null; then
GIT_STATE=$GIT_STATE$GIT_PROMPT_STAGED
fi
if [[ -n $GIT_STATE ]]; then
echo "$GIT_PROMPT_PREFIX$GIT_STATE$GIT_PROMPT_SUFFIX"
fi
}
# If inside a Git repository, print its branch and state
git_prompt_string() {
local git_where="$(parse_git_branch)"
[ -n "$git_where" ] && echo "$(parse_git_state)%{$fg[gray]%}${git_where#(refs/heads/|tags/)}"
}
####################### streaming ####################################
# https://wiki.archlinux.org/index.php/Streaming_to_twitch.tv
## Usage: $ streaming streamkeyhere
streaming() {
INRES="1280x720" # input resolution
OUTRES="1280x720" # output resolution
FPS="30" # target FPS
GOP="60" # i-frame interval, should be double of FPS,
GOPMIN="30" # min i-frame interval, should be equal to fps,
THREADS="2" # max 6
CBR="1000k" # constant bitrate (should be between 1000k - 3000k)
QUALITY="ultrafast" # one of the many FFMPEG preset
AUDIO_RATE="44100"
STREAM_KEY="$1" # use the terminal command Streaming streamkeyhere to stream your video to twitch or justin
SERVER="live-sao" # twitch server in sao paulo, see https://stream.twitch.tv/ingests/ for list
case "$(uname -s)" in
Darwin)
ffmpeg -f avfoundation -s "$INRES" -r "$FPS" -i :0.0 -f avfoundation -i 0 -f flv -ac 2 -ar $AUDIO_RATE \
-vcodec libx264 -g $GOP -keyint_min $GOPMIN -b:v $CBR -minrate $CBR -maxrate $CBR -pix_fmt yuv420p\
-s $OUTRES -preset $QUALITY -tune film -acodec aac -threads $THREADS -strict normal \
-bufsize $CBR "rtmp://$SERVER.twitch.tv/app/$STREAM_KEY"
;;
Linux)
ffmpeg -f x11grab -s "$INRES" -r "$FPS" -i :0.0 -f pulse -i 0 -f flv -ac 2 -ar $AUDIO_RATE \
-vcodec libx264 -g $GOP -keyint_min $GOPMIN -b:v $CBR -minrate $CBR -maxrate $CBR -pix_fmt yuv420p\
-s $OUTRES -preset $QUALITY -tune film -acodec aac -threads $THREADS -strict normal \
-bufsize $CBR "rtmp://$SERVER.twitch.tv/app/$STREAM_KEY"
;;
*)
;;
esac
}
# Set the right-hand prompt
# RPS1='$(git_prompt_string)'
######################################################################
case "$(uname -s)" in
Darwin)
[ -L $HOME/.zshrc.osx ] && source $HOME/.zshrc.osx
;;
Linux)
[ -L $HOME/.zshrc.linux ] && source $HOME/.zshrc.linux
;;
*)
;;
esac
export TERM="xterm-256color"
eval "$(rbenv init - zsh)"