-
Notifications
You must be signed in to change notification settings - Fork 2
/
zshrc
181 lines (153 loc) · 4.03 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
{{#if dotter.packages.zsh}}
#==> Zsh options
# Prompt
setopt PROMPT_SUBST
zstyle ':completion:*' completer _expand _complete _ignored _correct _approximate
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' menu select=0
autoload -Uz compinit
compinit
# History
HISTFILE=~/.zsh_history
HISTSIZE=1000000000
SAVEHIST=1000000000
setopt INC_APPEND_HISTORY_TIME EXTENDED_HISTORY HIST_IGNORE_DUPS
#<==
{{/if}}
#==> Aliases
# ls
{{#if (is_executable "eza")}}
alias l="eza --time-style long-iso --color=auto -F"
alias ll="l -ahl"
{{else}}
alias l="ls --color=auto -F"
alias ll="l -Ahl"
{{/if}}
alias la="l -a"
# Clearing screen
alias c="echo -ne '\033c';"
alias cl="c l"
alias cll="c ll"
# Navigation
alias b="cd - >/dev/null && l" # b stands for back
# Interactive commands
alias mv="mv -i" # "m" - never forget
alias cp="cp -i"
# Move up quickly
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
# Package management
alias install='{{ install }}'
alias uninstall='{{ uninstall }}'
alias update='{{ update }}'
alias autoremove='{{ autoremove }}'
# Git
alias ga="git add"
alias gb="git branch"
alias gc="git commit"
alias gca="git commit --amend"
alias gcam="git commit -am"
alias gcm="git commit -m"
alias gd="git diff"
alias gds="git diff --staged"
alias glg="git log --all --oneline --graph --decorate"
alias gpl="git pull --prune"
alias gps="git push"
alias gm="git merge"
alias gs="git status -sb"
alias gsw="git switch"
# Misc
alias e="exit"
alias eb="exec {{#if dotter.packages.zsh}}zsh{{else}}bash{{/if}}"
alias vsp="vi -O"
alias pv="pv -pterb"
#<==
# Prompt git integration
GIT_PS1_SHOWDIRTYSTATE=1
GIT_PS1_SHOWSTASHSTATE=1
GIT_PS1_SHOWUNTRACKEDFILES=1
GIT_PS1_SHOWUPSTREAM=verbose
. ~/.git_prompt
{{#if dotter.packages.zsh}}
#==> ZSH Prompt
function displaytime {
local T=$1
local D=$((T/60/60/24))
local H=$((T/60/60%24))
local M=$((T/60%60))
local S=$((T%60))
(( $D > 0 )) && printf '%d days ' $D
(( $H > 0 )) && printf '%d hours ' $H
(( $M > 0 )) && printf '%d minutes ' $M
(( $D > 0 || $H > 0 || $M > 0 )) && printf 'and '
printf '%d seconds\n' $S
}
function preexec() {
timer=$(($(date +%s%0N)/1000000000))
}
PS1_EXIT_CODE="%F{0}%(?.%K{15}.%K{1}) %? "
PS1_USERNAME="%F{8}%K{ {{user_color}}} %n@%m "
PS1_PATH="%F{7}%K{8} %(5~@.../%3~@%~) "
PS1_PROMPT="%F{15}%B%(!.%K{1} # .%K{0} $ )%f%k%b "
PS1_PRE="$PS1_EXIT_CODE$PS1_USERNAME$PS1_PATH"
PS1_GIT="%%K{5} %s "
PS1_POST="$PS1_PROMPT"
function precmd() {
if [ $timer ]; then
now=$(($(date +%s%0N)/1000000000))
elapsed=$(($now-$timer))
elapsed_human=$(displaytime $elapsed)
if [ $elapsed -ge 1 ]; then
export RPROMPT="%F{cyan}${elapsed_human} %F"
else
export RPROMPT=""
fi
unset timer
fi
# Git Prompt
__git_ps1 "$PS1_PRE" "$PS1_POST" "$PS1_GIT"
}
#<==
{{else}}
#==> Bash Prompt
PS1_EXIT_CODE='\[\033[38;5;0m\]\[\033[48;5;15m\] $? '
PS1_USERNAME='\[\033[38;5;8m\]\[\033[48;5;7m\] \u@\h '
PS1_PATH='\[\033[38;5;7m\]\[\033[48;5;8m\] \w '
PS1_PRE="$PS1_EXIT_CODE$PS1_USERNAME$PS1_PATH"
PS1_GIT='\[\033[48;5;5m\] %s '
PS1_POST='\[$(tput bold)\]\[\033[48;5;0m\] \\$ \[$(tput sgr0)\]'
PROMPT_COMMAND="__git_ps1 '$PS1_PRE' '$PS1_POST' '$PS1_GIT'"
#<==
{{/if}}
#==> Misc
# Dircolors
eval `{{#if (is_executable "gdircolors")}}gdircolors{{else}}dircolors{{/if}} ~/.dir_colors`
# CD
{{#if (is_executable "zoxide")}}
eval "$(zoxide init {{#if dotter.packages.zsh}}zsh{{else}}bash{{/if}})"
{{/if}}
cd ()
{
# Pass all arguments to cd
{{#if (is_executable "zoxide")}}z{{else}}builtin cd{{/if}} "$@" || return $?
l
}
{{#if (is_executable "bat")}}
alias cat="bat"
{{/if}}
{{#if (is_executable "thefuck")}}
eval $(thefuck --alias)
{{/if}}
# Terminal color
TERM=xterm-256color
export PATH=$HOME/.scripts:$PATH
{{#if (is_executable "atuin")}}
export ATUIN_NOBIND="true"
eval "$(atuin init {{#if dotter.packages.zsh}}zsh{{else}}bash{{/if}})"
bindkey '^r' _atuin_search_widget
{{/if}}
#<==
# Local zshrc
[ -f ~/.zshrc.local ] && . ~/.zshrc.local
# vim:foldmethod=marker:foldmarker=\=\=>,<\=\=:foldtext=v\:folddashes.getline(v\:foldstart)[3\:]