cmdfu(){ wget -qO - "http://www.commandlinefu.com/commands/matching/$@/$(echo -n "$@" | openssl base64)/plaintext"; }
It's like man but for one-liners. cmdfu(){ wget -qO - "http://www.commandlinefu.com/commands/matching/$@/$(echo -n "$@" | openssl base64)/plaintext"; }
It's like man but for one-liners. [URL]/matching/ssh/c3No - Search results for the query
'ssh' (note that the final segment is a base64-encoding
of the search query)
So it's passing the command args through 'openssl base64' to encode them as required by the api. $ echo -n ssh | openssl base64
c3No
It's not immediately clear to me why they require both - base64 encoding might be useful to allow non-printable/special-purpose chars in the URL, but we already have a perfectly good URL-encoding scheme for that.And requiring both (it doesn't seem to work with only one) is just silly.
There is a Django-rewrite of commandlinefu on the way including a saner API.
$ echo 'test' | openssl base64
dGVzdAo=
Which is the same as: $ echo 'test' | base64
dGVzdAo=
The URL is the same as: args="$@"
b64=$(echo -n "$@" | openssl base64)
url="http://www.commandlinefu.com/commands/matching/$args/$b64/plaintext"
For these purposes though, "$@" could probably be replaced with "$*". Technically the URL is invalid since "$@" could introduce non-escaped spaces into the URL.$(<command>) gets replaced by the output of <command>, in our case that means the output of the openssl base64 call, which takes stdin, applies the base64 encoding and prints it out on stdout. echo -n $@ just serves to translate our parameters into something the openssl base64 call can work with (-n means it won't introduce a superfluous newline). I'm not sure why the script uses openssl base64 instead of just base64 (a GNU coreutils utility).
I agree with the sibling that the API requirement to include both verbatim and base64-encoded search terms are fairly bizarre.