Files
dotfiles/zsh/zshrc.j2

462 lines
11 KiB
Plaintext
Raw Normal View History

{% if user.gpg_agent %}
2017-08-05 18:59:49 +02:00
export GPG_TTY=$(tty)
2019-04-16 20:10:47 +02:00
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
2018-08-17 19:44:31 +02:00
{% endif %}
2017-08-05 18:59:49 +02:00
2022-07-05 22:27:10 +02:00
{% if user.ssh_agent %}
if ! pgrep -u "$USER" ssh-agent > /dev/null ; then
ssh-agent > "$XDG_RUNTIME_DIR/ssh-agent.env"
fi
if [[ ! "$SSH_AUTH_SOCK" ]]; then
source "$XDG_RUNTIME_DIR/ssh-agent.env" >/dev/null
fi
{% endif %}
2024-04-14 01:00:01 +02:00
{% raw %}
setopt EXTENDED_HISTORY
setopt HIST_EXPIRE_DUPS_FIRST
setopt HIST_VERIFY
setopt INC_APPEND_HISTORY
setopt SHARE_HISTORY
setopt AUTO_CD
setopt APPEND_HISTORY
setopt HIST_IGNORE_DUPS
setopt NOHIST_IGNORE_ALL_DUPS
setopt HIST_IGNORE_SPACE
setopt CORRECT
setopt RM_STAR_SILENT
setopt BG_NICE
setopt CHECK_JOBS
setopt HUP
setopt LONG_LIST_JOBS
setopt share_history
bindkey -e
autoload -U promptinit
promptinit
autoload -U colors
colors
autoload -U compinit
compinit
zstyle ':completion:*' menu select
setopt completealiases
autoload -U edit-command-line
zle -N edit-command-line
bindkey '^xe' edit-command-line
bindkey '^x^e' edit-command-line
HISTSIZE=100000
SAVEHIST=100000
2024-05-05 10:44:47 +02:00
HISTFILE="$XDG_STATE_HOME/zsh_history"
2024-04-14 01:00:01 +02:00
2024-05-05 11:15:23 +02:00
# Completion files: Use XDG dirs
[ -d "$XDG_CACHE_HOME"/zsh ] || mkdir -p "$XDG_CACHE_HOME"/zsh
zstyle ':completion:*' cache-path "$XDG_CACHE_HOME"/zsh/zcompcache
compinit -d "$XDG_CACHE_HOME"/zsh/zcompdump-$ZSH_VERSION
2024-04-14 01:00:01 +02:00
alias vim="nvim"
### BETTER COMMANDS
alias ls="exa --oneline --icons --group-directories-first"
alias ll='ls --all --long --classify --group --modified --time-style=long-iso --git'
alias la='ls --all'
alias spm="sudo pacman"
alias tml="tmux list-sessions"
alias tma="tmux ls 2>/dev/null && tmux attach-session || tmux"
alias tmn="tmux new-session -A -s"
alias clipc="xclip -selection primary"
alias clipo="xclip -out -selection clipboard"
alias rgrep="grep -r"
alias calc='python3 -ic "from math import *; import cmath"'
alias le_haxxor_1='clear && dmesg | pv -qL 20'
alias le_haxxor_2='clear && hexdump -C /dev/urandom | pv -qlL 2'
alias root='sudo -sE'
### USEFUL DEFAULT OPTIONS
alias tmux="tmux -2"
alias chmod="chmod -c"
alias chown="chown -c"
alias diff="diff --color=auto"
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
2024-04-16 11:56:05 +02:00
alias rg='rg --hidden --glob "!.git/**" --glob "!.git"'
2024-04-14 01:00:01 +02:00
alias rm='rm -v'
alias cp='cp -vi'
alias mv='mv -vi'
alias ln='ln -v'
alias du='du -h'
alias df='df -h'
### SHORTENING COMMAND NAMES
alias cs="cryptsetup"
alias v="vim"
alias g="git"
alias c="cd"
alias l="ls"
alias s="sudo"
alias cl="clear"
alias nocolor="sed -r \"s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g\""
alias ip="ip -color"
alias vimtask="vim -c :TW"
alias tw="task"
alias twl="task list"
alias twa="task add"
alias twd="task done"
alias inbox="task add +inbox"
alias json2yaml="python3 -c 'import sys, yaml, json; yaml.safe_dump(json.loads(sys.stdin.read()), stream=sys.stdout)'"
alias currentbranch='git rev-parse --abbrev-ref HEAD'
alias issh="ssh -o StrictHostKeyChecking=false -o UserKnownHostsFile=/dev/null"
alias gfix='git commit --amend --no-edit'
alias gfixa='git commit --amend --no-edit --all '
alias gfixp='git commit --amend --no-edit --patch'
alias issh="ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"
alias newpw="pwgen --secure 25 1"
alias sys="systemctl"
alias sysu="systemctl --user"
alias gpg=gpg2
alias alacritty="alacritty --config-file ${XDG_CONFIG_HOME}/alacritty/config.toml"
2024-04-14 01:00:01 +02:00
alias d=docker
alias dc=docker-compose
alias hx=helix
alias h=helix
alias wget="wget --hsts-file ${XDG_STATE_HOME}/wget-hsts"
2024-04-14 01:00:01 +02:00
gitmaster() {
git stash push -m gitmaster-$(date -uIseconds) -u || return 1
_branch=$(git rev-parse --abbrev-ref HEAD)
git fe || return 1
git checkout master || return 1
git merge origin/master || return 1
git checkout $_branch
git stash pop
}
cd() {
builtin cd "$@" && ls
}
mount() {
if [[ $# == 0 ]] ; then
command mount | column -t
else
command mount "$@"
fi
}
extr()
{
if [[ -f "$1" ]] ; then
case "$1" in
*.tar.bz2 ) tar xvjf "$1" ;;
*.tar.gz ) tar xvzf "$1" ;;
*.tar.xz ) tar xvJf "$1" ;;
*.bz2 ) bunzip2 "$1" ;;
*.rar ) unrar x "$1" ;;
*.gz ) gunzip "$1" ;;
*.tar ) tar xvf "$1" ;;
*.tbz2 ) tar xvjf "$1" ;;
*.tgz ) tar xvzf "$1" ;;
*.zip ) unzip "$1" ;;
*.Z ) uncompress "$1" ;;
*.7z ) 7z x "$1" ;;
*)
echo "$1 cannot be extracted via $0"
;;
esac
else
echo "$1 is not a valid file"
fi
}
ruler() {
for s in '....^....|' '1234567890'; do
w=${#s}
str=$(for (( i=1; $i<=$(( ($COLUMNS + $w) / $w )) ; i=$i+1 )); do echo -n $s; done )
str=$(echo $str | cut -c -$COLUMNS)
echo $str
done
}
addext() {
[[ -z "$1" ]] || [[ -z "$2" ]] && { echo "Usage: $0 <file> <extension>" ; return }
mv "$1" "$1$2"
}
rmext() {
[[ -e "$1" ]] && mv -i "$1" "${1%.*}"
}
ckwww() {
ping -c 3 www.google.com
}
httpcode() {
curl http://httpcode.info/$1
}
bak() {
if ! [[ "$1" ]] ; then
printf '%s\n' "usage: $0 FILE"
return 1
fi
if ! [[ -e "$1" ]] ; then
printf '%s\n' "\"$1\" not found"
return 1
fi
name="$1.$(date +%Y%m%d%H%M%S.bak)"
if [[ -e "${name}" ]] ; then
printf '%s\n' "Backup file \"$name\" already exists"
return 1
fi
cp --archive --verbose --no-clobber "$1" "${name}"
}
fstab() {
# yeah
expand /etc/fstab | grep -v '^#' | grep -P '^.+$' | tr -s ' ' | tr ' ' '|' | cat <(grep -P '<.+>' /etc/fstab | cut -f 2- -d ' ' | sed 's/>[^<]*</>|</g') - | column -ts '|'
}
serve() {
python3 -m http.server 8800
}
manpdf() {
[[ -z "$1" ]] && { printf '%s' >&2 "$(man)" ; return ; }
man -t "$1" | ps2pdf - - | zathura -
}
myip4() {
curl "http://ipv4.icanhazip.com"
}
myip6() {
curl "http://ipv6.icanhazip.com" 2>/dev/null || echo "no ip6"
}
diffdir() {
[[ "$1" ]] && [[ "$2" ]] || { echo "$0 <dir1> <dir2>" ; return 1 ; }
diff <(cd "$1" && find -type f -exec md5sum {} \;) <(cd "$2" && find -type f -exec md5sum {} \;)
}
diffdir2() {
[[ "$1" ]] && [[ "$2" ]] || { echo "$0 <dir1> <dir2>" ; return 1 ; }
comm -13 <(cd "$1" && find -type f | sort -g) <(cd "$2" && find -type f | sort -g)
}
man() {
env LESS_TERMCAP_mb=$'\E[01;31m' \
LESS_TERMCAP_md=$'\E[01;38;5;74m' \
LESS_TERMCAP_me=$'\E[0m' \
LESS_TERMCAP_se=$'\E[0m' \
LESS_TERMCAP_so=$'\E[38;5;246m' \
LESS_TERMCAP_ue=$'\E[0m' \
LESS_TERMCAP_us=$'\E[04;38;5;146m' \
man "$@"
}
resolvecd() {
cd "$(readlink -f $(pwd))"
}
ssht () {
ssh -t $@ "tmux a || tmux";
}
t() {
if [[ "$1" ]] ; then
tmux new-session -A -s "$1"
else
tmux attach-session
fi
}
sb() {
echo $(( $1 * $(cat /sys/class/backlight/intel_backlight/max_brightness) / 100)) | sudo tee /sys/class/backlight/intel_backlight/brightness
}
clip() {
tee >(xclip -selection clipboard) | tee >(xclip -selection primary)
}
gb() {
_superproject="$(git rev-parse --show-superproject-working-tree)"
_root="$(git rev-parse --show-toplevel)"
if [[ -n "${_superproject}" ]] ; then
if [[ "$(pwd)" == "${_root}" ]] ; then
builtin cd "${_superproject}"
else
builtin cd "${_root}"
fi
else
builtin cd "${_root}"
fi
}
bm() {
case "$1" in
dev)
cd "$HOME/development/projects"
;;
dot)
cd "$HOME/dotfiles"
;;
*)
echo "unknown target"
;;
esac
}
embiggen() {
enscript --no-header --media=A4 --landscape --font="DejaVuSansMono30" -o - 2>/dev/null | ps2pdf - | zathura -
}
journal() {
journaldir=~/sync/journal/
file="$journaldir/$(date +%Y-%m-%d).md"
if [[ ! -e $file ]] ; then
cp $journaldir/template.md $file || return
fi
$EDITOR $file
}
prefix() {
prefix=$2
file=$1
mv $file ${prefix}${file}
}
tmp() {
cd "$(mktemp -d)"
}
+vi-git-untracked() {
if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]] && \
[[ $(git ls-files --other --directory --exclude-standard | sed q | wc -l | tr -d ' ') == 1 ]] ; then
2024-05-03 16:21:35 +02:00
hook_com[unstaged]+='+U'
2024-04-14 01:00:01 +02:00
fi
}
2024-05-03 16:21:35 +02:00
+vi-git-remotebranch() {
local remote
2024-04-14 01:00:01 +02:00
local ahead behind
local -a gitstatus
ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
(( $ahead )) && gitstatus+=( "+${ahead}" )
behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l)
(( $behind )) && gitstatus+=( "-${behind}" )
remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} \
--symbolic-full-name 2>/dev/null)/refs\/remotes\/}
if [[ -n ${remote} ]] ; then
2024-05-05 10:31:26 +02:00
hook_com[branch]="%F{cyan}${hook_com[branch]}%F{$mainc}:%b%F{magenta}${remote}%F{yellow}${(j:/:)gitstatus}%F{$mainc}"
2024-04-14 01:00:01 +02:00
fi
}
2024-05-03 16:21:35 +02:00
setopt PROMPT_SUBST
2024-04-14 01:00:01 +02:00
autoload -Uz vcs_info
2024-05-03 16:21:35 +02:00
zstyle ':vcs_info:*' stagedstr 'I'
zstyle ':vcs_info:*' unstagedstr 'M'
zstyle ':vcs_info:*' enable git
2024-04-14 01:00:01 +02:00
zstyle ':vcs_info:*' check-for-changes true
2024-05-03 16:21:35 +02:00
zstyle ':vcs_info:*' get-revision true
2024-04-14 01:00:01 +02:00
2024-05-03 16:21:35 +02:00
zstyle ':vcs_info:*' formats "[%b] [%c%u]"
zstyle ':vcs_info:*' actionformats '%a '
2024-04-14 01:00:01 +02:00
2024-05-03 16:21:35 +02:00
zstyle ':vcs_info:git*+set-message:*' hooks git-untracked git-remotebranch
2024-04-14 01:00:01 +02:00
2024-05-03 16:21:35 +02:00
precmd() {
vcs_info
}
2024-04-14 01:00:01 +02:00
2024-05-05 10:31:26 +02:00
if [[ -e "$XDG_RUNTIME_DIR/darkmode" ]] ; then
mainc=white
2024-05-03 16:21:35 +02:00
else
2024-05-05 10:31:26 +02:00
mainc=black
2024-05-03 16:21:35 +02:00
fi
2024-04-14 01:00:01 +02:00
2024-05-05 15:30:09 +02:00
_topstr='%F{green}%n%F{$mainc} ─ %B%F{yellow}%5~%b ${vcs_info_msg_0_}%F{$mainc} '
2024-05-03 16:21:35 +02:00
botstr='%B${PINFO}%(!.#.$)%b '
2024-04-14 01:00:01 +02:00
2024-05-05 10:31:26 +02:00
PROMPT='%F{$mainc}┌─ '"${_topstr}"'
2024-04-14 01:00:01 +02:00
└─ '"${botstr}"
2024-05-05 10:31:26 +02:00
RPROMPT='%b%F{cyan}%*%F{$mainc} [%?]'
2024-04-14 01:00:01 +02:00
autoload zkbd
bindkey "\e[1~" beginning-of-line
bindkey "\e[4~" end-of-line
bindkey "\e[5~" beginning-of-history
bindkey "\e[6~" end-of-history
bindkey "\e[3~" delete-char
bindkey "\e[2~" quoted-insert
bindkey "\e[5C" forward-word
bindkey "\eOc" emacs-forward-word
bindkey "\e[5D" backward-word
bindkey "\eOd" emacs-backward-word
bindkey "\ee[C" forward-word
bindkey "\ee[D" backward-word
bindkey "^H" backward-delete-word
# for rxvt
bindkey "\e[8~" end-of-line
bindkey "\e[7~" beginning-of-line
# for non RH/Debian xterm, can't hurt for RH/DEbian xterm
bindkey "\eOH" beginning-of-line
bindkey "\eOF" end-of-line
# for freebsd console
bindkey "\e[H" beginning-of-line
bindkey "\e[F" end-of-line
# completion in the middle of a line
bindkey '^i' expand-or-complete-prefix
export FZF_DEFAULT_OPTS='--height 50% --border'
eval "$(fzf --zsh)"
2024-05-05 10:31:26 +02:00
# These have to be sourced at the end, see
# https://github.com/zsh-users/zsh-syntax-highlighting?tab=readme-ov-file#why-must-zsh-syntax-highlightingzsh-be-sourced-at-the-end-of-the-zshrc-file
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
2024-04-14 01:00:01 +02:00
{% endraw %}