3 ms·
My shell-fu isn't the greatest. I thought I could be clever and do >alias rip="curl -G -H 'Accept: text/plain' \ --url https://dontbeevil.rip/search --
by wodenokoto 5y ago
My shell-fu isn't the greatest. I thought I could be clever and do
>alias rip="curl -G -H 'Accept: text/plain' \
--url https://dontbeevil.rip/search --data-urlencode q="
>rip hello
{"message": "Missing required request parameters: [q]"}
curl: (6) Could not resolve host: hello
- harryvederci 5y agoYou could also put a shell script on your `PATH` instead of creating an alias: #! /bin/sh query_string="q=$@" curl --get \ --header 'Accept: text/plain' \ --url https://dontbeevil.rip/search \ --data-urlencode "${query_string}"
- mrlemke 5y agoI'd do it almost the same but without the variable. Note: the long shebang is for using on Termux, PC users should change it to something like #!/use/bin/env sh. #!/data/data/com.termux/files/use/bin/env sh curl -G -H "Accept: text/plain" \ --url "https://dontbeevil.rip/search" \ --data-urlenconde "q=$*"
- harryvederci 5y agoDidn't know about "$*", thanks! Edit: typo in your version: "urlenconde"
- cudder 5y agoTurn it into a function: rip() { curl -G -H 'Accept: text/plain' \ --url https://dontbeevil.rip/search --data-urlencode "q=$@" } Now `rip hello` works.
- harryvederci 5y agoThis only works with 1-word arguments. You can change $@ to $* to fix that. (I'm acting all wise, but I learned that today as well :) )
- pxeger1 5y agoSwitch to Zsh, where there'll be no difference!
- nameless912 5y agofunction rip() { printf ">>" read query curl -G -H 'Accept: text/plain' --url https://dontbeevil.rip/search --data-urlencode q="$query" } :)