Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: persistant Directory history?
- X-seq: zsh-users 10954
- From: Francisco Borges <f.borges@xxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: persistant Directory history?
- Date: Wed, 8 Nov 2006 00:18:12 +0100
- Cc: chesss <testingagain@xxxxxxxxx>
- In-reply-to: <5db995410611071219q77820cfeg931ac950f744a276@xxxxxxxxxxxxxx>
- Mail-followup-to: zsh-users@xxxxxxxxxx, chesss <testingagain@xxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: Alfa Informatica - Rijksuniversiteit Groningen
- References: <5db995410611060845y53f673e6je029a9c60659f116@xxxxxxxxxxxxxx> <20061107145231.GA8117@xxxxxxxxxx> <5db995410611071219q77820cfeg931ac950f744a276@xxxxxxxxxxxxxx>
: On Wed, Nov 08, 2006 at 01:49AM +0530, chesss wrote:
> Finally this worked for me just perfect :) . i got it from
> http://www.zsh.org/mla/users/2006/msg00173.html
That was my first attempt (i.e. taking code from someone else ;-)) to
solve it, but there were problems with it.
> DIRSTACKSIZE=20
> if [[ -f ~/.zdirs ]] && [[ ${#dirstack[*]} -eq 0 ]]; then
> dirstack=( $(< ~/.zdirs) )
> popd > /dev/null
> fi
> precmd() {
> dirs -l >! ~/.zdirs # added -l
> }
> cd
>
> The only problem with the above was that a new shell would start with
> the last directory. So I added the extra 'cd' at the end :D
Here are the caveats of that code:
1. it will fail if your directories have spaces in their names. To solve
this you have to use "dirs -p" to put one dir per line, and use "f"
to read them.
2. The popd is used to avoid having multiple repeated entries; but a
beter solution is to simply use a "u" when loading the directories so
that duplicate entries are deleted.
3. You dont need to save the dirstack after every command, only when you
change dirs, so it's beter to use "chpwd" instead of "precmd".
Making these changes, you would have a better ;-) persistent dirstack
history with:
#----------------------------------------------------------
DIRSTACKSIZE=20
if [[ -f ~/.zdirs ]] && [[ ${#dirstack[*]} -eq 0 ]]; then
dirstack=( ${(uf)"$(< ~/.zdirs)"} )
fi
chpwd() { dirs -pl >! ~/.zdirs }
#----------------------------------------------------------
If you want $OLDPWD to work as well, then you have to include
cd $dirstack[0] && cd - > /dev/null
inside that "if" block.
Cheers,
--
Francisco Borges
Messages sorted by:
Reverse Date,
Date,
Thread,
Author