There are a few ways to accomplish this.
- The simplest solution is to call the function with a single argument, that is enclose the search term inside double quotes. For example
# Instead of
$ ytaudio unity fat rat
# Use
$ ytaudio "unity fat rat"
The problem with this solution is that we have to type quotes to enclose the search term each time we call the function. It might not seem like much, but it is annoying if the function is called a lot of times.
- Enclose
$argv
within quotes inside the function. Change the first line of the function to the line below.
yt-dlp -f 251 -x ytsearch:"$argv" -o /tmp/yt-audio.opus
- Use
string collect
of fish. Replace the first line of the function with the lines below.
set search (echo $argv | string collect)
yt-dlp -f 251 -x ytsearch:$search -o /tmp/yt-audio.opus
- Using
string join
of fish (thanks to @glennjackman). Fish has an easy and awesome way to concatenate strings. Replace the first line of the function with the two lines below.
set search (echo $argv | string join " ")
yt-dlp -f 251 -x ytsearch:$search -o /tmp/yt-audio.opus
string join " "
means to join strings with a space character.
In the second, third and fourth solution, the function can be called without quotes for the search term
ytaudio unity fat rat