commit 8f8ab83383257b0476693626ceb5cf19aca05bf0
parent df67719d5ad3469908e7e41134ce2622c1f4fad8
Author: mtmn <miro@haravara.org>
Date: Wed, 3 Jun 2026 23:55:54 +0200
prompt: add support for git worktrees
Diffstat:
2 files changed, 39 insertions(+), 18 deletions(-)
diff --git a/hosts/void/overlays/config/shell/rc/void b/hosts/void/overlays/config/shell/rc/void
Binary files differ.
diff --git a/modules/mixins/dotfiles/config/shell/rc/prompt-functions b/modules/mixins/dotfiles/config/shell/rc/prompt-functions
@@ -1,5 +1,5 @@
# vim: ft=sh
-_SNOWFLAKE=$'\U2744'
+_SNOWFLAKE=$(printf '\342\235\204')
_C_RESET=$(tput sgr0)
_C_1=$(tput setaf 1)
_C_2=$(tput setaf 3)
@@ -8,7 +8,7 @@ _C_4=$(tput setaf 5)
_C_6=$(tput setaf 6)
colour_part() {
- local colour_val msg delim
+ colour_val=''
msg="$2"
delim="${3- }"
[ "$msg" ] || return 1
@@ -27,7 +27,7 @@ colour_part() {
}
_jj_prompt() {
- local jj_wc jj_bookmarks jj_state
+ jj_state=''
if ! jj root >/dev/null 2>&1; then
return 1
fi
@@ -45,7 +45,8 @@ _jj_prompt() {
}
_git_prompt() {
- local branch git_state git_head git_dir tag
+ git_head=''
+ git_state=''
if branch="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)"; then
if [ "$branch" != HEAD ]; then
git_head=$branch
@@ -54,12 +55,21 @@ _git_prompt() {
else
git_head=$(git rev-parse --short HEAD)
fi
- git_dir=$(git rev-parse --git-dir)
+ git_dir=$(git rev-parse --absolute-git-dir 2>/dev/null)
+ case "$git_dir" in
+ */worktrees/*)
+ git_head=$(basename "$(git rev-parse --show-toplevel 2>/dev/null)")
+ ;;
+ *)
+ [ "$git_head" = master ] && unset git_head
+ [ "$git_head" = main ] && unset git_head
+ ;;
+ esac
if [ -d "$git_dir/rebase-apply" ] || [ -d "$git_dir/rebase-merge" ]; then
git_state=rebase
elif [ -f "$git_dir/MERGE_HEAD" ]; then
git_state=merge
- elif [ -f "$git_dir/CHERRY_PICK_HEAD" ] || [ -f .git/sequencer/todo ]; then
+ elif [ -f "$git_dir/CHERRY_PICK_HEAD" ] || [ -f "$git_dir/sequencer/todo" ]; then
git_state=cherry-pick
elif [ -f "$git_dir/REVERT_HEAD" ]; then
git_state=revert
@@ -67,10 +77,8 @@ _git_prompt() {
git_state=bisect
fi
fi
- [ "$git_head" = master ] && unset git_head
- [ "$git_head" = main ] && unset git_head
- colour_part 2 "$git_head"
- colour_part 1 "$git_state"
+ colour_part 2 "${git_head-}"
+ colour_part 1 "${git_state-}"
}
_virt_prompt() {
@@ -101,7 +109,6 @@ _devshell_prompt() {
_user_prompt() {
if ! [ "${_USER+x}" ]; then
- local user
user=$(id -un)
case $user in
miro) _USER='' ;;
@@ -113,20 +120,34 @@ _user_prompt() {
_pwd_prompt() {
[ "$PWD" = "$HOME" ] && return
- local stripped_pwd="${PWD##*/}"
- colour_part 4 "${stripped_pwd:-/}"
+ colour_part 4 "${_PWD_PART:-${PWD##*/}}"
}
_vcs_prompt() {
- if [ "$PWD" != "$_VCS_LAST_PWD" ]; then
- _VCS_LAST_PWD=$PWD
- _VCS_CACHE=$(_jj_prompt || _git_prompt)
- fi
printf '%s' "$_VCS_CACHE"
}
+_prompt_precmd() {
+ [ "$PWD" = "$_VCS_LAST_PWD" ] && return
+ _VCS_LAST_PWD=$PWD
+ _PWD_PART=''
+ if git_dir=$(git rev-parse --absolute-git-dir 2>/dev/null); then
+ case "$git_dir" in
+ */worktrees/*)
+ main_git="${git_dir%/worktrees/*}"
+ _PWD_PART=$(basename "${main_git%/.git}")
+ ;;
+ esac
+ fi
+ _VCS_CACHE=$(_jj_prompt || _git_prompt)
+}
+
+if [ "$ZSH_VERSION" ]; then
+ autoload -Uz add-zsh-hook
+ add-zsh-hook precmd _prompt_precmd
+fi
+
_get_ps1() {
- local prompt_ender
if [ "$ZSH_VERSION" ]; then
prompt_ender="%(?:%%:%{${_C_1}%}%%%{${_C_RESET}%})"
else