Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Terminal Based Wikipedia (github.com/yashsinghcodes)
165 points by 0xfafafa on March 12, 2023 | hide | past | favorite | 39 comments



Why do the screenshots show some sort of syntax highlighting applied to the article text?


The images were generated by carbon and it's auto syntax selection must have defined the whole thing to be shell code. I'll fix it in next commit. Thanks pointing it out.


Its actually kinda neat...


Looks like syntax highlighting from the shell. (Text between quotation marks being highlighted, numbers and key words like "for", "and", "in", "create", "as", "or".)


    cat /bin/wik
    #!/bin/sh
    lynx https://en.wikipedia.org/w/index.php?search=$1


Also `elinks` and `w3m`.

The mobile site, https://en.m.wikipedia.org/ , looks a little better in them.


Nice, here's mine

    cat `which ddg`
    #!/usr/bin/env sh
    w3m 'https://duckduckgo.com/?q='`echo $@ | sed 's/ /\+/g'`


The execution is really nice!

But,there are already browsers and web guidelines to make this possible without specific single purpose apps.

Why would I use this over for example, Lynx?


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.


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!


I have never used Lynx personally, but just going through the description of it i would say that wik also provide quick introduction lookup to a desired topic. Initially i made this as a personal tool just for this quick introduction lookup feature as i don't wanted to hustle through a browser for a just introduction search on the topic. But when made i made this project public i added full info and search.



Needs a pager, otherwise looks great!


But please don't build a custom pager, but use $PAGER (unless this is supposed to turn into a full browser ...) so it works as expected (key bindings etc )


Indeed and it would be so much better to use termcap (eg through ncurses) instead of blasting ANSI codes without checking :) some of us still use terminals


Looks nice but a few things are a bit confusing:

1. I'm not sure what's the difference between -i and -s, they seem to work the same for a few examples I tried

2. It renders every paragraph in a different color, which seems... unnecessary

3. There's a [-] at the beginning of every paragraph which I'm not sure what it is for (seems to suggest that it is to fold the paragraph but I don't really see how to actually fold it).


Thank you for adding the screenshots. Looks good.


In Emacs this can be done with emacs-w3m or eww.


Everything can be done in emacs.


Obviously, just use Alt-X butterfly ...


Seems like programmers like the terminal aesthetic.

The only real improvement is speed at the cost of memorizing a new key stroke interface for every app. Every other aspect of terminal interfaces is a downgrade. The cost of memorization is also a huge burden

I feel there's got to be a better way that gets the best of both worlds.


Sounds good.. although this comes to mind: https://xkcd.com/927/ (How standards proliferate)

Even if you found a better way, the world might just end up with yet another set of keystrokes to memorize.


>beautifulsoup

Really? Seriously? No better way to query the source of a page and render it on the terminal?



Wow.

Much worse than I thought.

If only if mediawiki (php) never happened. Wikipedia was sane at one point.


cool!

Is this scraping the HTML pages, or fetching the wikitext through the API and rendering it?



Is there any plan for navigating sections or fetching specific data from the article? For example, a command to print Demographics or Population Density for a specific country.


Looks good. Access to the revision history for each page would be a nice feature that might work well in the terminal.


This is neat! Very useful to be able to pipe stdout to other tools like command-line summarization via LLMs.


Does this work on all major platforms including Windows Terminal?


Does it show footnoted references?


Is there an infobox display?


Nice one, thank you!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: