blob: 88ae0b842f93126bc2e1d1ce27d621063456414e (
plain) (
blame)
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
|
# plugins - fzf
# fzf is automatically picked up by /etc/profile on cygwin, but manjaro installs them here
if [[ -a /usr/share/fzf/key-bindings.zsh ]] && [[ -a /usr/share/fzf/completion.zsh ]]; then
export FZF_DEFAULT_OPTS='--no-height --no-reverse'
source /usr/share/fzf/key-bindings.zsh
source /usr/share/fzf/completion.zsh
fi
# magic cd
setopt autocd
export CDPATH=".:$HOME:$HOME/devil:$HOME/src"
# spelling correction... TBA if we like this
# could also use correct_all & potentially alias some things with nocorrect
setopt correct
# just enables a bit nicer life when copy/pasting commands from docs
setopt interactive_comments
# completions
setopt complete_in_word # complete both ends of words
setopt always_to_end # and move cursor to the end afterward
setopt auto_menu # <tab><tab> brings up the menu ...
setopt no_menu_complete # ... and does not select the first option
setopt auto_param_slash # convenience: add trailing / after directories
setopt extended_glob
setopt no_case_glob
setopt no_flow_control
zstyle ':completion:*' special-dirs true
# cache completions
zstyle ':completion::complete:*' use-cache yes
zstyle ':completion::complete:*' cache-path "$HOME/.zcompcache"
# enable completions
autoload -Uz compinit && compinit
# history
HISTFILE=${ZDOTDIR:-$HOME}/.zsh_history
HISTSIZE=10000
SAVEHIST=$HISTSIZE
setopt extended_history # write timestamp
setopt inc_append_history # write always, not just at end of session
setopt hist_ignore_space # add leading space to hide from history
setopt hist_ignore_dups # deduplicate commands run twice in a row
setopt hist_verify # confirm before executing
# vi mode
bindkey -v
# make backspace and delete behave like vim
bindkey -M viins '^?' backward-delete-char
bindkey -M viins '^H' backward-delete-char
bindkey -M viins '^[[3~' delete-char
# display block cursor in normal mode
function zle-keymap-select zle-line-init zle-line-finish {
case $KEYMAP in
vicmd) echo -ne "\e[2 q";;
viins|main) echo -ne "\e[6 q";;
esac
zle reset-prompt
zle -R
}
zle -N zle-keymap-select
zle -N zle-line-init
zle -N zle-line-finish
# colors in various core utils
alias diff='diff --color'
alias ls='ls --color=auto'
export LESS='-R'
grep_opts="--color=auto --exclude-dir=.git"
alias grep="grep $grep_opts"
alias egrep="egrep $grep_opts"
alias fgrep="fgrep $grep_opts"
unset grep_opts
# dots go up
alias -g ...='../..'
alias -g ....='../../..'
alias -g .....='../../../..'
# aliases
alias cls=clear
alias config='git --git-dir=$HOME/.dotfiles --work-tree=$HOME'
alias ll='ls -l --almost-all --no-group --human-readable'
alias mkdir='mkdir -p'
if command -v gpg2 &> /dev/null; then
alias gpg='gpg2'
fi
# collapse spaces into tabs in-place
# spacetotab <FILE> [WIDTH=4]
function spacetotab () {
unexpand --tabs=${2:-4} --first-only "$1" > "$1.tmp"
mv "$1.tmp" "$1"
}
# prompt
# TODO maybe just use someone else's theme altogether
# TODO git integration was useful - port something from belak/zsh-utils or ohmyzsh
# TODO location should control its length a little better
# TODO only color the last segment of the path (pwd)
user="%n"
if [[ -n "$SSH_CLIENT" || "$USER" == "root" ]]; then
user+="@%M"
fi
last_status="%(?.%F{green}%#.%F{red}%?)%f"
location="%F{blue}%3~%f"
PROMPT="[$user:$location] $last_status "
RPROMPT="%!"
unset user
unset last_status
unset location
# display a fortune when opening an interactive terminal
tty -s && fortune $HOME/fortunes 2>/dev/null ||:
|