Re:Some Useful Bash Aliases – Chuck Carroll
by ForkMeOnTinder on Monday December 25, 2023 @04:10PM
(#38766132)
Merry christmas, HN!
[ Parent
| on HN ]
Re:Some Useful Bash Aliases – Chuck Carroll
by jafarlihi on Monday December 25, 2023 @04:23PM
(#38766256)
I devised `cdb` for this: https://github.com/jafarlihi/dotfiles/blob/a5133f49d67732199...
You can do just `cdb 5` to navigate 5 directories back.
Re:Some Useful Bash Aliases – Chuck Carroll
by pokler on Monday December 25, 2023 @04:36PM
(#38766358)
up() { cd $(eval printf '../'%.0s {1..$1}); }
So you can just type something like `up 2` to move by two directories.
Re:Some Useful Bash Aliases – Chuck Carroll
by fsckboy on Tuesday December 26, 2023 @01:26AM
(#38769354)
eval printf? um.... is your name little bobby tables by any chance?
Re:Some Useful Bash Aliases – Chuck Carroll
by ibiza on Monday December 25, 2023 @04:50PM
(#38766464)
I did not realize cd'ing up was an esoteric sport. My own take:
shopt -s cdable_vars
u2=../.. u3=../../.. u4=../../../.. u5=../../../../..
Re:Some Useful Bash Aliases – Chuck Carroll
by jbaber on Monday December 25, 2023 @05:36PM
(#38766903)
I used to do things like this until I found bash has
shopt -s autocd
which makes it so naming a directory cd's to it, including .. ~ etc.
Re:Some Useful Bash Aliases – Chuck Carroll
by Biganon on Monday December 25, 2023 @06:42PM
(#38767426)
I think it's a terrible idea, because one day you'll try to enter a directory that shares its name with a command you don't know, and it will execute this command instead
Re:Some Useful Bash Aliases – Chuck Carroll
by dw_arthur on Monday December 25, 2023 @06:28PM
(#38767343)
my version of ..
function ..() {
local temp_dir=$PWD
cd ..
for token in "$@"; do
cd ..
done
OLDPWD=$temp_dir
}
so you can just type .. to go up once or .. [word] to go up twice and so on
Re:Some Useful Bash Aliases – Chuck Carroll
by JNRowe on Monday December 25, 2023 @11:06PM
(#38768835)
That seems potentially unpredictable versus building the string and calling cd once. For example, if you use direnv-type tools there may be side-effects along the route¹. zsh users could have state changing via the chpwd functions too, although that could be mitigated with "cd -q" at least.
Obviously, it might not be an issue for your use, but just noting a potential gotcha if I were to lift it for example.
[ Golf-y zsh, because vacation time and AoC has finished: ..() { cd ../${(pj:/:)${@/*/..}} } ]
¹ even just expensive setup/teardown delays would feel odd*
Re:Some Useful Bash Aliases – Chuck Carroll
by POiNTx on Monday December 25, 2023 @06:36PM
(#38767391)
Not bash but if you're using fish you can use https://github.com/nickeb96/puffer-fish