Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Terminal directory navigation with the tab key UNIX
One of my favourite lines in my ~/.tcshrc file is this line:
bindkey "^I" complete-word-fwd
It's been discussed on macosxhints before. What I've just now discovered -- yeah, I'm slow -- is that it gets a little cooler if you have a working shift or right arrow key.

Go somewhere and type 'ls' and hit tab. You'll start cycling through the directory's contents alphabetically. When you hit a folder with stuff in it, hit shift-tab (or the right arrow key). Start hitting tab again, and now you cycle through the contents of the directory that was on the 'ls' line. This also works with other commands, of course. Spiffy, eh?
  • Currently 2.50 / 5
  You rated: 2 / 5 (2 votes cast)

Terminal directory navigation with the tab key | 4 comments | Create New Account
Click here to return to the 'Terminal directory navigation with the tab key' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Spiffiness is in the eye of the beholder
Authored by: el bid on May 13, '02 11:20:53AM
I think I must be misunderstanding this, because I can't see why you would want to reallocate the Tab key like this. Tab is immensely powerful by default. Eg: cd to /Library type cd and then [Tab] and you'll see something like this:
Addresses/ Internet Plug-Ins/ Printers/ Application Support/ Internet Search Sites/ Recent Servers/ Assistants/ KeyBindings/ Screen Savers/ Audio/ Keyboards/ Scripts/ Caches/ Keychains/ Services/ ColorPickers/ Logs/ Snapz Pro X/ ColorSync/ Mail/ SoftwareLicenses/ Colors/ Mesa3/ Sounds/ Contextual Menu Items/ Mozilla/ Spelling/ Documentation/ Not.Mozilla/ Voices/ Favorites/ NoteBook Files/ VueScanX unmirrored/ Fire/ OpenAG/ VueScanX/ FontCollections/ OpenUp/ iApps/ Fonts/ PStill/ iTunes/ Frameworks/ PreferencePanes/ GNUMail/ Preferences/
Do you really want to "cycle round" to VueScanX? Isn't it easier to continue the cd line thus: cd Vu [tab] ... which then completes to cd VueScanX and you just have to hit [Return]. If you wanted "VuescanX unmirrored", instead of [Return] just hit [Space][Tab][Return]. -- el bid

[ Reply to This | # ]
Spiffiness is in the eye of the beholder
Authored by: tiktok on May 14, '02 03:49:52AM

I think there is some confusion. To get to "VuescanX umirrored", you can just type "cd Vu [tab][tab]" instead of "cd Vu [tab][space][tab]"

It works better with more than two directories. I'm going to work off your example. In your example directory listing, you have 3 directories that start with "Color". With the normal tab behavior, if you type "cd Co[tab]", then you only get a listing of the 3 "Color..." directories. And then you have to type a bit more and [tab] to complete the line.

With the new bindkey, you can type "cd Co[tab]" and it will complete the line with 1st possible directory. In your example, it would be "cd Colorpickers". The next time you type tab, it will cycle to the next possible directory, i.e. "cd Colorsync". A third tab will cycle it to "cd Colors". When there are no more possible matches, it will revert back to whatever the line was before all the tabs.

Sorry if this explanation ends up being long and unclear. The easiest thing to do is try it out and get a feel for it. It works best when you are going down multiple directories and don't remember the exact path.

[ Reply to This | # ]
Spiffiness is in the eye of the beholder
Authored by: el bid on May 14, '02 08:00:40AM
I think there is some confusion. To get to "VuescanX umirrored", you can just type "cd Vu [tab][tab]" instead of "cd Vu [tab][space][tab]"

Yes, there was some confusion here on my part -- of course I should have escaped the space in my example above, which introduces one extra keystroke, and strengthens the case for the bindkey reassignment of Tab.

But I'm still agin it. Tab by default has an incredibly useful behaviour which will get over-written.

It may often happen that you've constructed a long command line to which you only need to add the name of the file to be operated on -- except that you can't remember what is was. Tab will show you the whole directory; Z Tab will show you all the files beginning with Z and so on. And what's more, if your file is actually in a subdirectory, called, say, Zarathustra/part1, a second Tab after Zarathustra has completed (and BTW I completed that second Zarathustra just now by hitting Esc in a Cocoa app -- I assume we all know about that one...) will show me the Zarathustra directory contents.

The suggested bindkey reassignment of Tab kills this. Now it happens that there is a standard Emacs key assignment that does pretty well what complete-word-forward does. In Emacs it's called dabbrev-expand, and it's assigned by default to Alt-/, a key combo that isn't assigned to anything under Mac OS X's default shell. As the default bindkey assignment for tcsh is described as "Emacs-style", it seems pretty clear cut to me that a better key to put complete-word-forward on would be Alt/.

So my only question is, How do you represent Alt when doing a tsch bindkey assignment?

el bid

[ Reply to This | # ]
An existing keybinding for TAB
Authored by: digitalee on May 15, '02 02:24:43AM
Thanks for encouraging me to spiff up my tcsh completions!

I agree that assigning alt / for complete-word-fwd seems to be more emacs keybinding compliant but it is rather difficult to get fingers around (that is unless you used DoubleCommand to reassign that useless ENTER key ;).....

However, while pouring through the tcsh man looking for the keybinding for alt I did discover that ^D (think Directory) accomplishes the same as the default TAB behaviour, this solution feels pretty natural to me. Try it on for size.

[ Reply to This | # ]