Command Line Habr

This is a weekend post about how to make a command line version of Habr.



image



If you are a fan of minimalism and the command line, then welcome to cat.



The idea for creating a command line version of Habr was inspired by comments on the article about optimizing articles with a lot of comments.



And what could be minimal than the command line? This is how a script was born to turn the desktop version of Habr into a kind of terminal with command management.



DISCLAIMER: I want to warn you right away that I am not js-ninja and javascript is not my main development language, so do not judge strictly because of the non-optimal use of language constructs.



Also, this project was created as MVP, PoC, JfF and etc. and the goal was not to implement the entire possible range of functionality provided by Habr.



The open-source JqueryTerminal library was used as a terminal controlby Jakub T. Jankiewicz licensed from MIT.



This library implements a very wide range of possibilities, and if your project needs such a function, I recommend paying close attention to this project, most likely all your needs have already been implemented and you will not need to uncover a sledgehammer and a file.



The script provides a minimal set of commands:



image



ls - view the list of articles.



For example:



image



cd - change the current directory



List of supported directories:



image



pwd - display the path of the current directory



whoami - the name of the current user



more - display the text version of the article



For example:



image



open- open the article in a new browser window



Unfortunately (or fortunately), due to the restrictions imposed by the browser to ensure the safety of the user, it is impossible to make a demonstration without preliminary steps from the user.



In order to try the script yourself, you need to:



1. Open the source code of the script and copy it to the clipboard (Ctrl-a / Ctrl-c)



2. Open Habr (I will repeat once again that this script works only for the desktop version of the site)



3 On the Habr page, open the developer tools (Ctrl-Shift-I for Chrome) and paste the script from the clipboard into the console command line and press Enter. The script will automatically load the required libraries and start execution.



If everything is done correctly, in the window where you have opened Habr, you will see something similar:



image



There is still an option to configure loading from GreaseMonkey, but this extension is used by a fairly limited number of users and, if necessary, they can figure it out on their own.



For entomological interest, the source code can be viewed in the repository .



Enjoy.



All Articles