8 Commits

Author SHA1 Message Date
7c98b592bc Remove (potentially broken) histfile migration 2026-03-13 09:56:01 +00:00
1f5b1d841b Update prompt to support Modular dev env 2026-03-05 11:35:20 +00:00
719ce5f992 Remove bindkeys from autoenv snapshots
This turned out to be a buggy mess so will be handled manually in
`.exit` files
2026-03-05 11:34:43 +00:00
09340b74e8 Introduce shell state snapshots to autoenv plugin
This patch provides `_autoenv_snap_pre` & `_autoenv_snap_post` to create
a shell state diff for use in `.enter` files which can then be restored
in `.exit` with `_autoenv_snap_restore`.
2026-03-05 11:20:14 +00:00
a59bcafcf3 Propertly authorize .enter/.exit in worktree add 2026-03-05 11:19:55 +00:00
2b81c4bcd9 Create new branch for worktree if it doesn't exist 2026-03-05 11:19:16 +00:00
111f72bf59 Update prompt to truncate directory in worktree 2026-02-25 18:38:48 +00:00
30fc9bf427 Link root repos .enter and .exit in new worktrees 2026-02-25 18:33:02 +00:00
4 changed files with 88 additions and 7 deletions

View File

@@ -132,6 +132,67 @@ commands:
# Global entered directories array. # Global entered directories array.
_autoenv_entered=() _autoenv_entered=()
# Per-directory shell state snapshots for computing enter/exit diffs.
typeset -gA _autoenv_snap_pre_funcs _autoenv_snap_pre_aliases _autoenv_snap_pre_env
typeset -gA _autoenv_snap_pre_path _autoenv_snap_pre_ps1
typeset -gA _autoenv_snap_diff_funcs _autoenv_snap_diff_aliases _autoenv_snap_diff_env
# Snapshot shell state before .enter modifications. Call in .enter BEFORE
# sourcing scripts: _autoenv_snap_pre ${0:A:h}
_autoenv_snap_pre() {
local dir=$1
_autoenv_snap_pre_funcs[$dir]="${(pj:\n:)${(@k)functions}}"
_autoenv_snap_pre_aliases[$dir]="${(pj:\n:)${(@k)aliases}}"
_autoenv_snap_pre_env[$dir]="${(F)$(typeset +gx 2>/dev/null)}"
_autoenv_snap_pre_path[$dir]="$PATH"
_autoenv_snap_pre_ps1[$dir]="$PS1"
}
# Snapshot shell state after .enter modifications and compute the diff.
# Call in .enter AFTER sourcing scripts: _autoenv_snap_post ${0:A:h}
_autoenv_snap_post() {
local dir=$1 f a v
local -a pre_funcs=("${(f)_autoenv_snap_pre_funcs[$dir]}")
local -a pre_aliases=("${(f)_autoenv_snap_pre_aliases[$dir]}")
local -a pre_env=("${(f)_autoenv_snap_pre_env[$dir]}")
local -a diff_funcs=() diff_aliases=() diff_env=()
for f in "${(@k)functions}"; do
(( ${pre_funcs[(Ie)$f]} )) || diff_funcs+=$f
done
for a in "${(@k)aliases}"; do
(( ${pre_aliases[(Ie)$a]} )) || diff_aliases+=$a
done
for v in "${(f)$(typeset +gx 2>/dev/null)}"; do
(( ${pre_env[(Ie)$v]} )) || diff_env+=$v
done
_autoenv_snap_diff_funcs[$dir]="${(pj:\n:)diff_funcs}"
_autoenv_snap_diff_aliases[$dir]="${(pj:\n:)diff_aliases}"
_autoenv_snap_diff_env[$dir]="${(pj:\n:)diff_env}"
unset "_autoenv_snap_pre_funcs[$dir]" "_autoenv_snap_pre_aliases[$dir]" \
"_autoenv_snap_pre_env[$dir]"
}
# Restore shell state by removing only what was added between snap_pre and
# snap_post. Call in .exit: _autoenv_snap_restore ${0:A:h}
_autoenv_snap_restore() {
local dir=$1 f a v
for f in "${(f)_autoenv_snap_diff_funcs[$dir]}"; do
[[ -n "$f" ]] && unset -f "$f"
done
for a in "${(f)_autoenv_snap_diff_aliases[$dir]}"; do
[[ -n "$a" ]] && unalias "$a" 2>/dev/null
done
for v in "${(f)_autoenv_snap_diff_env[$dir]}"; do
[[ -n "$v" ]] && unset "$v"
done
PATH="${_autoenv_snap_pre_path[$dir]}"
PS1="${_autoenv_snap_pre_ps1[$dir]}"
unset "_autoenv_snap_pre_path[$dir]" "_autoenv_snap_pre_ps1[$dir]" \
"_autoenv_snap_diff_funcs[$dir]" "_autoenv_snap_diff_aliases[$dir]" \
"_autoenv_snap_diff_env[$dir]"
prompt "${prompt_theme[@]}"
}
# Load zstat from stat module for inspecting modified time. # Load zstat from stat module for inspecting modified time.
zmodload -F zsh/stat b:zstat zmodload -F zsh/stat b:zstat

