Skip to content

Commit

Permalink
Use add-zsh-hook for all zsh hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiX committed Sep 16, 2024
1 parent 4700123 commit 8b5b338
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 41 deletions.
30 changes: 4 additions & 26 deletions zsh/funcs/prompt_jde_setup
Original file line number Diff line number Diff line change
Expand Up @@ -550,24 +550,13 @@ prompt_jde_ps1 () {
PS2="${(j::)ps2}"
}

#############################################################################}}}
### WINCH {{{
################################################################################
#TODO: this is not getting called
prompt_jde_winch () {
setopt localoptions noksharrays

# Delete ourself from TRAPWINCH if not using our precmd insert.
[[ $functions[precmd] = *prompt_jde_precmd* ]] && prompt_jde_ps1 ||
functions[TRAPWINCH]="${functions[TRAPWINCH]//prompt_jde_winch}"
}

#############################################################################}}}
### SETUP {{{
################################################################################
prompt_jde_setup () {
# zsh options we require: prompt_*
prompt_opts=( cr subst percent )
autoload -Uz add-zsh-hook

setopt localoptions noksharrays
typeset -g PROMPT_JDE_ALTCHAR PROMPT_JDE_MAILCOUNT
Expand All @@ -577,9 +566,6 @@ prompt_jde_setup () {
# A few extra niceties ...
repeat 1 case "$1:l" in
(off|disable)
functions[precmd]="${functions[precmd]//prompt_jde_precmd}"
functions[preexec]="${functions[preexec]//prompt_jde_preexec}"
functions[TRAPWINCH]="${functions[TRAPWINCH]//prompt_jde_winch}"
[[ $prompt_theme[1] = jde ]] && PS1=${${(f)PS1}[-1]}
return 1
;;
Expand Down Expand Up @@ -608,17 +594,9 @@ prompt_jde_setup () {

prompt_jde_ps1

# Paste our special commands into precmd and TRAPWINCH
functions[precmd]="${functions[precmd]//prompt_*_precmd}
prompt_jde_precmd"

functions[preexec]="${functions[preexec]//prompt_*_preexec \"\$1\"}
prompt_jde_preexec \"\$1\""

functions[TRAPWINCH]="${functions[TRAPWINCH]//prompt_jde_winch}
prompt_jde_winch"

return 0
# Wire up hooks
add-zsh-hook precmd prompt_jde_precmd
add-zsh-hook preexec prompt_jde_preexec
}

# }}}
Expand Down
13 changes: 7 additions & 6 deletions zsh/rc.apps
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ then
alias tdl='todo --link' # Debian...

# Run on directory changes
functions[chpwd]="${functions[chpwd]//chpwd_devtodo}
chpwd_devtodo"
autoload -Uz add-zsh-hook
add-zsh-hook chpwd _chpwd_devtodo

chpwd_devtodo ()
_chpwd_devtodo ()
{
[[ -t 0 && -r .todo ]] && devtodo "$TODO_OPTIONS[@]"
}
Expand Down Expand Up @@ -61,16 +61,17 @@ then
doas ()
{
local -U path=($path /sbin /usr/sbin /usr/local/sbin)
local WAYLAND_DISPLAY="$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY"
command doas "$@"
}
fi

if [[ -x =git ]]
then
functions[chpwd]="${functions[chpwd]//chpwd_gitblame}
chpwd_gitblame"
autoload -Uz add-zsh-hook
add-zsh-hook chpwd _chpwd_gitblame

chpwd_gitblame ()
_chpwd_gitblame ()
{
if [[ -d .git && -f .git-blame-ignore-revs ]]
then
Expand Down
8 changes: 5 additions & 3 deletions zsh/rc.prompt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r'
zstyle ':vcs_info:*' enable git cvs svn darcs mtn hg bzr
if vcs_info 2> /dev/null
then
functions[precmd]="${functions[precmd]//vcs_info}
vcs_info"
autoload -Uz add-zsh-hook
add-zsh-hook precmd vcs_info
fi

# screen info
case "$TERM" in
screen*)
preexec ()
autoload -Uz add-zsh-hook
add-zsh-hook preexec _preexec_screen_title
_preexec_screen_title ()
{
local CMD=${1[(wr)^(*=*|sudo|-*)]}
CMD=${CMD##*/}
Expand Down
12 changes: 6 additions & 6 deletions zsh/rc.screen
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ if [[ -x =tmux ]]
then
if [[ -n $TMUX ]]
then
functions[precmd]="${functions[precmd]//tmux_magic_precmd}
tmux_magic_precmd"
autoload -Uz add-zsh-hook
add-zsh-hook precmd _precmd_tmux_magic

tmux_magic_precmd () {
_precmd_tmux_magic () {
eval $(tmux show-environment -s)
}

Expand All @@ -23,10 +23,10 @@ then
if [[ -n $STY ]]
then
# Now for the bigger magic
functions[precmd]="${functions[precmd]//screen_magic_precmd}
screen_magic_precmd"
autoload -Uz add-zsh-hook
add-zsh-hook precmd _precmd_screen_magic

screen_magic_precmd () {
_precmd_screen_magic () {
local parent=$(_get_screen_parent)
if [[ $parent != $screen_magic_lastparent && -r /proc/$parent/environ ]]
then
Expand Down

0 comments on commit 8b5b338

Please sign in to comment.