-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path.zshrc
More file actions
177 lines (144 loc) · 4.64 KB
/
.zshrc
File metadata and controls
177 lines (144 loc) · 4.64 KB
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
## Environment
export LANG=ja_JP.UTF-8
export EDITOR=vim
## Shell options
setopt auto_cd # cd by typing directory name
setopt auto_pushd # push directories to stack on cd
setopt pushd_ignore_dups # no duplicate entries in directory stack
setopt nocorrect # disable command auto-correction
setopt nonomatch # pass unmatched globs as literal strings
setopt list_packed # compact completion list
setopt noautoremoveslash # keep trailing slash on completions
setopt nolistbeep no_beep # disable all beep sounds
setopt ignoreeof # disable Ctrl+D shell exit
setopt interactivecomments # allow # comments in interactive shell
setopt extended_glob # enable extended glob patterns
unsetopt promptcr # allow output without trailing newline
case ${OSTYPE} in
linux*) export GLFW_IM_MODULE=ibus ;;
esac
umask 002
## History
HISTFILE=~/.zsh_history
HISTSIZE=1000000
SAVEHIST=$HISTSIZE
setopt hist_ignore_dups # ignore consecutive duplicate commands
setopt hist_ignore_all_dups # remove older duplicate entries
setopt hist_reduce_blanks # strip extra whitespace from commands
setopt hist_verify # confirm history expansion before executing
setopt share_history # share history across sessions
## Keybindings
stty -ixon # disable XON/XOFF to allow ^S for history search
bindkey -e # emacs key bindings
# ^P/^N: history search matching current line prefix
autoload history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey "^P" history-beginning-search-backward-end
bindkey "^N" history-beginning-search-forward-end
export WORDCHARS="" # treat symbols as word delimiters
bindkey '^I' complete-word # Tab: complete word
case ${OSTYPE} in
darwin*)
bindkey "^[[1;3C" forward-word # Option+Right: forward word
bindkey "^[[1;3D" backward-word # Option+Left: backward word
;;
esac
## Completion
setopt complete_aliases # enable completion for aliased commands
zstyle ':completion:*' verbose yes
zstyle ':completion:*:descriptions' format '%B%d%b'
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:warnings' format 'No matches for: %d'
zstyle ':completion:*' group-name ''
## Aliases
# ls color flag differs by OS (-G for macOS, --color=auto for Linux)
case ${OSTYPE} in
darwin*) LS_COLOR=-G ;;
linux*) LS_COLOR=--color=auto ;;
esac
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias ls="ls -F $LS_COLOR"
alias ll="ls -aFhl $LS_COLOR"
alias la="ls -aF $LS_COLOR"
alias lt="ls -aFhlt $LS_COLOR | head -10"
alias less='less -M'
alias grep='grep -E --color'
alias g='git'
alias h='history -16'
alias l='less'
## PATH
typeset -U PATH
case ${OSTYPE} in
darwin*)
export PATH=/opt/homebrew/bin:$PATH
export PATH=$HOME/.local/bin:$PATH
;;
linux*)
export PATH=/usr/local/bin:$PATH
;;
esac
# Ruby / Perl / Python version managers
[ -d ~/.rbenv ] && export PATH=~/.rbenv/bin:$PATH
[ -d ~/.plenv ] && export PATH=~/.plenv/bin:$PATH
[ -d ~/.pyenv ] && export PATH=~/.pyenv/bin:$PATH
command -v rbenv >/dev/null && eval "$(rbenv init -)"
command -v plenv >/dev/null && eval "$(plenv init -)"
command -v pyenv >/dev/null && eval "$(pyenv init -)"
## Oh My Zsh
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="robbyrussell"
plugins=(git zsh-completions zsh-autosuggestions fast-syntax-highlighting fzf-tab)
typeset -U fpath
case ${OSTYPE} in
darwin*) fpath=(/opt/homebrew/share/zsh/site-functions $fpath) ;;
esac
fpath=(${ZSH_CUSTOM:-$ZSH/custom}/plugins/zsh-completions/src(N) $fpath)
[ -f "$ZSH/oh-my-zsh.sh" ] && source "$ZSH/oh-my-zsh.sh"
## Tmux auto-start
is_screen_running() {
[ ! -z "$WINDOW" ]
}
is_tmux_running() {
[ ! -z "$TMUX" ]
}
is_screen_or_tmux_running() {
is_screen_running || is_tmux_running
}
shell_has_started_interactively() {
[ ! -z "$PS1" ]
}
resolve_alias() {
cmd="$1"
while \
whence "$cmd" >/dev/null 2>/dev/null \
&& [ "$(whence "$cmd")" != "$cmd" ]
do
cmd=$(whence "$cmd")
done
echo "$cmd"
}
if ! is_screen_or_tmux_running && shell_has_started_interactively; then
for cmd in tmux tscreen screen; do
if whence $cmd >/dev/null 2>/dev/null; then
$(resolve_alias "$cmd")
break
fi
done
fi
## Additional configs
[ -f ~/.zshrc.mine ] && source ~/.zshrc.mine
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
command -v fd >/dev/null && export FZF_DEFAULT_COMMAND='fd --type file --hidden --no-ignore'
if command -v zoxide >/dev/null; then
eval "$(zoxide init zsh)"
# zoxide wrapper: run pwd after z/zi
function z() {
__zoxide_z "$@" && pwd
}
function zi() {
__zoxide_zi "$@" && pwd
}
fi