diff options
author | venomade <venomade@venomade.com> | 2025-02-27 18:22:03 +0000 |
---|---|---|
committer | venomade <venomade@venomade.com> | 2025-02-27 18:22:03 +0000 |
commit | ae02cb425a4340bee8aeb347ef17ca550f82d201 (patch) | |
tree | 6cc5a58c7d244b35b8df28da3f80688a6819d156 |
Add zshrc
-rw-r--r-- | .zshrc | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/.zshrc b/.zshrc new file mode 100644 index 0000000..c724133 --- /dev/null +++ b/.zshrc @@ -0,0 +1,56 @@ +autoload -U colors && colors + +USER_COLOR="%F{magenta}" +VENV_COLOR="%F{yellow}" +DIR_COLOR="%F{green}" +GIT_COLOR="%F{blue}" +GIT_DIRTY_COLOR="%F{red}" +PROMPT_SYMBOL_COLOR="%F{yellow}" +RESET_COLOR="%f" + +shorten_path() { + local path="${PWD/#$HOME/~}" + local parts=("${(@s:/:)path}") + + if (( ${#parts} > 3 )); then + echo "${parts[1]}/.../${parts[-2]}/${parts[-1]}" + else + echo "$path" + fi +} + +git_branch() { + local branch + branch=$(git symbolic-ref --short HEAD 2>/dev/null || git rev-parse --short HEAD 2>/dev/null) + [[ -n "$branch" ]] && echo "$branch" +} + +git_dirty() { + [[ -n "$(git status --porcelain 2>/dev/null)" ]] && echo "✗" || echo "✓" +} + +set_prompt() { + local user="${USER_COLOR}%n${RESET_COLOR}" + local venv="" + [[ -n "$VIRTUAL_ENV" ]] && venv="${VENV_COLOR}($(basename $VIRTUAL_ENV))${RESET_COLOR} " + + local path="${DIR_COLOR}$(shorten_path)${RESET_COLOR}" + local git_info="" + local branch="$(git_branch)" + + if [[ -n "$branch" ]]; then + git_info=" %F{white}on%f ${GIT_COLOR}${branch}${RESET_COLOR}${GIT_DIRTY_COLOR}$(git_dirty)${RESET_COLOR}" + fi + + PROMPT="${user} %F{white}in%f ${venv}${path}${git_info} +${PROMPT_SYMBOL_COLOR}λ${RESET_COLOR} " +} + +autoload -Uz add-zsh-hook +add-zsh-hook precmd set_prompt + +export PATH="$PATH:$HOME/.local/bin" + +alias gvc="ssh git@git.venomade.com" + +alias rgf='rg --files | rg' |