4 ms·
Cd command is broken
Everyone who knows `cd` kowns there's another command called `ls`. `ls` is always typed after `cd`. Like `cd project`, ls`.
Everyone wants to read child files as soon as he enters a directory, and `ls` is the command.
But why are `cd` and `ls` the same command. Enter a directory is an action, rather than 忒o actions. Suppose you want to open a site called <https://news.ycombinator.com> and you type in the url and hit Enter(like `cd hacker-news`). Then do you need to type in `open` to read?
Hope one day we may fix it.
- iamtherockstar 14y agoHuh? Since when do you always use 'ls' after 'cd' - I can think of many times that I don't need to do this, and it would annoy me if every time I called 'cd' it then printed out the directory listing as well. The popular Unix mantra is "do one thing and do it well" - both these commands, while definitely connected, are each "one thing" and they both perform them very well.
- jiyinyiyong 14y agoThe philosophy of Unix convinced me at my first glance. But then found there might be some problem in this case. Just an example. People may say something offer three features, one plus one and plus one, just like Unix does. But if we are going to explain 99, it is faster to say 100 minus 1 rather than 90 plus 9. `cd $1 && ls` is a larger command. It's also an easier one.
- maerF0x0 14y agoscripting is your friend: $ function newcd(){ cd $1; ls;} $ alias cd=newcd $ cd .. $ cd Desktop EDIT: I had accidentally put a "$1" in the ls command, now removed.
- jiyinyiyong 14y agoThat's my solution right now. There's a bug I don't kown if you can grt rid of it or not. When I type `cd a\ dir`, it works, while `c a\ dir` fails. `$1` seems not to cover the whole parameter. Can you fix this?
- mmozeiko 14y agoVery often I don't want ls. I want cd X && make. Or cd X && svn up. Or something similar.
- jiyinyiyong 14y agoI think it doesn't metter if this command gives several lines more logs. It doesn't do anything else that may break the faollowing command.
- nayefc 14y agoYou can add an alias in bash to fix this. Or type dir && ls. Your assumption is wrong. We don't "type ls after cd". Maybe a lot of times, but definitely not most of the times. I memorize my directories from the first time I'm in that I barely need to type ls.
- jiyinyiyong 14y agoStill feeling strange that someone remembers all files and pathes. (Or maybe the habbits in China is a bit different. Even I use Bash everyday, I still want to read file list every time I enter a directory.)
- nayefc 14y agoI usually cd into the main directory I want to be in and then if I ever want to edit a file, simply typing emacs then tab for bash for auto-completion does the trick. But again, just use a bash alias :) What's the problem with that?
- jiyinyiyong 14y agoStill feeling strange that someone remembers all files and pathes. (Or maybe the habbits in China is a bit different. Even I use Bash everyday, I still want to read file list every time I enter a directory.)
- nayefc 14y agoWhy does this sound like a marketing email/post to me?