Navigating through my directory history from the command line

view story

http://unix.stackexchange.com – In Zsh, is there a way to navigate through the history of directories that I have visited (those listed in dirs) when I am typing a command in the command line? For example, say I type cd in the terminal, I would like to then use M-n or M-p until I find the directory that I want to follow cd as I type in my command. It would be extra nice if the list does not have any dupes. For example, if I visited A->B->C->A, the history should just be B->C->A. It would also be great if the list can keep track of directories across multiple sessions (in the same way my code below does (HowTos)