hnarayanan / shpotify

A command-line interface to Spotify.
https://harishnarayanan.org/projects/
2.01k stars 153 forks source link

apostrophes cause an error #71

Closed incandescentman closed 7 years ago

incandescentman commented 7 years ago

shpotify is brilliant! Amazing work. Question:

$ spotify play wouldnt it be nice works, but if I use an apostrophe and do $ spotify play wouldn't it be nice it puts me in some kind of process that gives me a > and won't accept commands.

hnarayanan commented 7 years ago

This is a shell thing, and not super easy to work around. Could you try

$ spotify play "wouldn't it be nice"

and see if that does what you want?

dmofot commented 7 years ago

This will probably be shell specific (in my case bash), but here's what's working for me:

No Apostrophe / No Quotes

$ spotify play wouldnt it be nice
Searching tracks for: wouldnt it be nice
Playing (wouldnt it be nice Search) -> Spotify URI: spotify:track:2Gy7qnDwt8Z3MNxqat4CsK

Apostrophe / Quotes

$ spotify play "wouldn't it be nice"
Searching tracks for: wouldn't it be nice
Playing (wouldn't it be nice Search) -> Spotify URI: spotify:track:2Gy7qnDwt8Z3MNxqat4CsK

Apostrophe / No Quotes

$ spotify play wouldn't it be nice
→ '
Searching tracks for: wouldnt it be nice
Playing (wouldnt it be nice Search) -> Spotify URI: spotify:track:2Gy7qnDwt8Z3MNxqat4CsK

The last one works by using another apostrophe. You just need to close the apostrophe since the shell thinks it's a single quote. You can use as many apostrophes as you need as long as there is an even number. So this works (' * 8):

$ spotify play wouldn't it be nice'''''''
Searching tracks for: wouldnt it be nice
Playing (wouldnt it be nice Search) -> Spotify URI: spotify:track:2Gy7qnDwt8Z3MNxqat4CsK

but this doesn't (' * 7):

$ spotify play wouldn't it be nice''''''
→ '
Searching tracks for: wouldnt it be nice
Playing (wouldnt it be nice Search) -> Spotify URI: spotify:track:2Gy7qnDwt8Z3MNxqat4CsK

Solution

The solution is to escape single quotes like this:

$ spotify play wouldn\'t it be nice
Searching tracks for: wouldn't it be nice
Playing (wouldn't it be nice Search) -> Spotify URI: spotify:track:2Gy7qnDwt8Z3MNxqat4CsK

Within shpotify, it's probably possible to escape inputs. Here's how that would be done in the shell:

$ inputvar="wouldn't it be nice"
$ output="${input//"'"/"\'"}"
$ echo $output
wouldn\'t it be nice
incandescentman commented 7 years ago

OK great, using quotation marks works, as does omitting the apostrophe! (Those are both much more intuitive than closing the single quote.) Thanks!