Compare commits
6 Commits
111f72bf59
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7c98b592bc | |||
| 1f5b1d841b | |||
| 719ce5f992 | |||
| 09340b74e8 | |||
| a59bcafcf3 | |||
| 2b81c4bcd9 |
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -144,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.
|
||||||
|
|||||||
@@ -33,12 +33,16 @@ 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
|
if [ -f $root/.enter ] && [ -f $root/.exit ]; then
|
||||||
ln -s $root/.enter $wt_dest/.enter
|
ln -s $root/.enter $wt_dest/.enter
|
||||||
ln -s $root/.exit $wt_dest/.exit
|
ln -s $root/.exit $wt_dest/.exit
|
||||||
_autoenv_authorized $PWD/.enter yes
|
_autoenv_authorized $wt_dest/.enter yes
|
||||||
_autoenv_authorized $PWD/.exit yes
|
_autoenv_authorized $wt_dest/.exit yes
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
rm|remove)
|
rm|remove)
|
||||||
|
|||||||
5
zshenv
5
zshenv
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user