Bash autocomplete

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
dosfan
Member
Member
Posts: 65
Joined: Tue Oct 14, 2008 1:18 pm
Location: Scotland

Bash autocomplete

Post by dosfan »

I am having a bit of trouble getting Bash's autocomplete function to work properly in my OS's port.

I've implemented a non-canonical reading mode in my crappy terminal driver. I had hoped that autocomplete would magically start working. Unfortunately, only to some extent. It completes the command but doesn't show on screen. Triple tab displays directory contents OK.

eg. 'cd /de[tab][enter]' would complete to 'cd /dev' (but not printed at the prompt)

Anything obvious I should be doing? I don't have a termcap file as I don't do any ansi vt emulation stuff. Do I need one?

I'm not familiar with all this termios/termcap voodoo yet.

Cheers.
All your base are belong to us.
Martijn
Posts: 22
Joined: Tue Feb 26, 2008 3:43 am
Location: The Netherlands

Re: Bash autocomplete

Post by Martijn »

The problem is most likely caused by an incorrect value in the 'st_mode' field in the stat structure returned by stat/fstat.
dosfan
Member
Member
Posts: 65
Joined: Tue Oct 14, 2008 1:18 pm
Location: Scotland

Re: Bash autocomplete

Post by dosfan »

My st_mode values seem sane.

Are you thinking along the lines of isatty() ? If not, could you explain your reasoning?




Cheers

EDIT: I should also point out, upon pressing tab it does syscall sys_stat(/dev) in the above example.
All your base are belong to us.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: Bash autocomplete

Post by pcmattman »

Do you know if it's trying to write characters to the terminal? If not, do you know why?
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Bash autocomplete

Post by JamesM »

Try "ls /de[TAB]". I know you probably don't have ls installed - it doesn't matter. When using the cd builtin, bash checks the st_mode field of the stat structure to check that path is a directory. It doesn't do this for non-builtin applications.
Martijn
Posts: 22
Joined: Tue Feb 26, 2008 3:43 am
Location: The Netherlands

Re: Bash autocomplete

Post by Martijn »

dosfan wrote:My st_mode values seem sane.

Are you thinking along the lines of isatty() ? If not, could you explain your reasoning?

Cheers

EDIT: I should also point out, upon pressing tab it does syscall sys_stat(/dev) in the above example.
I have to correct myself here. The st_mode field does not appear to have any effect on auto-completion. Sorry for spreading confusion! ;)

Most of my input/output problems were termios related. You can get by this by providing a simple tcgetattr/tcsetattr implementation. Setup a global 'struct termios' with some default values and flags set (canonical mode etc). Make tcgetattr return this struct, and make tcsetattr overwrite this struct. Hope this solves your problem.
Post Reply