David Shields
David Shields

Reputation: 11

Zsh ls tab completion on symlink does not follow the symlink

I have a folder in the home directory: hdd -> /hdd.

ls -l hdd outputs hdd -> /hdd. I expected it to follow the symlink and show the contents of /hdd, but that's not the main point.

ls -l hdd/ outputs the contents of /hdd, as expected.

ls -l hd followed by a tab completion which then shows ls -l hdd/, then hitting ENTER will run the command ls -l hdd, NOT ls -l hdd/. Thus, it shows hdd -> /hdd, rather than the contents of /hdd.

Why is ls -l hdd the command being run when it tab completes ls -l hdd/? Which is generally the preferred behavior? If I manually typed ls -l hdd/ without using any completion, it will of course show the contents of /hdd.

Upvotes: 1

Views: 413

Answers (1)

Adaephon
Adaephon

Reputation: 18349

This is due to the option AUTO_REMOVE_SLASH, which is by default enabled:

AUTO_REMOVE_SLASH
When the last character resulting from a completion is a slash and the next character typed is a word delimiter, a slash, or a character that ends a command (such as a semicolon or an ampersand), remove the slash.

You can disable it with

setop noautoremoveslash

You can also can configure zle to highlight slashes (and - depending on configuration - other suffices) which it would remove automatically. For example make it pink and bold:

zle_highlight[(r)suffix:*]="suffix:fg=magenta,bold"

Note: This might not work in conjunction with the external zsh-syntax-highlighting plugin.

Upvotes: 1

Related Questions