Archived
1
0
Fork 0
This repository has been archived on 2024-06-19. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/zshrc
Christoph Heiss bcc38f8d8b
zsh: Only automatically start sway if it is installed
Signed-off-by: Christoph Heiss <christoph@c8h4.io>
2023-03-01 16:51:44 +01:00

231 lines
5.4 KiB
Bash

#
# ~/.zshrc
#
# If not running interactively, do nothing
[[ $- != *i* ]] && return
export PATH="$HOME/.local/share/flatpak/exports/bin:$HOME/.local/bin:$PATH"
# If running on the first TTY and sway is installed, start sway
[[ $(tty) = /dev/tty1 ]] && type sway &>/dev/null && exec $HOME/.config/sway/run.sh
export ZSH=$HOME/.oh-my-zsh
ZSH_THEME=spaceship
HYPHEN_INSENSITIVE=true
ENABLE_CORRECTION=true
# Display red dots whilst waiting for completion
COMPLETION_WAITING_DOTS=true
# Timestamps for history
HIST_STAMPS=yyyy-mm-dd
plugins=(
colored-man-pages
copybuffer
docker
docker-compose
git
git-extras
helm
kubectl
ripgrep
rust
safe-paste
sudo
z
# must be last
zsh-syntax-highlighting
)
source $ZSH/oh-my-zsh.sh
# Show low battery warning < 20% left
SPACESHIP_BATTERY_THRESHOLD=20
# Show execution time of last command if > 10 sec
SPACESHIP_EXEC_TIME_ELAPSED=10
SPACESHIP_EXIT_CODE_SYMBOL="✘ "
SPACESHIP_EXIT_CODE_SHOW=true
SPACESHIP_TIME_SHOW=true
SPACESHIP_HOST_SHOW_FULL=true
SPACESHIP_USER_SHOW=needed
export HISTCONTROL=ignoreboth
export HISTSIZE=10000
export HISTFILESIZE=$HISTSIZE
export MANPATH="/usr/local/man:$MANPATH"
export LC_ALL=$LANG
export EDITOR=nvim
export PKG_CONFIG_PATH="$HOME/.local/lib/pkgconfig:$HOME/.local/share/pkgconfig:/usr/local/lib/pkgconfig"
export GPG_TTY=$(tty)
export VAGRANT_DEFAULT_PROVIDER=libvirt
# Setup nvm
export NVM_DIR=$HOME/.nvm
[ -s $NVM_DIR/nvm.sh ] && source $NVM_DIR/nvm.sh
if [ -s $HOME/.zshrc_secret ]; then
[ $(stat -c '%a' $HOME/.zshrc_secret) != 600 ] && \
printf "\e[91m~/.zshrc_secret is readable by other users, fix permissions!\e[0m\n"
source $HOME/.zshrc_secret
fi
# Do not freeze terminal on Ctrl-S
stty -ixon
# Do not share history
unsetopt share_history
# Disable annoying correction prompt
unsetopt correct_all
# Additional keybinds
bindkey '^H' backward-kill-word
# Git
export GIT_EDITOR=$EDITOR
alias gc='git commit --verbose --signoff'
alias gcan!='git commit --verbose --signoff --amend --date now --reset-author'
alias gfp='git format-patch'
alias gsm='git send-email'
alias gsmc='git send-email --compose'
# Golang
export GOPATH=$HOME/.go
export PATH="$GOPATH/bin:$PATH"
# Makefile
alias m='make'
# neovim
alias n='nvim'
# ripgrep
alias rg='rg --no-heading'
# Rust
export PATH="$HOME/.cargo/bin:$PATH"
alias cb='cargo build'
alias cnb='cargo +nightly build'
alias cr='cargo run'
alias cnr='cargo +nightly run'
alias ccl='cargo clippy'
# PostgreSQL
alias lpsql='psql -U postgres -h localhost'
# Misc
alias diff='diff -u -p -r -N --color=auto'
alias ip='ip --color'
alias journalctl-clean='journalctl --vacuum-time=7d'
alias nocorrect=''
alias open=xdg-open
alias sudo='sudo '
alias usystemctl='systemctl --user'
alias valgrind-full-check='valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --num-callers=256'
alias weather='curl wttr.in'
alias yt-dlp-mp3="yt-dlp -o '%(title)s.%(ext)s' -i -x --audio-quality 320K --audio-format mp3"
alias yt-dlp-video="yt-dlp -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio' --merge-output-format mp4"
git-check-merge() {
local output="$(git merge $1 --no-ff --no-commit 2>&1)"
if [[ "$output" == *"merge failed"* ]]; then
echo "$output" | grep CONFLICT 2>/dev/null
echo "Automatic merge failed" 2>/dev/null
else
echo "Automatic merge went well"
fi
git merge --abort # Return to previous state
}
gen-rsa-keypair() {
openssl genpkey -algorithm RSA -out "$1" -pkeyopt rsa_keygen_bits:4096
openssl rsa -pubout -in "$1" -out "$1.pub"
}
allow-any-ptrace() {
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope >/dev/null
}
deny-any-ptrace() {
echo 1 | sudo tee /proc/sys/kernel/yama/ptrace_scope >/dev/null
}
curl-time() {
curl -w @- -o /dev/null -s "$@" <<'EOF'
time_namelookup: %{time_namelookup}\n
time_connect: %{time_connect}\n
time_appconnect: %{time_appconnect}\n
time_pretransfer: %{time_pretransfer}\n
time_redirect: %{time_redirect}\n
time_starttransfer: %{time_starttransfer}\n
----------\n
time_total: %{time_total}\n
EOF
}
__update_log() {
printf "\n 📦 \e[92mUpdating $1\e[0m\n"
}
__update_system_packages() {
if [ -f /etc/arch-release ]; then
yay -Syu --sudoloop --noconfirm --nodiffmenu --noeditmenu --noupgrademenu
yay -Yc --noconfirm # Clean unneeeded dependencies
yes y | yay -Scc
elif [ -f /etc/fedora-release ]; then
sudo dnf upgrade --assumeyes
sudo dnf clean packages
elif [ -f /etc/debian_version ]; then
sudo apt update
sudo apt full-upgrade --assume-yes
fi
}
__update_git_repo() {
pushd "$1"
git pull
popd
}
update() {
setopt pushdsilent
__update_log 'system packages'
__update_system_packages
if hash flatpak 2> /dev/null; then
__update_log 'flatpak apps'
flatpak update -y
flatpak remove -y --unused
fi
if hash yarn 2> /dev/null; then
__update_log 'global node packages'
yarn global upgrade
fi
if hash rustup 2> /dev/null; then
__update_log rust
rustup update
fi
__update_log 'oh-my-zsh'
omz update --unattended
__update_log 'oh-my-zsh extra stuff'
__update_git_repo "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting"
__update_git_repo "$ZSH_CUSTOM/themes/spaceship-prompt"
unsetopt pushdsilent
}