1

In zsh, globbing kicks in when using wildcard characters ? or * like this:

ls file?.txt

However I would like to disable globbing in a case like this:

youtube-dl https://www.youtube.com/watch?v=QIysdjpiLcA

I can work around this by putting the argument in either single or double quotes (' or ").

Can I somehow configure zsh to ignore wildcard characters (i.e. don't do any globbing) when using in patterns such as URLs? Or for certain commands/executables?

1 Answers1

5

If you put noglob in front of a command, no globbing is done.

noglob youtube-dl https://www.youtube.com/watch?v=QIysdjpiLcA

To disable globbing for a particular command, make it an alias.

alias youtube-dl='noglob youtube-dl'

With URLs, this helps with ?, but not with &. There's no way to disable the interpretation of & except quoting.

If you have the URL in the clipboard, instead of pasting it, you can use a command to recall the clipboard content:

youtube-dl "`xsel`"         # X11 automatic mouse selection
youtube-dl "`xclip -o`"     # X11 automatic mouse selection
youtube-dl "`xsel -b`"      # X11 explicitly copied clipboard
youtube-dl "`xclip -o -sc`" # X11 explicitly copied clipboard
youtube-dl "`pbpaste`"      # macOS clipboard

You'll have the pasting command in your shell history, not the URL. If you press Tab at the end of the command line before the end of the command, the command substitution will be expanded to the URL. (The required key may be different depending on your completion settings; see also How can I expand all variables at the command line in Zsh? and Shell that tab-completes prefix?.)

Alternatively, if your terminal supports bracketed paste (good modern ones do), press Ctrl+U (or anything else that sets a numeric argument) before pasting. The URL (or whatever you paste) will be pasted with quotes around it. Note that this includes leading and trailing space that browsers would ignore.