merge: zsh cleanup

This commit is contained in:
2026-03-09 13:51:54 +01:00
10 changed files with 130 additions and 243 deletions

3
.gitignore vendored
View File

@@ -16,12 +16,9 @@ zsh/*
!zsh/.zshrc !zsh/.zshrc
!zsh/.zshenv !zsh/.zshenv
!zsh/.zprofile !zsh/.zprofile
!zsh/.zsh_plugins*.txt
!zsh/scripts.zsh !zsh/scripts.zsh
!zsh/aliases.zsh !zsh/aliases.zsh
!zsh/completions/.keep
!zsh/ssh-menu !zsh/ssh-menu
!zsh/get-dump
# starship # starship
!starship !starship

View File

@@ -1,2 +1,5 @@
export PATH="/usr/local/bin:/opt/homebrew/bin:$HOME/neovim/bin:$HOME/bin:${PATH}" path=(
"$HOME/.local/bin"
"$GOPATH/bin"
$path
)

View File

@@ -1,11 +0,0 @@
# set up Zsh completions with plugins
# mattmc3/ez-compinit
zsh-users/zsh-completions kind:fpath path:src
# frameworks like oh-my-zsh are supported
getantidote/use-omz # handle OMZ dependencies
ohmyzsh/ohmyzsh path:lib # load OMZ's library
ohmyzsh/ohmyzsh path:plugins/git
# popular fish-like plugins
zsh-users/zsh-autosuggestions

View File

@@ -1 +0,0 @@
lukechilds/zsh-nvm

View File

@@ -4,22 +4,8 @@ export XDG_CACHE_HOME="$HOME/.cache"
export XDG_DATA_HOME="$HOME/.local/share" export XDG_DATA_HOME="$HOME/.local/share"
export XDG_STATE_HOME="$HOME/.local/state" export XDG_STATE_HOME="$HOME/.local/state"
# ~/.local/bin # deduplicate path
export PATH="$HOME/.local/bin:$PATH" typeset -U path
# brew sbin
export PATH="/opt/homebrew/sbin:$PATH"
# brew lib
export LIBRARY_PATH="$LIBRARY_PATH:/opt/homebrew/lib"
# cargo
if [[ "$OSTYPE" == "darwin"* ]]; then
source "$HOME/.cargo/env"
fi
# language environment
export LANG=en_US.UTF-8
# editor # editor
export EDITOR=nvim export EDITOR=nvim
@@ -27,35 +13,12 @@ export EDITOR=nvim
# go # go
export GOPATH="$XDG_DATA_HOME/go" export GOPATH="$XDG_DATA_HOME/go"
export GOMODCACHE="$XDG_CACHE_HOME/go/mod" export GOMODCACHE="$XDG_CACHE_HOME/go/mod"
export PATH="$GOPATH/bin:$PATH"
# ggman # ggman
export GGROOT="$HOME/git" export GGROOT="$HOME/git"
# neovim
export PATH="$XDG_DATA_HOME/neovim/bin:$PATH"
# pyenv
export PYENV_ROOT="$XDG_DATA_HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
# pyenv-virtualenv
# leave python promt to starship
export PYENV_VIRTUALENV_DISABLE_PROMPT=1
# poetry
export POETRY_HOME="$XDG_DATA_HOME/poetry"
command -v poetry >/dev/null || export PATH="$POETRY_HOME/bin:$PATH"
# gnupg
export GPG_TTY=$(tty)
# aflabs
export USER_UID=$(id -u)
export USER_GID=$(id -g)
# name # name
export NAME="Matej Janežič" export NAME="Matej Janežič"
# starship nest config into a folder, default is ~/.config/startship.toml # starship nest config into a folder, default is ~/.config/starship.toml
export STARSHIP_CONFIG="$XDG_CONFIG_HOME/starship/config.toml" export STARSHIP_CONFIG="$XDG_CONFIG_HOME/starship/config.toml"

View File

@@ -1,46 +1,69 @@
# zsh history file # shell options
export HISTFILE="$XDG_STATE_HOME/zsh/history" unsetopt autocd # don't cd into directories by name
export HISTSIZE=100 setopt NO_BEEP # no terminal bell
setopt AUTO_PUSHD # cd pushes to directory stack
setopt PUSHD_IGNORE_DUPS # no duplicates in directory stack
setopt EXTENDED_GLOB # enable extended glob operators (#, ~, ^)
## pre plugin load # history
# nvm HISTFILE="$XDG_STATE_HOME/zsh/history"
export NVM_COMPLETION=true HISTSIZE=10000
# zsh autosugestions SAVEHIST=10000
export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ffffff,bg=cyan,bold,underline" setopt HIST_IGNORE_DUPS # skip consecutive duplicates
setopt HIST_IGNORE_SPACE # skip commands starting with space
setopt SHARE_HISTORY # share history across sessions
setopt HIST_REDUCE_BLANKS # strip extra whitespace
# source antidote # plugins
source $ZDOTDIR/.antidote/antidote.zsh local _plugins="$XDG_DATA_HOME/zsh/plugins"
antidote load local _stamp="$XDG_CACHE_HOME/zsh/plugins-updated"
local _repos=(
"https://github.com/zsh-users/zsh-completions"
"https://github.com/zsh-users/zsh-autosuggestions"
)
local _needs_update=0
if [[ "$OSTYPE" == "darwin"* ]]; then if [[ ! -f "$_stamp" ]] || [[ -n $_stamp(#qN.mh+168) ]]; then
antidote load ${ZDOTDIR:-~}/.zsh_plugins_darwin.txt mkdir -p "${_stamp:h}"
touch "$_stamp"
_needs_update=1
fi fi
unsetopt autocd for _repo in $_repos; do
if [[ ! -d "$_plugins/${_repo:t}" ]]; then
git clone "$_repo" "$_plugins/${_repo:t}"
elif (( _needs_update )); then
git -C "$_plugins/${_repo:t}" pull --quiet &
fi
done
(( _needs_update )) && wait
if [[ "$OSTYPE" == "darwin"* ]]; then fpath=("$_plugins/zsh-completions/src" $fpath)
eval "$(pyenv init - zsh)" ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ffffff,bg=cyan,bold,underline"
eval "$(pyenv virtualenv-init - zsh)" source "$_plugins/zsh-autosuggestions/zsh-autosuggestions.zsh"
fi
if [[ "$OSTYPE" == "darwin"* ]]; then # aliases and functions
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
fi
# ggman
eval "$(ggman shellrc)"
# custom functions and aliases
source "$ZDOTDIR/aliases.zsh" source "$ZDOTDIR/aliases.zsh"
source "$ZDOTDIR/scripts.zsh" source "$ZDOTDIR/scripts.zsh"
# completion # completion
fpath=($ZDOTDIR/completions $fpath) fpath=("$XDG_DATA_HOME/zsh/completions" $fpath)
autoload -Uz compinit autoload -Uz compinit
compinit -d $XDG_CACHE_HOME/zsh/zcompdump-$ZSH_VERSION # only regenerate dump once per day
zstyle ':completion:*' cache-path $XDG_CACHE_HOME/zsh/zcompcache local _zcompdump="$XDG_CACHE_HOME/zsh/zcompdump-$ZSH_VERSION"
if [[ -n $_zcompdump(#qN.mh+24) ]]; then
# opam configuration compinit -d "$_zcompdump"
# [[ ! -r /Users/janezicmatej/.opam/opam-init/init.zsh ]] || source /Users/janezicmatej/.opam/opam-init/init.zsh > /dev/null 2> /dev/null else
compinit -C -d "$_zcompdump"
fi
zstyle ':completion:*' cache-path "$XDG_CACHE_HOME/zsh/zcompcache"
zstyle ':completion:*' menu select
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
# tool hooks
eval "$(ggman shellrc)"
eval "$(starship init zsh)" eval "$(starship init zsh)"
eval "$(direnv hook zsh)"
# gnupg
export GPG_TTY=$(tty)

View File

@@ -1,12 +1,7 @@
alias z="exec zsh" alias z="exec zsh"
alias t=tmux_attach alias t=tmux_attach
if [[ "$OSTYPE" == "darwin"* ]]; then alias n=nvim
alias n=nvim_ve
alias vim=nvim_ve
elif [[ "$OSTYPE" == "linux"* ]]; then
alias n=nvim
fi
alias s="ssh-menu" alias s="ssh-menu"
@@ -15,28 +10,59 @@ alias dp="docker ps --format 'table {{.Names}}\t{{.Ports}}'"
alias dcp="docker compose ps --format 'table {{.Name}}\t{{.Ports}}'" alias dcp="docker compose ps --format 'table {{.Name}}\t{{.Ports}}'"
# navigation # navigation
alias cdgit="cd $GGROOT" alias cdgit='cd $GGROOT'
alias icloud="cd $HOME/Library/Mobile\ Documents/com\~apple\~CloudDocs"
alias temp="cd $HOME/Desktop/temp"
# apple specific # git status/diff
alias accenton="defaults write -g ApplePressAndHoldEnabled -bool true" alias gst="git status"
alias accentoff="defaults write -g ApplePressAndHoldEnabled -bool false" alias gd="git diff"
alias gds="git diff --staged"
# git alias gdup="git diff @{upstream}"
alias gpo="git push origin" alias glog="git log --oneline --decorate --graph"
alias gros="git reset origin/$(git_current_branch) --soft" alias gloga="git log --oneline --decorate --graph --all"
alias gcan="git commit -v --amend --no-edit"
alias glogaa="git log --oneline --graph --all --pretty=format:\"%C(auto)%h %C(blue)(%aL/%cL)%C(auto)%(decorate) %s%Creset\"" alias glogaa="git log --oneline --graph --all --pretty=format:\"%C(auto)%h %C(blue)(%aL/%cL)%C(auto)%(decorate) %s%Creset\""
# unsorted # git staging/commit
alias ci="glab ci list" alias ga="git add"
alias bm=batman alias gc="git commit -v"
alias grow="~/.local/bin/cbonsai -liWC -M 15 -t 2 -w 60 -s $(date +%s)" alias gc!="git commit -v --amend"
alias clean_ds_store='find . -name ".DS_Store" -type f -delete -print' alias gcan="git commit -v --amend --no-edit"
alias gcan!="git commit -v --all --no-edit --amend"
alias grs="git restore"
# git branch/checkout
alias gb="git branch"
alias gco="git checkout"
alias gcm='git checkout $(git_main_branch)'
alias gsw="git switch"
# git fetch/pull/push
alias gfa="git fetch --all --prune"
alias gl="git pull"
alias gp="git push"
alias gpf="git push --force-with-lease"
alias gpf!="git push --force"
alias gpo="git push origin"
# git rebase
alias grb="git rebase"
alias grba="git rebase --abort"
alias grbc="git rebase --continue"
alias grbi="git rebase -i"
grbm() { git rebase "$(git_main_branch)" }
# git merge
alias gm="git merge"
alias gma="git merge --abort"
alias gmc="git merge --continue"
# git cherry-pick
alias gcp="git cherry-pick"
alias gcpa="git cherry-pick --abort"
alias gcpc="git cherry-pick --continue"
# git stash/reset
alias gstp="git stash pop"
gros() { git reset "origin/$(git_current_branch)" --soft }
# ruff # ruff
alias ruffme="ruff check --fix && ruff format" alias ruffme="ruff check --fix && ruff format"
# clipboard
alias xcp="xclip -selection c"

View File

View File

@@ -1,51 +0,0 @@
#!/usr/bin/env bash
function get-dump {
if [[ -z $1 ]]; then
host="$(rg -N --no-heading 'Host .*' ~/.ssh \
| sed 's/Host \(.*\)/\1/' \
| fzf --cycle \
--bind 'tab:toggle-up,btab:toggle-down' \
--delimiter ':' \
--with-nth 2 \
--header "Navigate with ARROW KEYS or TAB/S-TAB. Select with ENTER." \
--border "double" \
--border-label "get-dump" \
--ansi \
--highlight-line \
| cut -d ":" -f2
)"
if [[ -z $host ]]; then
return
fi
else
host=$1
fi
selected=$(ssh "$host" docker ps --format "{{.Names}}" \
| fzf --cycle \
--bind 'tab:toggle-up,btab:toggle-down' \
--header "Navigate with ARROW KEYS or TAB/S-TAB. Select with ENTER." \
--border "double" \
--border-label "get-dump" \
--ansi \
--highlight-line \
)
if [[ -z $selected ]]; then
echo "not provided"
return
fi
if ! [[ -d "./dumps" ]]; then
mkdir "./dumps"
fi
location="./dumps/${host}_${selected}_$(date +'%s')"
echo "dumping to $location"
ssh "$host" docker exec "$selected" pg_dump -U db --format=c db >"$location"
}
get-dump "$@"

View File

@@ -1,90 +1,28 @@
function nvim_ve { # git helpers for aliases
if [[ -e $VIRTUAL_ENV && -f "$VIRTUAL_ENV/bin/activate" ]]; then function git_current_branch {
source "$VIRTUAL_ENV/bin/activate" command git rev-parse --abbrev-ref HEAD 2>/dev/null
command nvim $@
deactivate
else
command nvim $@
fi
} }
function afm { function git_main_branch {
RES=$(curl -s "https://$1/api/monitoring/requirements") command git rev-parse --git-dir &>/dev/null || return
COUNT=$(echo "$RES" | grep -c $2) local ref
if [[ $COUNT -ge 0 ]]; then for ref in refs/{heads,remotes/{origin,upstream}}/{main,master,trunk}; do
VER=$(echo "$RES" | jq '.[] | select(.name | contains("'"$2"'")).version') if command git show-ref -q --verify "$ref"; then
# OP=$(echo "$RES" | jq '.[] | select(.name | contains("'"$2"'")).requirement?[0][0]') echo ${ref:t}
# echo "$2""$(echo "$OP" | tr -d '"')""$(echo "$VER" | tr -d '"')" return 0
echo "${2}==$(echo "$VER" | tr -d '"')"
fi fi
done
echo main
} }
function nukepip {
pip uninstall $(pip freeze) -y
pip install -r $(pyenv root)/default-packages
}
function pyinit {
if [[ -f .python-version ]]; then
echo "found .python-version, stopping"
return
fi
DIRNAME=$(basename "$PWD")
if [[ $(pyenv versions | grep -E "/${DIRNAME}$") ]]; then
echo "found existing version with this name, setting..."
pyenv local "$DIRNAME"
return
fi
if [[ -z $1 ]]; then
echo "no python version provided, defaulting to $(pyenv version-name)"
VERSION=$(pyenv version-name)
else
VERSION=$1
fi
pyenv virtualenv "$VERSION" "$DIRNAME"
pyenv local "$DIRNAME"
}
function lh {
if [[ -z $1 ]]; then
PORT=7999
else
PORT=$1
fi
open "http://localhost:$PORT"
}
function dps {
if [[ -z $1 ]]; then
docker ps --format table'{{ .ID }}\t{{ .Image }}\t{{ .Ports}}\t{{ .Names }}'
else
docker ps --format table'{{ .ID }}\t{{ .Image }}\t{{ .Ports}}\t{{ .Names }}' | grep $1
fi
}
function tssh {
if [[ -z $1 ]]; then
echo "provide ssh host"
return
fi
ssh -t "$@" "command -v tmux && (tmux a || tmux new-session -s gorazd -c ~) || bash"
}
function tmux_attach { function tmux_attach {
local tmux_running
tmux_running=$(pgrep tmux) tmux_running=$(pgrep tmux)
if ! [[ -z ${TMUX} ]]; then if [[ -n ${TMUX} ]]; then
echo "already attached; refreshing env" echo "already attached; refreshing env"
source <(tmux show-environment | sed -n 's/^\(.*\)=\(.*\)$/export \1="\2"/p') source <(tmux show-environment | sed -n 's/^\(.*\)=\(.*\)$/export \1="\2"/p')
return 1 return 0
fi fi
if [[ -z $tmux_running ]]; then if [[ -z $tmux_running ]]; then