[Home] Zsh logo

per_directory_history

Zsh Wizard

Download per_directory_history Return to Examples
  1. # From: "Bart Schaefer" <schaefer>
  2. # Subject: Re: per-directory history?
  3. #
  4. # On Apr 11, 12:08pm, Matt Pharr wrote:
  5. # } Subject: per-directory history?
  6. # }
  7. # } I was thinking about the history stuff in zsh last night, and it struck me
  8. # } that it would be neat to have a per-directory history mechanism.
  9. # }
  10. # } Is this easily done at the user level given zsh's current set of features?
  11. #
  12. # Relatively easily, yes. The main issues are security (avoid loading a
  13. # history left for you by someone malicious (though this isn't too bad as
  14. # the commands aren't actually executed)), collision-avoidance in shared
  15. # directories, and handling of non-writable directories.
  16. #
  17. # The solution looks something like
  18. chpwd() {
  19. local ohistsize=$HISTSIZE
  20. fc -W ~-/.history.$UID
  21. HISTSIZE=0 # Discard previous dir's history
  22. HISTSIZE=$ohistsize # Prepare for new dir's history
  23. fc -R ./.history.$UID
  24. }