-
-
Save mbadran/130469 to your computer and use it in GitHub Desktop.
alias cd="pushd $@ > /dev/null" |
brilliant thread, guys!
the last revision by @3v1n0 - it's true oldschool hell of shell programming, applause! ππ₯π
close to ideal, except one missing thing, the last one that matters - the special behaviour of cd -P
description from cd --help
of bash builtin
-P | use the physical directory structure without following symbolic links:
resolve symbolic links in DIR before processing instances of `..' |
it's a pity, since I find this behaviour very useful for both interactive and scripted scenarios, and advise -P
everyone - it even worth to be mentioned as alias cd='cd -P'
at /etc/profile
however, as I see from your experiments above, one can try to mimic native cd -P
behaviour like this - pushd "$(realpath "$1")"
(nb! not tested)
if one implements this update during a week, that would be great! and I'll try to do it myself on weekends if not
and one more note to catch up especially for mr. @keltroth and mr. @3v1n0
as it caught my eye, you both till the last revision leave $OLDPWD
value unescaped, and it's quite dangerous, 'cause if the previous dir will include spaces in name - with cd -
one will definitely fail to return. and since everything in this routine is silenced with /dev/null
, it would be an adventure to find out what a hell is going on. been there, seen that
I've been fond of tuning little things of that kind a lot, it's very exciting sometimes
the last for today - three more functions on topic from my own regular set of /etc/bash.functions
pushd () {
builtin pushd ${1} >/dev/null 2>&1
}
popd () {
builtin popd ${1} >/dev/null 2>&1
}
dirs () {
builtin dirs -v
}
respect, guys!
Another improvement over @jan-warchol version, to make
cd -
to alternatively usepushd $OLDPWD
andpopd
depending on what we called before.This allows to avoid to fill your history with elements when you often do
cd -; cd - # repeated as long you want
. This could be applied when using this alias also for$OLDPWD
, but in that case it might be that you want it repeated there, so I didn't touch it.Also added
cd -l
as alias fordir -v
and usecd -g X
to go to theX
th directory in your history (without popping, that's possible too of course, but it' something more an addition in this case).