jimhester / per-directory-history

Per directory history for zsh, as well as global history, and the ability to toggle between them with ^G.
zlib License
248 stars 35 forks source link

history files doesn't get populated with additional chpwd hook present #12

Open yggdr opened 9 years ago

yggdr commented 9 years ago

Hi, the history files seem to not get written to when I have the following autols function (excerpt from my zshrc). When I remove the autols function, it might start working, but not necessarily immediately?! I'm a bit confused by this behaviour, maybe you can figure it out? The per-directory history files get apparently touched, but not actually written to. Files are writeable by my user of course. Removing .directory-history doesn't help, the directory structure and history files get created, but not pupulated.

function autols() {
    local trdirs
    local cddir
    trdirs=('/storage/code' '/storage/torrents' '/storage/scratch')
    cddir=`pwd -P`

    if [[ ${trdirs[(i)$cddir]} -le $#trdirs ]] then
        ls -tr
    else
        ls
    fi
}

source $HOME/.zsh/zgen/zgen.zsh

if ! zgen saved; then
    #zgen oh-my-zsh

    zgen oh-my-zsh plugins/colorize
    zgen load zsh-users/zsh-syntax-highlighting
    zgen load voronkovich/gitignore.plugin.zsh
    zgen load rimraf/k
    zgen load jimhester/per-directory-history
    zgen oh-my-zsh plugins/per-directory-history
    zgen load oknowton/zsh-dwim
    zgen load knu/zsh-manydots-magic
    zgen oh-my-zsh plugins/pip
    zgen oh-my-zsh plugins/python
    zgen oh-my-zsh plugins/git
    zgen oh-my-zsh plugins/git-extras
    zgen oh-my-zsh plugins/mercurial
    zgen oh-my-zsh plugins/mosh
    zgen oh-my-zsh plugins/tmux
    #zgen oh-my-zsh plugins/tmuxinator
    #zgen oh-my-zsh plugins/catimg
    zgen oh-my-zsh plugins/colored-man
    zgen oh-my-zsh plugins/cp
    zgen oh-my-zsh plugins/extract
    #zgen oh-my-zsh plugins/django
    zgen oh-my-zsh plugins/wakeonlan
    zgen oh-my-zsh plugins/golang
    #zgen oh-my-zsh custom/themes/powerlevel9k
    #zgen load thvitt/tvline
    zgen load zsh-users/zsh-completions
    #zgen load tarruda/zsh-autosuggestions
    zgen load marzocchi/zsh-notify

    zgen save
fi

#zle-line-init() {
#    zle autosuggest-start
#}
#zle -N zle-line-init
#bindkey '^f' vi-forward-word

autoload -Uz manydots-magic
manydots-magic

source $HOME/.zsh/theme.zsh
add-zsh-hook chpwd autols
jimhester commented 9 years ago

per-directory-history also uses a chpwd hook (see jimhester/per-directory-history/per-directory-history.zsh#L144), so they must be interfering with each other somehow. Try adding the hooks in the opposite order and see if that helps things any.

jimhester commented 9 years ago

Also it looks like you are sourcing both the script from this repository and the one from oh-my-zsh, which may be messing things up, I would only source the one from here.

You could also try adding -U to the autoload command, which would ensure there is only one instance of the function loaded.

yggdr commented 9 years ago

When I move the add-zsh-hook directly after my autols function declaration, zsh complains that there is no add-zsh-hook. I have to manually add it to chpwd_functions like so chpwd_functions=('autols' $chpwd_functions). Here it doesn't matter whether autols comes first or not, the behaviour doesn't change. The double loading was a mistake when I tried to comment out most of zgen load. You can ignore it.

Can you reproduce the behaviour when you add an autols functions like I did?

IsmailM commented 9 years ago

Try #13…

On install I saw an error suggesting that the add-zsh-hook were not recognised…

Thus, the PR is a simple fix…

yggdr commented 9 years ago

@IsmailM Nope, doesn't help, but the hooks were always added, so that can't be the problem: echo $chpwd_functions _per-directory-history-change-directory autols _powerline_tmux_set_pwd