How to Use the `hn` Command-Line Interface for Hacker News (with Examples)

How to Use the `hn` Command-Line Interface for Hacker News (with Examples)

The hn command is a powerful command-line interface tool designed to provide users with easy access to Hacker News directly from their terminal. It serves as an efficient alternative to browsing Hacker News through a web browser. With this tool, you can effortlessly view stories, keep a list open after selecting a link, and sort stories by submission date, all while remaining in the comfort of your command-line environment. This CLI tool is particularly useful for developers, journalists, and technology enthusiasts who frequently check Hacker News and appreciate the simplicity of terminal-based interfaces.

Use Case 1: Viewing Stories on Hacker News

Code:

hn

Motivation: Many users frequently visit Hacker News to catch up on the trending topics, news articles, and discussions from the tech world. By using the hn command, users can seamlessly access the top stories without the need to open a browser window. This method saves both time and resources, especially for those who work in an environment where using a graphical user interface is not ideal.

Explanation: The command hn is executed without any additional arguments. Here, the tool utilizes its default functionality to fetch and display a list of the top stories on Hacker News. The results are presented in a simple, readable format directly in the terminal.

Example Output:

1. Show HN: Game Hacking Book... (https://bookhacking.com/blog)
2. Ask HN: What are the best tips for debugging code? (https://news.ycombinator.com/item?id=1323)
3. Launch HN: ChatGPT-Plugin for Python (https://chatgptplugin.com)
...

Use Case 2: Viewing a Specific Number of Stories on Hacker News

Code:

hn --limit 10

Motivation: There are circumstances where users may be interested in just a handful of the top stories, either due to time constraints or a need to focus on specific current trends without being overwhelmed by information. This use case allows users to specify the exact number of stories they want to view, providing a concise glimpse of the most relevant news.

Explanation: The argument --limit is used here to define the number of stories that should be displayed. By specifying a number after --limit, users instruct the tool to return only that specified quantity of top stories from Hacker News. In this example, the user wants to see only the top 10 stories.

Example Output:

1. Show HN: Python libraries for data science (https://pylibrary.com)
2. Ask HN: Most challenging project you worked on? (https://news.ycombinator.com/item?id=456)
3. Story: Apple's new ARM chips (https://techsite.com/apple-arm)
...

Code:

hn --keep-open

Motivation: A common irritation when reading through multiple stories is the need to repeatedly fetch the story list after selecting and viewing an individual story. The --keep-open flag offers a simple solution by keeping the list in the terminal open even after a story link has been selected, allowing for seamless navigation without repetitive task execution.

Explanation: The --keep-open flag modifies the default behavior of the hn command. By using this argument, users are able to keep the story list displayed in the terminal even after interactions, making it easier to explore multiple articles or topics without re-fetching the list each time.

Example Output:

1. Ask HN: How to improve JavaScript skills? (https://news.ycombinator.com/item?id=789)
2. Story: A new era for quantum computing (https://quantumnews.com/era)
3. Comment: Rust performance vs Go (https://news.ycombinator.com/item?id=1011)
...
[Selected link opens in a new browser tab, list remains visible in terminal]

Use Case 4: Viewing Stories Sorted by Submission Date

Code:

hn --latest

Motivation: For users who want to keep up with the very latest news and discussions, sorted lists based on submission date are crucial. Tech enthusiasts and journalists often use this functionality to stay updated on brand new developments in the technology sector as they emerge, providing a constant and immediate flow of fresh information.

Explanation: The --latest flag instructs the hn command to sort and display the available stories based on their submission date, with the newest submissions appearing first in the list. This enables users to view stories in chronological order, starting with the most recent ones.

Example Output:

1. Story: Recent updates in web security (https://securityblog.com/updates) - 20 minutes ago
2. Comment: Blockchain innovations in 2023 (https://news.ycombinator.com/item?id=1234) - 45 minutes ago
3. Ask HN: Best machine learning tools? (https://news.ycombinator.com/item?id=5678) - 1 hour ago
...

Conclusion:

The hn command-line interface offers a versatile and efficient way to access Hacker News stories directly from the terminal. Whether you’re checking the top stories, focusing on a specific number, keeping the list open for convenience, or seeking the freshest content sorted by submission date, the hn tool is a valuable resource. It simplifies navigation and enhances productivity for those who prefer working within a terminal environment, eliminating the need for unnecessary clicks and browser windows. For individuals who value streamlined access to the latest in tech news, the hn CLI is an indispensable tool.

Related Posts

How to Use the Command 'zstd' (with Examples)

How to Use the Command 'zstd' (with Examples)

Zstandard, or zstd, is a fast lossless compression algorithm that provides high compression ratios.

Read More
How to Use the Command 'ffuf' (with Examples)

How to Use the Command 'ffuf' (with Examples)

ffuf is a powerful and fast web fuzzer written in Go, designed to help penetration testers and security researchers discover hidden directories, files, and vulnerabilities on web servers.

Read More
How to use the command 'pdfunite' (with examples)

How to use the command 'pdfunite' (with examples)

pdfunite is a utility tool for merging multiple PDF files into a single PDF document.

Read More