6 ms·
Cd Is Wasting Your Time
- c22 9y agoWhy not ls ~/Dev<TAB>/<TAB><TAB>pro<TAB> I guess cd would waste a lot of my time if I was cding everywhere to just "look around".
- btown 9y agoI use code based on http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-f... and the discussion thread https://news.ycombinator.com/item?id=6229001 https://news.ycombinator.com/item?id=6229001 - no need for Python or something extra to install, similar semantics, just put this in .bash_profile: export MARKPATH=$HOME/.marks function j { cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1" } function mark { mkdir -p "$MARKPATH"; ln -s "$(pwd)" "$MARKPATH/$1" } function unmark { rm -i "$MARKPATH/$1" } function marks { \ls -l "$MARKPATH" | tail -n +2 | sed 's/ / /g' | cut -d' ' -f9- | awk -F ' -> ' '{printf "%-10s -> %s\n", $1, $2}' } function _jump { local cur=${COMP_WORDS[COMP_CWORD]} local marks=$(find $MARKPATH -type l | awk -F '/' '{print $NF}') COMPREPLY=($(compgen -W '${marks[@]}' -- "$cur")) return 0 } complete -o default -o nospace -F _jump j With multiple projects and codebases going on at once, it's an invaluable tool.
- shakna 9y agoI think fish wins this game without looking archaic, and zsh with fish-style completions wins it and is POSIX-compliant. Completions are remembered, so if your project has ever had the same setup, cd will predict for you, and be a couple keystrokes away.
- rnhmjoj 9y agoAlso fish stores the current directory along the command in history; so in ~/src/project the completion will show first commands you typed here rather than ~ or some other directory. This is incredibly useful.
- Const-me 9y agoGUI file browsers support keyboard commands and they are much faster to type, because commands are much shorter. “cd .. {Enter}” in console is either “{Alt}+{Up arrow}” or “{Home} {Enter}” in GUI, 6 versus 2 key presses. “cd de{tab}” in console is “d e” or “{Alt}+d e” in GUI, 6 versus 2-3 key presses. GUI tools are able to expose shorter commands because context is richer, i.e. user instantly sees a filter edit box popping up after {Alt}+d, user will see both current location + child items after each navigation or filter operation, etc. That kind of interactivity is what saves user input. The approach is hard to implement in a shell because shells were designed for command-output interaction model. OTOH, rich GUI tools are much harder to develop.
- jbergens 9y agoFor example the Total Commander on Windows has nice shortcuts for going to your most common folders or show the list of recently visited folders.
- Const-me 9y agoI’m also on Windows, and using both Total Commander and Far. Often at the same time, but they’re both very good. TC has better archives support, and better F3 previews for pictures and multimedia. Far has slightly better FTP client, includes SCP client, has _much_ better F4 editor, and also has seamless command-line shell integration, i.e. Ctrl+O switches between blue panels and interactive shell, with synchronized current directory and commands to insert file names/paths into the shell prompt.
- icebraining 9y agoThat GUI is more efficient because it limits you to navigation commands. There's no reason why a navigation-specific shell can't let you type "de{Enter}" and automatically change to that directory.
- Const-me 9y ago> That GUI is more efficient because it limits you to navigation commands While indeed limited, it’s not limited just to navigation. Here’s a GUI that appears when I press Alt+F7 in a GUI file manager: http://const.me/tmp/tc-find-gui.png http://const.me/tmp/tc-find-gui.png It exposes combined functionality of many Linux shell utilities: find, grep, lsattr, xargs, fdupes, iconv, mountavfs/fusermount, etc. For example I click “{Alt}+(F7 r t) test {enter}” to find all files containing “test” in all files and subdirectories, including content of archives. That’s 9 key presses. Can you do equally efficient in a command line shell? Not only it saves key presses, its also less stuff to remember and therefore much easier to use. I only need to remember Alt+F7, the rest is obvious because labels, and by convention, underlined letters in them mark {Alt}+{Letter} shortcuts. You don’t even need to use keyboard, mouse is even more accessible (but not touchscreens, for them entirely different GUI is required).
- lolive 9y agoA bit offtopic, but anyway: The more I use the command line, the more I type full path on my commands. So (when I recall them from history) I can run them from anywhere. Next step is to store path in variables, and my command lines contain the variable instead of the path (depending whether I want the history to include the variable or the path, I will Ctrl-Alt-e the commande line before running it). Next step is to define functions to aggregate several command lines together. And be able to replay them later. (I built a small utility to make it super simple, otherwise it is a complex time-consuming process to define and manage functions in shell). Next step is to separate those functions into several local accounts, so tasks (and bash history) are cleanly separated. Next step is to use screen/tmux to have one (or more) shell open for all those local accounts. (i usually have a "master" tmux, with one window per user, and each user can launch its own tmux inside it). That sounds insanely complex. But I find a kind of calmness now. My tasks are organized by user, histories are very semantic (each command line is a function name, very few "cd" or other non-meaningful commands). And when I need to type commands, I think whether I will go the usual way (aka the _quick and dirty_ way). Or if I will build a clean workflow so I can replay my commands later.
- 1_player 9y agoProbably not a direct answer to your comment, but fish autocompletion has two killer features I haven't found in any other shell: 1. Type part of a command and search the history: I often have to run a mysqldump + mysql load on a couple databases, and the command is quite long. If i just type `db1` and press up arrow, fish will load the command 'mysqldump -uxxx db1 | mysql -uyyy local_db1'. I don't have to create functions to do complex, common shell commands, as long as they have keywords I can use to look them up. 2. Search the history based on the current path: Suppose I have two directories, `app1` and `app2`, each with a `run-appX` executable. If I enter `app2` and I type `.`, fish will autocomplete it to `./run-app2`, because the history is context dependent, and it knows there's a `run-app2` file I've often referenced while in the `app2` directory. Haven't found a way to replicate these two behaviours in any other shell as well as fish does, and I don't have to create separate functions for most of my workflow. fish takes care of that.
- 9y ago
- helb 9y agoPossibly related – one of my most used keystroke-saving aliases/functions is: mcd () { mkdir -p "$*" && cd "$*" } …which, quite obviously, creates a directory and jumps into it. Note: the name overrides the GNU Mtools' mcd (https://www.gnu.org/software/mtools/manual/mtools.html#mcd https://www.gnu.org/software/mtools/manual/mtools.html#mcd) on some systems – choose another name if you need the tool. The original mcd "changes MSDOS directory" according to it's manpage, and wants to do something with a floppy drive when i run it by mistake.
- psisbwvaiia 9y agoI make an alias for each dir that I know I’ll be working in a lot. If I need workspaces I save a tmux session. Is that aight? Is j good for more u predictable patterns? I’ll give it a shot
- bulbousR 9y agoRanger is pretty good and has vim bindings ootb
- bradknowles 9y agoThe title should be "cd is Wasting Your Time", with a lowercase "cd". We're not talking about Coefficient of Drag here, which would be a proper "Cd", we're talking about the shell command "cd".
- craftyguy 9y agofrom the autojump readme: > Directories must be visited first before they can be jumped to. Well that's annoying..
- oweiler 9y agoI add popular paths to CDPATH to directly jump to the directory I want to. Has it's problems but works quite well.