1

My goal is to type client air tab and complete the list of clients i have within my ~/clients directory.

Since hopefully my client list will grow i don't want to hardcode alias commands anymore but use client that will handle the cd /Users/pjammer/clients part and then use zsh to miraculously display essentially the ls of that directory, allowing me to autocomplete a directory name within the directory and go right there.

Thoughts?

pjammer
  • 9,489
  • 5
  • 46
  • 56
  • 1
    I don't post an answer because that would be pure publicity, but I developed a plugin that might achieved far you are looking for. have a look https://github.com/AdrieanKhisbe/diractions, it as some in context completion `aliasdir subpath ` – AdrieanKhisbe Mar 31 '15 at 14:35
  • If you don't post the answer i will scoop the million upvotes! let the stack overflow tifosi do what they will with it but i'll select it. thanks bro. Did you make the plugin because it zsh itself does it weird, or didn't do such things easily? – pjammer Mar 31 '15 at 14:41
  • I made a longer answer then. I made it for bash first, but adapt it to zsh when I made the jump. It's just lately I had the completion support for the subdir, but it's been a huge time saver. :). (I still need to improved the contextual completion of command, but that's another story) – AdrieanKhisbe Mar 31 '15 at 14:50

2 Answers2

2

Warning, this is [kindof] publicity

I developed a plugin that might achieved far you are looking for.

The main concept is the one of diraction, a powered directory bookmark. It's an alias that enable you to jump in the attached dir, or to perform some operation in its context.

Have a look github.com/AdrieanKhisbe/diractions, it as some in context completion aliasdir subpath <tab>

It started as a shell function, and then outgrow to a plugin that got completion at some point. For free you have also an environment variable to refer the directory anywhere in the command, and a command suite, and configuration system to set up your bookmarks.

AdrieanKhisbe
  • 3,899
  • 8
  • 37
  • 45
0

For navigational needs like this, I use a simple but perhaps more generalized solution: I setup an alias utilizing a fuzzy selection tool (e.g. pick: https://github.com/thoughtbot/pick, but there are numerous others -- fzf, c.f: http://junegunn.kr/2014/04/fzf+vim+tmux/).

The neat trick is to pass the contents of find to the fuzzy selector tool, for example:

cd $(find ~/path/to/clients/ -maxdepth 1 -type d | pick )

Then, you can alias that in your .rc (I like to use 2 mnemonic for these kinds of aliases):

2cli='cd $(find ~/path/toclients/ -maxdepth 1-type d | pick) 

Typing '2cli' will cd you to the client of you choice from any starting location.

This approach has changed my core navigation in shells. It effectively generalizes the popular vim plugin Command-T for the shell. For instance, when working in git, I use the following alias to change branches:

alias gb='git checkout $(git branch -a | pick)'

Another example is to open and edit some src file which you don't quite recall its name that is somewhere in deep nest of directories but again where you don't quite remember:

alias pf="find . \( ! -regex '.*/\..*' \) -type f | pick "
vim $(pf) 

Here, the pf alias ('pick file') quickly builds a collection of files in the directory where the cmd is invoked, excluding hidden directories, and lets you fuzzy select a filename to be sent to stdout. Using this alias in conjunction with an editor like vim, allows you find and open a file you've selected with just one alias -- this combines the command act of finding, cd'ing, and opening a file in one fell swoop.

To be clear, there is nothing new here--fuzzy selection tools are popular and there numerous implementations of them (in Go, Haskell, python, ruby, etc.), each with their own dis/ad-vantages. I am merely passing on my workflow/movement aliases which I believe solve your particular need as well provide a generalize-able approach.

gregory
  • 10,969
  • 2
  • 30
  • 42