
Cd Is Wasting Your Time - ingve
https://olivierlacan.com/posts/cd-is-wasting-your-time/
======
btown
I use code based on [http://jeroenjanssens.com/2013/08/16/quickly-navigate-
your-f...](http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-
filesystem-from-the-command-line.html) 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.

------
lolive
A 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
Probably 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.

~~~
lolive
Very interesting tricks!

The first one probably has an equivalent in Bash with Ctrl-R and typing (and
Ctrl+R again to cycle through matching lines)

The second one is new to me. Cool!

~~~
BenjiWiebe
I have a long command I use semi-regularly in Bash. The ctrl-r search tends to
turn up the wrong command, so I edited the command and appended a unique
comment. Now I just do ctrl-r, unique-comment, enter.

------
Const-me
GUI 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
For 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
I’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.

------
helb
Possibly 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.

~~~
andscoop
Zsh has a built in like this called `take` that which quite nifty

~~~
helb
Thanks, didn't know that. I just copied the mcd function from .bashrc to
.zshrc when i switched ~5 years ago…

------
shakna
I 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
Also 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.

------
bradknowles
The 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".

------
c22
Why 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".

------
psisbwvaiia
I 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

------
oweiler
I add popular paths to CDPATH to directly jump to the directory I want to. Has
it's problems but works quite well.

------
bulbousR
Ranger is pretty good and has vim bindings ootb

------
craftyguy
from the autojump readme:

> Directories must be visited first before they can be jumped to.

Well that's annoying..

