summaryrefslogtreecommitdiffstats
path: root/.config/zsh/.zshrc
blob: 37acce61f5d85cc868ceed787bfa8e833fce9835 (plain)
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
# .zshrc
# ========================
# =====    ===============
# ======  ================
# ======  ================
# ======  ====   ====   ==
# ======  ===     ==  =  =
# ======  ===  =  ==     =
# =  ===  ===  =  ==  ====
# =  ===  ===  =  ==  =  =
# ==     =====   ====   ==
# ========================

[ -z "$TMUX"  ] && export TERM=xterm-256color || export TERM=screen-256color

autoload -U colors && colors

HISTSIZE=1000000
SAVEHIST=1000000
HISTFILE=$XDG_CONFIG_HOME/zsh/history

case $(hostname -s) in
	mother|po-rbo)
		os_color='\e[1;34m'
		prompt_main="red"
		prompt_alt="blue"
		;;
	mars)
		os_color='\e[1;31m'
		prompt_main="red"
		prompt_alt="blue"
		;;
esac

LESS_TERMCAP_mb=$(printf $os_color);		export LESS_TERMCAP_mb
LESS_TERMCAP_md=$(printf $os_color);		export LESS_TERMCAP_md
LESS_TERMCAP_me=$(printf '\e[0m');			export LESS_TERMCAP_me
LESS_TERMCAP_so=$(printf '\e[1;33;40m');	export LESS_TERMCAP_so
LESS_TERMCAP_se=$(printf '\e[0m');			export LESS_TERMCAP_se
LESS_TERMCAP_us=$(printf '\e[0;4;35m');		export LESS_TERMCAP_us
LESS_TERMCAP_ue=$(printf '\e[0m');			export LESS_TERMCAP_ue

autoload -U history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end

setopt inc_append_history
setopt share_history

zstyle ':completion:*' completer _complete
zstyle ':completion:*' matcher-list '' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' '+l:|=* r:|=*'
zstyle ':completion:*' menu select
zstyle ':completion:*' list-colors 'di=34:ln=35:so=32:pi=33:ex=31:bd=46;34:cd=43;34:su=41;30:sg=46;30:tw=42;30:ow=43;30'
autoload -U compinit
zmodload zsh/complist
compinit
_comp_options+=(globdots)

bindkey -v
KEYTIMEOUT=1
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'j' vi-down-line-or-history
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'l' vi-forward-char
bindkey -v "^?" backward-delete-char
bindkey -v "^[[A" history-beginning-search-backward
bindkey -v "^[[B" history-beginning-search-forward
bindkey -M vicmd "k" history-beginning-search-backward
bindkey -M vicmd "j" history-beginning-search-forward
bindkey -v "^P" history-beginning-search-backward
bindkey -v "^N" history-beginning-search-forward

autoload edit-command-line && zle -N edit-command-line
bindkey "^e" edit-command-line

autoload -U add-zsh-hook
eza_after_cd() {
	eza -l --icons --color=always --group-directories-first --no-permissions --no-user --no-time --no-filesize
}
add-zsh-hook chpwd eza_after_cd

autoload -Uz url-quote-magic
zle -N self-insert url-quote-magic
autoload -Uz bracketed-paste-magic
zle -N bracketed-paste bracketed-paste-magic

[ -f "$ZDOTDIR"/alias.zsh ]								&& source "$ZDOTDIR"/alias.zsh
[ -f "$ZDOTDIR"/plugins.zsh ]							&& source "$ZDOTDIR"/plugins.zsh
[ -f "$XDG_PACKAGE_HOME"/fzf/shell/completion.zsh ]		&& source "$XDG_PACKAGE_HOME"/fzf/shell/completion.zsh
[ -f "$XDG_PACKAGE_HOME"/fzf/shell/key-bindings.zsh ]	&& source "$XDG_PACKAGE_HOME"/fzf/shell/key-bindings.zsh
[ -f "$XDG_CONFIG_HOME"/lf/icons ] && {
	LF_ICONS="$(tr '\n' ':' <"$XDG_CONFIG_HOME"/lf/icons)" \
		&& export LF_ICONS
}

globalias() {
	if [[ $LBUFFER =~ ^[a-z0-9]+$ ]]; then
		zle _expand_alias
		zle expand-word
	fi
	# zle self-insert
}

zle -N globalias

# Use lf to switch directories and bind it to ctrl-o
lfcd () {
    tmp="$(mktemp)"
    lf -last-dir-path="$tmp" "$@"
    if [ -f "$tmp" ]; then
        dir="$(cat "$tmp")"
        rm -f "$tmp" >/dev/null
        [ -d "$dir" ] && [ "$dir" != "$(pwd)" ] && cd "$dir"
    fi
}
nnncd ()
{
    # Block nesting of nnn in subshells
    [ "${NNNLVL:-0}" -eq 0 ] || {
        echo "nnn is already running"
        return
    }

    # The behaviour is set to cd on quit (nnn checks if NNN_TMPFILE is set)
    # If NNN_TMPFILE is set to a custom path, it must be exported for nnn to
    # see. To cd on quit only on ^G, remove the "export" and make sure not to
    # use a custom path, i.e. set NNN_TMPFILE *exactly* as follows:
    #      NNN_TMPFILE="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd"
    export NNN_TMPFILE="/tmp/nnn_lastd"

    # Unmask ^Q (, ^V etc.) (if required, see `stty -a`) to Quit nnn
    # stty start undef
    # stty stop undef
    # stty lwrap undef
    # stty lnext undef

    # The command builtin allows one to alias nnn to n, if desired, without
    # making an infinitely recursive alias
    command nnn "$@"

    [ ! -f "$NNN_TMPFILE" ] || {
        . "$NNN_TMPFILE"
        rm -f -- "$NNN_TMPFILE" > /dev/null
    }
}
bindkey -s '^o' '^unnncd\n'

bindkey -v "^ " globalias
bindkey -v " " magic-space
bindkey -M isearch " " magic-space

_gen_fzf_default_opts() {

local color00='#1d2021'
local color01='#282828'
local color02='#504945'
local color03='#665c54'
local color04='#a89984'
local color05='#bdae93'
local color06='#ebdbb2'
local color07='#fbf1c7'
local color08='#cc241d'
local color09='#fe8019'
local color0A='#d79921'
local color0B='#98971a'
local color0C='#689d6a'
local color0D='#458588'
local color0E='#b16286'
local color0F='#d65d0e'

export FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS"\
" --color=bg+:$color00,bg:$color00"\
" --color=fg:$color05,fg+:$color06"\
" --color=hl:$color08,hl+:$color08"\
" --color=spinner:$color0D"\
" --color=header:$color08,info:$color03,pointer:$color08"\
" --color=marker:$color0C,prompt:$color0A"

}

_gen_fzf_default_opts

PROMPT="%B%{$fg[$prompt_main]%}%m %{$fg[$prompt_alt]%}%c%{$fg[$prompt_main]%}%#%{$reset_color%} "
RPROMPT="%{$fg_bold[red]%}%(?..%?)%{$reset_color%}"