2

This question is on the "do everything through the terminal" mindset. I find navigating through the file system very inefficient. My typical workflow is:

I want to go to ~/foo/bar/boo/far/my/project/file.txt

cd ~
cd foo/b...???
# okay, I won't quite remember what bar was called
# let me just go to "foo" and view it
cd foo
ls
# Oh, it was bar
cd bar
# Now, what was after bar again?
ls
# boo, that is it.
cd boo
pwd
ls
cd for
cd my
# ERROR: my not found
ls
# at this point I'm kinda lost where I am
pwd
cd ..
cd far
cd my
cd pro<tab>
cd proj<tab>
cd proje<tab>
# wtf am I in the wrong directory again?
ls
# notice there is a directory called projectiles, that's why it doesn't work
cd project
vim fi<tab>

Now I want to go to ~/foo/bar/boo/settings.txt

cd ../../..
vim set<tab>
# notice I'm editing a completely different file
# wtf
# :q
ls
# oh I'm in the wrong place
pwd
cd ..
vim set<tab>
# :q
# Done!

In a perfect world, I'd probably just type vim ~/foo/bar/boo/far/my/project/file.txt, but in a real-world workflow, that would be the equivalent of just typing the source code of a program from line 0 to the last line without missing a character. That's now how work works — you need some kind of interaction, it is a steppy and messy process. And using cd, ls and pwd for that is very inefficient to me.

Is there a better way? Am I missing something?

viclib
  • 129

2 Answers2

3

There are a lot of different options to choose from to help out with these issues:

  • Use aliases

    • Both for commonly used directories, e.g. alias q='cd /home/durrantm/Dropbox/94_2015/work/code/ruby__rails/ruby/ruby_quiz' and also for common commands. Even alias p=pwd makes life easier when you type pwd a hundred times a day. You'll notice that one letter aliases are a favorite trick of mine.
  • Customize your PS1 prompt (search for PS1 prompt) to help show you where you are. Here's mine: enter image description here Features:

    • shows top 3 and bottom 2 directories (with underscore between when more than 5 levels)
    • does a carriage return so actual prompt is on a new line
    • uses color for the different information
    • show my git branch when I'm in a git project.
    • works on both Ubuntu and OSX (I use both daily)
    • shows date, user and machine

    More at https://unix.stackexchange.com/a/127800/10043

  • Use ctrl-p within vim as indicated and shown by muru

  • Install and use autojump (https://github.com/wting/autojump) to remember your visited command line directories. This may be perfect for you.

  • Command line fuzzy finder may also suit your style - more at https://github.com/junegunn/fzf

  • Use the z-shell which tends to have more built in support and better options such as cdpath (the Z Shell's menu-format directory completion) and the Z Shell's autocd option,

2

If you use vim, consider using the CtrlP plugin. It might take a while to index files at first run on a directory, but after that, it's fast. It matches over the entire path, so as long as you remember some bits of the path accurately, it's quite useful. Here's me looking for files in /usr/share:

enter image description here enter image description here

My /usr/share has over 150000 (178038 regular files according to find) files, so I added let g:ctrlp_max_depth = 10 and let g:ctrlp_max_files = 0 to my .vimrc. Indexing took a few seconds at first run.

muru
  • 72,889