Strange tab-completion behavior with zsh in screen

I'm running Mac OS, using the latest version of zsh.

I've noticed that I have funny tab-completion behavior when inside a screen session.

Specifically, once I press tab, the first part of my command seems to be duplicated before the completion results are inserted.

For example, if I type

cd ~<TAB>

the contents of my command line will be replaced with

cd ~cd ~/  

Strangely, this superfluous stuff doesn't affect the command: the interpreter still reads the command as

cd ~/

but it can be confusing at times, and it's certainly annoying to have my computer doing something I didn't intentionally program and cannot figure out.

Any ideas what's up?

Let me know if anybody wants to see any of my rc files.

Thanks all.

Perhaps your TERM variable does not match what is running, so the command line edit features are displaying a mess?

1 Like
echo $TERM

returns "xterm-color", which is I believe declared by a setting in the preferences of my Terminal.app.

The same command within a screen session returns "screen".

have you resized your window by any chance?
If so, you might want to run 'resize' from the shell. I don't know where 'resize' lives under MacOS, but on Solaris it's under /usr/openwin/bin directory.

1 Like

I ran "locate resize" and it seems the only resize on my computer is part of xterm.

What exactly does it do?

By the way, I noticed that the behavior doesn't occur for every tab-completion request: only when the zsh list of possible matches comes up does this occur.

In cases where there is only one possible match and it doesn't display a list to the user, the command line is unchanged.

Thus I can type

cd ~<TAB>

and it properly autocompletes "~" to /Users/myusername/, with no doubling. If I press tab again (which returns a list of the contents of ~/), the problem occurs.

cd~/<TAB>

will cause doubling without having to press tab a second time.

here's the man resize, but I'm not sure if there's one fo MacOS...

1 Like

Well, if the screen does not support the control characters defined for xterm-color or screen, the $TERM can create such anomalies. Try other export TERM=model, like xterm-color for screen and vice-versa, or something simpler like vt100, XTERM. I am assuming zsh does something sane on the proper term type. I am not a zsh user yet.

1 Like

OK, well I tried running

export TERM=xterm-color

I also tried xterm and vt100.

I even tried, when testing TERM=vt100 in screen, configuring terminal.app to strictly emulate vt100, by declaring the terminal as vt100 and selected the "strict vt100 keypad behavior" option.

None of this had any affect on the problem. Unless I would have to do something more than simply export TERM=blah within a screen session.

Hi.

I'd guess that it may have to do with your zsh prompt string, or (less cheerfully) the complex completion system of zsh.

What does your prompt string look like? I have not done much with mine, so it looks like:

leap% ps | grep $$
30801 pts/0    00:00:00 zsh
leap% echo $PROMPT
%m%# 

but when I enter cd ~<TAB> it prints the strings to which ~ might expand (in columns) and returns the cursor to after the ~

However, I am not using screen ... cheers, drl

1 Like

My prompt is fairly complex:

[mylongusername@Marshalls-MacBook-Pro:~]
[ :( ] $ echo $PROMPT                                                                         (11-20 15:31)
[%{%}%n%{%}@%{%}%U%m%u%{%}:%{%}%2c%{%}]
[ %(?,%{%}:%)%{%},%{%}:(%{%}) ] %(!.#.$) 

drl, I believe you have it figured out.

If I start a screen session, and then run export PROMPT=% in order to give myself a blank prompt, the problem is resolved!

So, any ideas what I might do, other than living with it (now that I at least know what's causing it), or using a simple prompt within screen? Is there any way to configure screen, like say, what the prompt variable is?

Hi.

Use half of the current prompt -- as much as makes sense. If it works, add half of the part left out, if it doesn't work, cut the half in half, repeat until solved.

Or, you could start with an emptyish prompt, and add a bit each time.

Good luck, keep us posted ... cheers, drl

To be honest, I can't figure out how to change the default prompt in screen.

I've been looking at screenrc files via google for a couple hours now, but I haven't found anything.

I just noticed that this problem also occurs when using su.

su has a prompt? I think su just drops you into the target user's default shell.

It seems to behave like screen does, up to and including giving me my weird problem. I never could figure out how or if screen will set its own prompt.

It seems like it has something to do with trying to create my user environment twice, as both screen and su try to replicate my user environment when I run them.