Google Search command

Asked Feb 26, 2021·8 replies·Last activity 5 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

so I've added added a google command, but it bugs me that every time I attempt to search for something that requires a space to separate between words, the link gets created with only the first word that was added. SO, unless you know to copy the beginning of the https all through the end of what you type, you won't get the correct answer. I've tried quite a few replacements but don't work but essentially, I want to replace a space for %20 and I keep getting "Unexpected end of input". Here is some examples of what I've tried:

$(eval https://www.google.com/search?q=$(query).replace(' ',/%/2/0))

$(eval https://www.google.com/search?q=$(query).replace(' ',"%20"))

$(eval https://www.google.com/search?q=$(query).replace(' ',"%20"))

$(eval https://www.google.com/search?q=$(querystring).replace(' ',"%20"))

$(eval https://www.google.com/search?q=$(querystring).replace(' ',+))

$(eval https://www.google.com/search?q=$(query).replace(' ',%20))

... and single quotes replaced with double quotes, etc, etc, etc. What am I missing?

8 replies

Have you considered using $(querystring) ?

I tried, as you can see above, and didn't work either.

I feel like what I'm missing is not difficult but I've also tried so many options that I feel the syntax is incorrect. I just don't understand where to fix it.

Hey @Quiet Flamingo!

If you look at a Google's search URL, you'll notice that spaces are +.
I made a !google command a while ago, here's the code:

$(eval q=`$(query)`.replace(` `,`+`);`https://www.google.com/search?q=`+q;)

Wait, I did try replacing with a + sign as well. Can you please explain why yours works and mine doesn't?

YOURS

Polar Cat said:
$(eval q=$(query).replace( ,+);https://www.google.com/search?q=`+q;)`

MINE

Quiet Flamingo said:
$(eval (https://www.google.com/search?q=$(querystring).replace)(’ ',+))

Querystring converts spaces into %20 first, so they wont get replaced by +

and what about the format? What is so different between how you coded it vs. how I coded it?

There's not much difference between your code and mine, I just use the right tools:

I used $(query) so the spaces don't get encoded, so I replace them with +.
If I used $(querystring), the spaces are encoded to %20 so I need to replace the encoded characters with +.

After than I simply added a step where I create a variable q, which I could have bypassed, it's just an habit.

So I could have written the code like this:

$(eval `https://www.google.com/search?q=$(query)`.replace(` `,`+`))
$(eval `https://www.google.com/search?q=$(querystring)`.replace(`%20`,`+`))

Didn't find your answer? The community is on Discord.

Ask on Discord