12

In zsh, when I press tab 2 times to enter the "completion menu", select a directory and press enter, it first adds the chosen directory with a trailing slash to the command, but as soon as I press space to add more arguments, it removes it.

i.e. "rsync foo/" gets changed to "rsync foo " after pressing space.

Is there a way to disable this behaviour?

It forces me to always add slashes manually for commands like rsync in particular.

2
  • 5
    Just type the /. Or use unsetopt AUTO_REMOVE_SLASH. Oct 8, 2014 at 12:14
  • 1
    This was interfering with autocd. I would type ~/conf/config<ENTER>, then i3s<TAB><ENTER>. It acted like it was about to cd to i3status/, then removed the slash and ran i3status instead!
    – Mikel
    Apr 25, 2020 at 18:22

1 Answer 1

18

To retain the / added after completing directories or symbolic links to directories, turn off the option auto_remove_slash which is on by default.

setopt no_auto_remove_slash

For many commands, retaining the trailing slash makes no difference for directories, but causes the command to act on the target directory instead of the symbolic link if the argument is a symbolic link to a directory. For an rsync source argument, a trailing slash causes the directory to be merged into the destination rather than copied to a subdirectory.

3
  • This works great for local paths, but for me it doesn’t affect remote paths like example.com:some/dir/. Any idea? Nov 20, 2017 at 8:23
  • This doesn't seem to work on 5.7.1, if I hit a TAB after a glob, for example, like cp files/*/*19<TAB> where the file structure is such that only one folder (and no file) two levels down from files ends in 19. So I want that the glob complete directly to that folder, add a slash, and then let me type the name of a file in that folder. Is that possible?
    – sameers
    Jul 20, 2020 at 19:13
  • 1
    @sameers That works for me. Not with the same version, but that's probably not the issue. There are a lot of ways to customize completion and I don't know what settings would affect this. Jul 20, 2020 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.