Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you automatically escape special characters in a string that is pasted into terminal?

I have the CLI utility "youtube-dl" installed. It takes a urls as arguments. It is most natural to paste these urls from the system clipboard. Using zsh, however, this returns an error "no matches found" because the special characters in youtube urls are not escaped.

I need to go from this:

https://www.youtube.com/watch?v=ShxHGFs2IKE

to this:

https\:\/\/www\.youtube\.com\/watch\?v=ShxHGFs2IKE

It is quite a pain to manually escape all the characters every time, so my question is: how can I make this work without all the manual editing of urls each time?

like image 990
Joel Strouts Avatar asked Sep 05 '25 18:09

Joel Strouts


1 Answers

As said in the comments, try using quotes:

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

Or you can load zsh url-quote-magic to get special shell characters to be quoted automatically in URLs:

autoload -Uz url-quote-magic
zle -N self-insert url-quote-magic
like image 160
MauricioRobayo Avatar answered Sep 09 '25 02:09

MauricioRobayo