Hacker News new | ask | show | jobs
by capitainenemo 1201 days ago
I was kinda wondering that myself. There's so many terminal based apps to keep track of, I've gotten into the habit of trying to know a core set fairly well (like bash,awk,sed,grep -P etc). For this sort of thing I have a dozen tabs open in w3m already.

  $ alias wiki='f(){ w3m -F "https://en.wikipedia.org/w/index.php?search=${1}&title=Special:Search&ns0=1"; unset -f f; }; f'
  $ wiki pandas
This seemed to work well for me.

A tab to the wikipedia search page bookmarked would work well too and could be used in existing w3m/lynx session.

3 comments

Oh, BTW, this sort of thing works well with any sort of site that degrades gracefully/is not pure JS.

  $ alias crate='f(){ w3m -F "https://lib.rs/search?q=${1}"; unset -f f; }; f'
  $ crate rocket
(lib.rs is a crate index using rust as the server instead of javascript, and has advantage of working well with terminal browsers)
This is the Unix way. You already have the tools and utilities you need, just pipeline them together and make an alias if it’s something you need frequently.
hey, off topic but can you explain or link a post which explains what the benefits of the alias -> function definition are over just defining the function directly? Thanks!
I am puzzled as well, why not define the function and call it wiki?
I'm just used to keeping all my aliases together for easy location with alias command and I like having ones with arguments with the others.

Aside from that, no benefit really that I can think of.

So yes, to be clear to anyone else you can just put:

  wiki(){ w3m -F "https://en.wikipedia.org/w/index.php?search=${1}&title=Special:Search&ns0=1"; }
in your .bashrc - and if you're me you just forget how you defined it and you have to cat it every once in a while :)

Oh, and you might be entertained by this silly alias adapted from an IOCC entry...

  $ cstdin
  printf("Hello World\n");
  Hello World

  alias cstdin='gcc -pedantic -ansi -Wall -o ~/.stdin ~/.stdin.c -lm && ~/.stdin'


  $ cat ~/.stdin.cc
  #include <stdio.h>
  <snip many headers>
  int main(int argc, char **argv)
  {
  #include </dev/tty>
  return 0;
  }
I'm sure it would also make way more sense as a dedicated script. I have a C++ one in there too.
ah I see, cool thanks!