View File

@@ -79,6 +79,17 @@ fresh_line_one() {
# Check we are in a git repository # Check we are in a git repository
local git=`${XDG_CACHE_HOME:-$HOME/.cache}/zsh/git-prompt` local git=`${XDG_CACHE_HOME:-$HOME/.cache}/zsh/git-prompt`
# Truncate branch name from directory when already shown (e.g., worktrees)
if [[ -n "$git" ]] && [[ -z $SANDBOX_HOME ]]; then
local branch_name=$(git symbolic-ref --short HEAD 2>/dev/null)
if [[ -n "$branch_name" ]]; then
local dir=${(%):-%~}
if [[ "$dir" == *"@${branch_name}"* ]]; then
directory="%{%F{37}%}${dir/@${branch_name}/@}%{%f%}"
fi
fi
fi
# If the last command failed, display its error code at the right # If the last command failed, display its error code at the right
if [[ $exit_code -ne 0 ]]; then if [[ $exit_code -ne 0 ]]; then
case $exit_code in case $exit_code in
@@ -133,8 +144,12 @@ fresh_line_one() {
local docker=" %{%F{6}%}$DOCKER_MACHINE_NAME%{%f%}" local docker=" %{%F{6}%}$DOCKER_MACHINE_NAME%{%f%}"
fi fi
if [[ ! -z "$MODULAR_PATH" ]]; then
local modular=" 🔥"
fi
# Print the first line of the prompt # Print the first line of the prompt
print -P "$time_stamp $directory$git$py$docker$result" print -P "$time_stamp $directory$git$py$docker$modular$result"
} }
# Executed before each prompt. # Executed before each prompt.

View File

@@ -33,7 +33,17 @@ Manage git worktrees by branch name."
add) add)
local root=$(git rev-parse --show-toplevel) local root=$(git rev-parse --show-toplevel)
local wt_dest=${root:h}/${root:t}@${branch} local wt_dest=${root:h}/${root:t}@${branch}
git worktree add "$wt_dest" "$branch" if ! git show-ref --verify --quiet refs/heads/"$branch" && \
! git show-ref --verify --quiet refs/remotes/origin/"$branch"; then
git branch "$branch" origin/main || return 1
fi
git worktree add "$wt_dest" "$branch" || return 1
if [ -f $root/.enter ] && [ -f $root/.exit ]; then
ln -s $root/.enter $wt_dest/.enter
ln -s $root/.exit $wt_dest/.exit
_autoenv_authorized $wt_dest/.enter yes
_autoenv_authorized $wt_dest/.exit yes
fi
;; ;;
rm|remove) rm|remove)
local wt_path local wt_path

5
zshenv
View File

@@ -15,11 +15,6 @@ HISTFILE=${XDG_STATE_HOME:-$HOME/.local/state}/zsh/histfile
HISTSIZE=20000 HISTSIZE=20000
SAVEHIST=20000 SAVEHIST=20000
# Migrate histfile from cache to state directory
! [ -f $HISTFILE ] && [ -f $HOME/.cache/zsh/histfile ] && \
mv $HOME/.cache/zsh/histfile \
${XDG_STATE_HOME:-$HOME/.local/state}/zsh/histfile
# Remove vi mode switch delay # Remove vi mode switch delay
KEYTIMEOUT=1 KEYTIMEOUT=1