# This function is an adjunct to the history-beginning-local # zle widget. It saves any history entries that would be # found by that widget in the local history file, provided that # already exists. It also saves the history globally unless # the local-history-only style is set in the context. # # The context is :zhist: followed by the function name, a colon, the # current directory from $PWD, and another colon. emulate -L zsh setopt extendedglob zmodload -i zsh/parameter local name=${funcstack[1]} lhp local -a lhf lhc integer lho zstyle -a ":zhist:${name}:${PWD}:" local-history-file lhf || return 1 zstyle -a ":zhist:${name}:${PWD}:" local-history-commands lhc || return 1 zstyle -s ":zhist:${WIDGET}:${PWD}:" local-history-pattern lhp zstyle -t ":zhist:${name}:${PWD}:" local-history-only && lho=1 for f in $lhf; do if [[ -f $f ]]; then local -a words words=(${(z)1}) if [[ ${(Q)words[1]} = (${(j.|.)~lhc}) || \ ( -n $lhp && $1 = ${~lhp} ) ]]; then # Save on the global history unless we're told not to. # If we define multiple zshaddhistory hooks we want a # a way of signalling that we've done this. One way # of doing this would be to set a global parameter to $HISTCMD, # although that doesn't change if we've ignored the previous line. # Another way would be to have a zshaddhistoryhook that reset # a global parameter (since this is called first) and rely # on all the other hooks being in zshaddhistory_functions, # as they should be for neatness. (( lho )) || print -Sr -- ${1%%$'\n'} fc -p -- $f break fi fi done