-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzshrc
199 lines (173 loc) · 5.65 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
# Set up the prompt
autoload -Uz promptinit
promptinit
prompt clint
setopt histignorealldups sharehistory
# Use emacs keybindings even if our EDITOR is set to vi
# bindkey -e
# Use vim keybindings
bindkey -v
# Press esc-v to edit the command in EDITOR
# <https://stackoverflow.com/a/903973/411495>
# This is a default in bash (^X^E when in emacs mode) and... damn that can be useful
autoload -U edit-command-line
zle -N edit-command-line
bindkey -M vicmd v edit-command-line
# Keep 1000 lines of history within the shell and save it to ~/.zsh_history:
HISTSIZE=1000
SAVEHIST=1000
HISTFILE=~/.zsh_history
# Use modern completion system
autoload -Uz compinit
compinit
zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' menu select=2
case $(uname) in
Linux)
eval "$(dircolors -b)"
;;
Darwin)
export LSCOLORS="Gxfxcxdxbxegedabagacad"
;;
esac
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
#######
# Make up/down arrow limit history to the part you already typed
# (via ArchWiki)
autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
[[ -n "$key[Up]" ]] && bindkey -- "$key[Up]" up-line-or-beginning-search
[[ -n "$key[Down]" ]] && bindkey -- "$key[Down]" down-line-or-beginning-search
# Digraphs
autoload insert-composed-char
zle -N insert-composed-char
bindkey ^K insert-composed-char
# Unicode input. Press keycode, type hexa number, press keycode again
autoload insert-unicode-char
zle -N insert-unicode-char
bindkey '^Xk' insert-unicode-char
# We totally have colour
export TERM=xterm-256color
export EDITOR=vim
# Aliases
case $(uname) in
Linux)
alias ls='ls --color=auto'
;;
Darwin)
alias ls='ls -G'
;;
esac
alias grep='grep --color=auto'
alias l='ls -lF'
alias ll='ls -alF'
alias shuf="perl -MList::Util=shuffle -e 'print shuffle(<STDIN>);'"
alias myip="dig +short myip.opendns.com @resolver1.opendns.com"
alias cdgit='cd $(git rev-parse --show-toplevel)'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
# cal defaults to Sunday first day...
alias cal='ncal'
# View markdown file as a man page
function mman {
pandoc -s -t man "$1" | groff -T utf8 -man | ${PAGER:-less}
}
case $(uname) in
Linux)
alias open='xdg-open'
alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'
;;
Darwin)
# Nothing at the moment
;;
esac
## An alias for when you encounter an open directory with books.
# The --accept screws you over when the path/filename gets too long. wget
# automatically rewrites the file name when it gets too long. In doing so, the
# extension is likely to disappear and become ".tmp". Of course, that does not
# match and the file is deleted despite it being what you wanted. <_< Adding
# tmp in accept seems to work, then explicitly rejecting index.html.tmp to not
# become all cluttered.
alias wget-books='wget --recursive --no-clobber --no-parent --accept epub,mobi,pdf,tmp,cbr,cbz --reject index.html.tmp'
# Ensure the encrypted home directory is also searched
# Be sure to run ~/bin/myupdate.sh (or cron it)
export LOCATE_PATH=$HOME/.local/share/mlocate.db
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
# Notify if a reboot is required
if [ -f /var/run/reboot-required ]; then
cat /var/run/reboot-required
if [ -f /var/run/reboot-required.pkgs ]; then
echo "for package(s):"
cat /var/run/reboot-required.pkgs
fi
fi
# Add rbenv
if [ -d "$HOME/.rbenv" ]; then
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
rbenv-update() {
local current=$(pwd)
cd $HOME/.rbenv
echo "Running git pull in $(pwd)"
git pull
cd plugins/ruby-build
echo "Running git pull in $(pwd)"
git pull
cd $current
}
fi
# Only load nodejs when asked to
function load_node() {
export NVM_DIR="$HOME/.nvm"
if [ -s "/usr/local/opt/nvm/nvm.sh" ]; then
# macOS homebrew installation
. "/usr/local/opt/nvm/nvm.sh"
elif [ -s "$NVM_DIR/nvm.sh" ]; then
# Manual installation
. "$NVM_DIR/nvm.sh"
fi
if [ -s "/usr/local/opt/nvm/etc/bash_completion" ]; then
# macOS homebrew installation
# TODO: Is there something for the manual installation
. "/usr/local/opt/nvm/etc/bash_completion"
fi
}
# Rust
if [ -d "$HOME/.cargo/bin" ]; then
export PATH="$HOME/.cargo/bin:$PATH"
fi
# Anaconda python
if [ -d "$HOME/.anaconda3/bin" ]; then
export PATH="$HOME/.anaconda3/bin:$PATH"
fi
if [ -x "$(command -v fzf)" ]; then
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
alias fzf='fzf --bind "ctrl-o:execute(xdg-open {}&)"'
function fzfd() {
local dir
dir=$(/usr/bin/find ${1:-.} -path '*/\.*' -prune -o -type d -print 2> /dev/null | fzf +m) && cd "$dir"
}
export FZF_DEFAULT_COMMAND="fd --type f --hidden --exclude .git"
fi
export RIPGREP_CONFIG_PATH=$HOME/.config/ripgreprc