summaryrefslogtreecommitdiff
path: root/config/essentials/zsh/.zshrc
blob: 96ec100ed7b0e4493cfcb9fd48b1c8daf2848074 (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
#!/bin/zsh

if [[ "/dev/tty1" = "$TTY" || "/dev/tty2" = "$TTY" ]] && [[ "$(id -u)" -ne 0 ]]
then
	clear
	eval "$(keychain --dir "$XDG_CONFIG_HOME/keychain" --eval --quiet --agents gpg 3A626DD20A32EB2E5DD9CE71CFD9ABC97158CD5D 2> /dev/null)"
	eval "$(keychain --dir "$XDG_CONFIG_HOME/keychain" --noask --eval --quiet --agents ssh 2> /dev/null)"
	clear
	if [ "/dev/tty1" = "$TTY" ]
	then
		Hyprland > /dev/null 2>&1
	else
		startx > /dev/null 2>&1
	fi
	exit
fi

autoload -U select-word-style
autoload -z edit-command-line
zle -N edit-command-line
zstyle ':compinstall' filename '/home/aluc/.zshrc'
zstyle ':completion:*' menu select
autoload -Uz compinit
compinit -d $XDG_CACHE_HOME/zsh/zcompdump-$ZSH_VERSION
autoload -Uz surround
zle -N delete-surround surround
zle -N add-surround surround
zle -N change-surround surround
compinit

if grep -qi "debian\|ubuntu" /etc/os-release 2>/dev/null
then
    sfiles=(
        /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh
        /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
    )
else
    sfiles=(
        /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
        /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh)
fi
sfiles+=(
		~/.config/zsh/functions.zsh
		~/.config/zsh/aliases.zsh
)
for f in "${sfiles[@]}"; do
    test -f "$f" && source "$f"
done

bindkey -v
bindkey -a cs change-surround
bindkey -a ds delete-surround
bindkey -a ys add-surround
bindkey -M visual S add-surround
bindkey "^A"  beginning-of-line
bindkey "^E"  end-of-line
bindkey '^I' expand-or-complete-prefix # necessary for completeinword
bindkey '^Y' autosuggest-accept
bindkey "^K"  kill-line
bindkey "^P"  up-line-or-history
bindkey "^N"  down-line-or-history
bindkey "^V"  quoted-insert
bindkey "^Xa" _expand_alias
bindkey "^Xe" edit-command-line
bindkey "^[." insert-last-word
bindkey "^['" quote-line

# rehash hook
zshcache_time="$(date +%s%N)"
autoload -Uz add-zsh-hook
rehash_precmd() {
  if [[ -a /var/cache/zsh/pacman ]]; then
    local paccache_time="$(date -r /var/cache/zsh/pacman +%s%N)"
    if (( zshcache_time < paccache_time )); then
      rehash
      zshcache_time="$paccache_time"
    fi
  fi
}
# window title hooks
add-zsh-hook -Uz precmd rehash_precmd
set_wt_action () {
	print -Pn "\e]0;$1\a"
}
add-zsh-hook -Uz preexec set_wt_action
set_wt () {
	print -Pn "\e]0;%n@%m on %~\a"
}
add-zsh-hook -Uz precmd set_wt


# prompt
PS1=' %B%(#.%F{1}.%F{13})[%n%b%f@%B%F{6}%m]%b%f %3~ '
RPROMPT='%F{blue}$(parse_git_remote)%f%F{red}$(parse_git_status)%f%F{green}$(parse_git_branch)%f%(?.. %?)'

setopt prompt_subst
parse_git_remote() {
	b="$(git branch -v 2> /dev/null | grep "^*" | sed 's/.\+\[\([^ ]\+\).*$/\1/')"
	if [ "$b" = "behind" ]
	then
		echo -n "↓ "
	elif [ "$b" = "ahead" ]
	then
		echo -n "↑ "
	fi
}
parse_git_branch() {
    git symbolic-ref --short HEAD 2> /dev/null || git rev-parse --short HEAD 2> /dev/null
}
parse_git_status() {
	git status --short 2> /dev/null | head -n1 | awk '{print $1 " "}'
}

export REPORTTIME=2
export TIMEFMT="-> %*E"
# override built-in time command
alias time='/usr/bin/time'
export MENUCMD='fzf'

# Options
setopt correct 
setopt nonomatch 
setopt autocd
setopt completeinword
setopt extendedglob
setopt histignorealldups
setopt histreduceblanks
setopt interactivecomments
setopt notify
setopt cdablevars