TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Better HN search with bash

1 pointsby eknsabout 10 years ago
The interface for Algolia search is horrible for picking date ranges so I made this little bash function to fix it (noting that &quot;open&quot; is an alias to &quot;xdg-open&quot; for me on Linux).<p>Might work in other shells too.<p><pre><code> function hn() { if test $# -lt 1 || test $# -gt 3; then echo &quot;Usage: $0 &lt;query&gt; [start=1970] [end=now]&quot; echo &quot;start and end are ISO dates like 2014-03-23.&quot; return 1 fi query=$1 start=$(test $# -gt 1 &amp;&amp; date --date &quot;$2&quot; +%s || date --date @0 +%s) end=$(test $# -gt 2 &amp;&amp; date --date &quot;$3&quot; +%s || date +%s) url=&quot;https:&#x2F;&#x2F;hn.algolia.com&#x2F;?sort=byPopularity&amp;prefix=false&amp;page=0&amp;type=story&amp;query=${query}&amp;dateRange=custom&amp;dateStart=${start}&amp;dateEnd=${end}&quot; echo $url open &quot;$url&quot; }</code></pre>

1 comment

redox_about 10 years ago
Indeed, we never took the time to plug a date parser. Any chance you&#x27;ve time for a pull-request? <a href="https://github.com/algolia/hn-search/blob/master/app/assets/javascripts/controllers.js#L26" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;algolia&#x2F;hn-search&#x2F;blob&#x2F;master&#x2F;app&#x2F;assets&#x2F;...</a> and <a href="https://github.com/algolia/hn-search/blob/master/app/controllers/api/v1/base_controller.rb#L7" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;algolia&#x2F;hn-search&#x2F;blob&#x2F;master&#x2F;app&#x2F;control...</a> :)<p>That would be cool!