tcsh: pushd + popd in one function
I really like pushd and popd, but I don't like their long spellings, so I made aliases: 'x' runs pushd and 'xx' runs popd. That's not bad, but I wish I could improve them in the following way:
x => If followed by a path, 'pushd' (and cd to) that path. If not given any arguments, run 'popd'. xx => 'cd -' The problem is implementing that pushd/popd in one command trick. Since tcsh does not have functions, I've been struggling hard to come with a solution. I made a script, and it works, but it only works within the context of the script. The script exits and not only am I still sitting in the same directory, but also my dirstack is emptied. A similar problem: make 'cdd'. I remember using that program in DOS a long time ago. I would run 'cdd /path/to/directory' and cd to that path if it existed, or create it and cd to it if it didn't exist. Again, I made a script, but that only works within the context of the script, not my current shell. So the new dir is created, but my shell won't cd into it. Help, please? |
Solved
Ok, I found the solution on my own. I was making the following mistake in my .tcshrc:
Code:
foreach i (`\ls -1 ~/myscripts`) Code:
foreach i (`\ls -1 ~/myscripts`) in .tcshrc: Code:
foreach i (`\ls -1 ~/myscripts`) Code:
#!/usr/bin/env tcsh Code:
alias cd 'pushd ' Code:
complete {cd,popd,pushd,x} 'n/*/d/' |
All times are GMT -5. The time now is 06:12 PM. |