-
Notifications
You must be signed in to change notification settings - Fork 11
/
zshrc
149 lines (122 loc) · 3.02 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
# Custom Completions
_git-db() { _git-checkout }
_git-dbf() { _git-checkout }
_git-delete-tag() { compadd "$@" $(git tag) }
_git-retag() { compadd "$@" $(git tag) }
_git-pr() { _gh-pull-request }
# Styles
zstyle ':completion:*:sudo:*' command-path $path
zstyle ':prompt:grml:left:setup' items percent rc
zstyle ':prompt:grml:right:setup' items path vcs
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:git:*' actionformats '[%r:%b|%a]'
zstyle ':vcs_info:git:*' formats '[%r:%b]'
# Aliases & Functions
alias g=git
alias p="sudo pacman"
clone() {
case "$1" in
*/*)
target=$HOME/code/$1
mkdir -p "$(dirname "$target")"
git clone "[email protected]:$1" "$target"
cd "$target"
;;
esac
}
setup_nvm() {
if [[ -f ./package.json ]] || [[ -f .nvmrc ]]; then
source /usr/share/nvm/init-nvm.sh
nvm use
fi
}
setup_venv() {
if [[ -f ./.venv/bin/activate ]]; then
source ./.venv/bin/activate
fi
}
chpwd_functions+=(setup_nvm setup_venv)
# Bindings & Options
bindkey '^[[Z' reverse-menu-complete # Shift-Tab
bindkey -M viins '^?' backward-delete-char # Backspace
# Use *all* of command-line so far when navigating history up/down
bindkey '^[[A' history-beginning-search-backward
bindkey '^[[B' history-beginning-search-forward
bindkey -M vicmd 'k' history-beginning-search-backward
bindkey -M vicmd 'j' history-beginning-search-forward
# v to edit command in $VISUAL or $EDITOR
autoload -U edit-command-line
zle -N edit-command-line
bindkey -M vicmd v edit-command-line
setopt inc_append_history
setopt vi
unsetopt nomatch
# Autosuggestions
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#808080"
for _plugins in /usr/local/share /usr/share/zsh/plugins; do
_plugin=$_plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
if [[ -f "$_plugin" ]]; then
source "$_plugin"
bindkey '^ ' autosuggest-execute
fi
done
unset _plugin
unset _plugins
# GPG
export GPG_TTY="$(tty)"
# Bundler
export BUNDLE_PATH=$(ruby -e 'puts Gem.user_dir')
# History
HISTSIZE=500000
SAVEHIST=$HISTSIZE
# Paths
cdpath=(
~
~/code
~/code/freckle
~/code/pbrisbin
~/code/restyled-io/
$cdpath
)
fpath=(
~/.local/share/zsh/site-functions
$fpath
)
path=(
~/.local/bin
$BUNDLE_PATH/bin
$path
)
# Completion
autoload bashcompinit && bashcompinit
autoload -Uz compinit && compinit
if [[ -f /usr/bin/aws_completer ]]; then
complete -C /usr/bin/aws_completer aws
fi
# SSH Agent
ssh_env="$HOME/.ssh/agent-env"
setup_ssh_agent() {
if pgrep ssh-agent >/dev/null; then
if [[ -f $ssh_env ]]; then
source "$ssh_env"
else
echo "ssh-agent running but $ssh_env not found" >&2
fi
else
ssh-agent | grep -Fv echo > "$ssh_env"
source "$ssh_env"
# Use pass(1), via wrapper script, to unlock SSH key
DISPLAY=99 SSH_ASKPASS="$HOME/.local/bin/ssh-askpass" ssh-add </dev/null
fi
}
# Start X
if [[ $TTY == /dev/tty1 ]] && [[ -z $DISPLAY ]]; then
exec startx
fi
setup_ssh_agent
setup_nvm
setup_venv
# Increased ulimit needed for some projects
ulimit -n 2048
popd >/dev/null