1

I have a custom script that I pass an argument into that will create a directory in a specific folder and then cd to it, unless it already exists, then it just cd to it.

I added a zsh autocompletion that way if I want to use the command to just jump to a directory in that folder I can autocomplete the target folder and get there in less keystrokes. The only issue with my zsh autocomplete is that it leaves the tailing directory slash after the autocomplete. Is there any way to tell zsh to only return the name of the directory and leave the / off? The docs are long winded and my searching has not turned up anything useful.

Here is my zsh autocomplete

compdef '_path_files -W /home/me/dir1/dir2/folder -/ && return 0 || return 1' mycommand

  • 1
    Maybe try `setopt autoremoveslash`, if it's not already set? That will remove the slash if you type a space or a separator character after it. – yut23 Jul 08 '22 at 01:01
  • thanks for the reply. yes, it is set by default actually. I found out mkdir does not accept a / as part of the directory name so it drops it anyways and my completion works as intended. – Stephen Redding Jul 08 '22 at 02:15

0 Answers0