dotfiles/.config/zsh/.zshrc
Arne Keller 74a932cc1a zshrc: misc. improvements
Prompt inside nix-shell: available packages
exa colors
files fzf widget
2022-02-07 09:03:36 +01:00

202 lines
6.1 KiB
Bash

###############
# shell setup #
###############
# uncomment to get profiling data with zprof
#zmodload zsh/zprof
autoload -Uz zmv
autoload -Uz add-zsh-hook
autoload -Uz compinit
autoload -U colors && colors
compinit -d "$XDG_CACHE_HOME/zcompdump"
zstyle ':completion:*' menu select
eval "$(zoxide init zsh)"
bindkey -e
bindkey "\e[1~" beginning-of-line
# ctrl+arrow keys
bindkey "^[[1;5D" backward-word
bindkey "^[[1;5C" forward-word
bindkey "\e[4~" end-of-line
bindkey "\e[3~" delete-char
# ctrl+backspace
bindkey '^H' backward-kill-word
# F9: duplicate last argument
bindkey -s "\e[20~" "!#\$^I"
paste-clipboard () {
LBUFFER+="$(xclip -sel clip -o)"
}
zle -N paste-clipboard
bindkey "\e[2~" paste-clipboard
#########################
# variables and aliases #
#########################
RPROMPT="%{$fg[green]%}%~%{$reset_color%}%"
PS1='%B%(?..[%?] )%b%n@%U%m%u> '
if (($+IN_NIX_SHELL)); then
PS1="($IN_NIX_SHELL) $PS1"
fi
check_nix_run() {
local path_copy
local -a bins
bins=()
path_copy="$PATH"
while [[ "$path_copy" =~ '\/nix\/store\/[^/]{33}([^/]+)\/[^:]+:?' ]]; do
bins+="$match[1]"
path_copy="${path_copy:$MEND}"
done
if [[ "${#bins[@]}" > 0 ]]; then
old_ps1="$PS1"
PS1="($bins[@]) $PS1"
in_nix_run=1
fi
}
check_nix_run
hide_nix_run() {
PS1="$old_ps1"
}
export LANG=de_DE.utf8
export LC_CTYPE=C.utf8
export EXA_COLORS='*.opus=38;5;248:*.ogg=38;5;248'
export TIME_STYLE=long-iso
export NPM_PACKAGES="${HOME}/.local/share/npm"
export PATH="$HOME/.local/bin:$PATH"
export EDITOR=vim
alias ski="sk --ansi -c 'rg --color=always --line-number \"{}\"'"
alias ls="exa"
alias ls-partitions="lsblk"
alias ls-network="sudo ss -lntup"
alias lh="ls -trhgGN --color=always | tr -s ' ' | cut -d' ' -f4-"
alias gitdots="git --git-dir=$HOME/.local/share/dotfiles --work-tree=$HOME"
alias heroku=/opt/heroku/bin/heroku
alias tectonic="tectonic -w https://ttassets.z13.web.core.windows.net/tlextras-2020.0r0.tar"
alias nix-build-env="nix-shell -I nixpkgs=/home/arne/nixpkgs -p binutils pkg-config gnumake cmake llvm llvmPackages.libclang llvmPackages.clang clang glibc libgit2 ocl-icd bzip2 libsass sqlite ncurses5 alsaLib xorg.libX11 manpages"
alias nix-shell="nix-shell -I nixpkgs=/home/arne/nixpkgs"
alias nix-zshell="nix-shell --run zsh"
alias add="git fuzzy status"
alias rga-pdf='rga --rga-adapters=poppler'
alias java-jacoco='java -javaagent:$HOME/.cache/m2/repository/org/jacoco/org.jacoco.agent/0.8.6/org.jacoco.agent-0.8.6-runtime.jar=port=36320,destfile=jacoco-it.exec,output=tcpserver'
export GIT_ASKPASS='/run/current-system/sw/bin/ksshaskpass'
export NIX_PATH='nixpkgs=/home/arne/nixpkgs:nixos-config=/etc/nixos/configuration.nix'
nix-run() {
ARGS=("$@")
nix run -I nixpkgs=/home/arne/nixpkgs ${ARGS[@]/#/nixpkgs.} -c zsh
}
#############
# utilities #
#############
#eval "$(navi widget zsh)"
#############
# XDG fixes #
#############
#export XDG_CONFIG_HOME="$HOME/.config"
#export XDG_DATA_HOME="$HOME/.local/share"
#export XDG_CACHE_HOME="$HOME/.cache"
export CARGO_HOME="$XDG_CACHE_HOME/cargo"
export RUSTUP_HOME="$HOME/.local/rustup"
export CARGO_TARGET_DIR="$CARGO_HOME/target"
export SQLITE_HISTORY="$XDG_DATA_HOME/sqlite_history"
export WINEPREFIX="$XDG_CACHE_HOME/wine"
export VIMINIT="set nocp | source ${XDG_CONFIG_HOME:-$HOME/.config}/vim/vimrc"
alias mvn="env HOME=$XDG_CACHE_HOME mvn --global-settings /home/arne/.config/maven/settings.xml -Dmaven.repo.local=$XDG_CACHE_HOME/m2/repository -Duser.home=$XDG_CACHE_HOME"
alias idle="HOME=/home/arne/.config idle3.9"
alias xscreensaver="HOME=$XDG_CONFIG_HOME xscreensaver"
alias xscreensaver-demo="HOME=$XDG_CONFIG_HOME xscreensaver-demo"
#################
# history setup #
#################
source $HOME/.local/bin/zsh-histdb/sqlite-history.zsh
histdb-fzf-widget() {
local selected num
setopt localoptions noglobsubst noposixbuiltins pipefail 2> /dev/null
selected=( $(histdb --sep 999 | awk -F'999' '{print $4}' | tac | awk '!seen[$0]++' | tac |
FZF_DEFAULT_OPTS="--tac --height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS --query=${(qqq)LBUFFER} +m" fzf) )
LBUFFER=$selected
zle redisplay
typeset -f zle-line-init >/dev/null && zle zle-line-init
return $ret
}
files-fzf-widget() {
local selected
setopt localoptions noglobsubst noposixbuiltins pipefail 2> /dev/null
[ -d .git ] && echo .git || git rev-parse --git-dir > /dev/null 2>&1
if [ ! $? -eq 0 ]; then
return
fi
selected=( $(git ls-files --exclude-standard | fzf --tac --preview 'bat --color=always --style=numbers --line-range=:50 {}') )
LBUFFER=$selected
zle redisplay
typeset -f zle-line-init >/dev/null && zle zle-line-init
return $ret
}
zle -N histdb-fzf-widget
zle -N files-fzf-widget
bindkey '^R' histdb-fzf-widget
bindkey '^T' files-fzf-widget
# disable default histfile
HISTFILE=
SAVEHIST=0
HISTSIZE=1000
unsetopt SHARE_HISTORY # don't share history between sessions
setopt HIST_IGNORE_SPACE
function mouse_around_rand {
while true; do
sleep "$1"
xdotool mousemove_relative -- $(($RANDOM % 10)) $(($RANDOM % 10))
xdotool mousemove_relative -- -$(($RANDOM % 10)) -$(($RANDOM % 10))
done
}
function git_github()
{
git config user.name FliegendeWurst
git config user.email '2012gdwu+github@posteo.de'
git config core.sshCommand "env SSH_ASKPASS=/run/current-system/sw/bin/ksshaskpass ssh -i ~/.ssh/github_id_ed25519 -F /dev/null"
}
function git_github_ak()
{
git config user.name arnek01
git config user.email 2012gdwu@posteo.de
git config commit.gpgsign false
}
function git_ak()
{
git config --replace user.name Arne\ Keller
git config --replace user.email arne.keller@posteo.de
git config commit.gpgsign false
}
function git_gitlab_ak()
{
git config --replace user.name Arne\ Keller
git config user.email arne.keller@posteo.de
git config commit.gpgsign false
git config core.sshCommand "env SSH_ASKPASS=/run/current-system/sw/bin/ksshaskpass ssh -i ~/.ssh/gitlab_ak -F /dev/null"
}
function git_kit()
{
git config --replace user.name Arne\ Keller
git config --replace user.email arne.keller@student.kit.edu
git config core.sshCommand "env SSH_ASKPASS=/run/current-system/sw/bin/ksshaskpass ssh -i ~/.ssh/id_newkey2021 -F /dev/null"
}