Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autocomplete in Unix Shell 3

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi!

Does anyone know if unix have an autocomplete feature?
The user is asked to input something and the word auto completes? Like the script will look at an existing file for reference?

TY!
Jared
 
You do have an option to autocomplete by typing the escape key in csh or tab in bash/tcsh. If your looking to have it go automatically then I don't know off hand. You would probably have to write your own program in C to do this. Also you have to catch all typed characters once the autocomplete feature begins to prevent adding extra, and probably wrong, characters. You also have to deal with partial completions when the program can't disambiguate between choices with the same root of characters. If anyone has something like this I would also be very interested.

Cheers,
ND [smile]
 
I would have tended to agree with bulldog on this ... but I've just tried it in ksh. ksh filename autocomplete appears to work when used inside a read command. In ksh, autocomplete is triggered by Esc-\ sequence.

Maybe not exactly what you want, but probably the best you can get without writing something specific yourself.

Greg.
 
To enable what they others have said, make sure you have the line
Code:
set -o vi
in your .profile or .login scripts. Then you can enjoy the vi editor commands (and more) right from the command prompt.

To envoke the editor, simply hit the ESC key. Just like going from input mode to command mode inside of vi. Some of the more useful key strokes:

ESC+\ = autocomplete, will complete upto the non-unique character.
ESC+* = space delimited list of all files that match the pattern you started with.
ESC+/str = search the commandline history for str.
ESC+n = search for the next occurance of str.
ESC+k = go back one in the commandline history.
ESC+j = go forward one in the commandline history.
ESC+$ = go to the end of the current line
ESC+0 = go to the beginning of the current line
ESC+i = return to insert mode
ESC+A = append to the end of the current line
ESC+I = insert from the beginning of the current line
ESC+fx = move cursor to the right until the next occurance of x
ESC+Fx = move cursor to the left until the next occurance of x
ESC+x = delete character under cursor and place it in the buffer
ESC+p = place the contents of the buffer after the cursor
(combining the last two keystrokes)
ESC+xp = transpose two characters (I use this alot)

Good luck, and keep trying diferent combinations, it is amazing the power of the Unix command line.
Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top