<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Gomez - Tech Notes</title>
    <link>https://gomez.wtf/post/bash/</link>
    <description>Recent content on Gomez - Tech Notes</description>
    <language>en-us</language>
    <lastBuildDate>Fri, 24 Oct 2025 00:05:11 -0700</lastBuildDate>
    <atom:link href="https://gomez.wtf/post/bash/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Hackernews comment to AI summary</title>
      <link>https://gomez.wtf/posts/hackernews-comments-to-ai-summary/</link>
      <pubDate>Fri, 24 Oct 2025 00:05:11 -0700</pubDate>
      <guid>https://gomez.wtf/posts/hackernews-comments-to-ai-summary/</guid>
      <description>&lt;p&gt;A recurring theme is that I have a lot of terminal helper scripts for shortcuts.&lt;/p&gt;
&lt;p&gt;Inspired by and modified from &lt;a href=&#34;https://til.simonwillison.net/llms/claude-hacker-news-themes&#34;&gt;Summarizing Hacker News discussion themes with Claude and LLM&lt;/a&gt;. I modified the bash script that fetches the HN title and all comments on a post and summarizes their themes and opinions, quoting users and keeping the summary short.&lt;/p&gt;
&lt;p&gt;A post may be popular, with hundreds of comments, and I don&amp;rsquo;t want to read them all. I want only the short-form themes expressed.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<p>A recurring theme is that I have a lot of terminal helper scripts for shortcuts.</p>
<p>Inspired by and modified from <a href="https://til.simonwillison.net/llms/claude-hacker-news-themes">Summarizing Hacker News discussion themes with Claude and LLM</a>. I modified the bash script that fetches the HN title and all comments on a post and summarizes their themes and opinions, quoting users and keeping the summary short.</p>
<p>A post may be popular, with hundreds of comments, and I don&rsquo;t want to read them all. I want only the short-form themes expressed.</p>
<h2 id="why-this-approach">Why This Approach?</h2>
<p>This script works best if you already have a code editor with an integrated AI chat (VS Code, Zed, etc.). Run the script, open the <code>.md</code> file in your editor, and the AI reads the embedded instructions and generates a summary.</p>
<p>Usage:</p>






<pre tabindex="0"><code>$ hn-summary
Please provide a valid Hacker News URL or item ID.

Usage: hn-summary [hn_url_or_id]
Description: Fetches Hacker News comments and saves them as markdown with auto-generated filename
Examples:
  hn-summary https://news.ycombinator.com/item?id=12345
  hn-summary 12345</code></pre>






<pre tabindex="0"><code>$ hn-summary https://news.ycombinator.com/item?id=27995270
Saved to: /home/user/Downloads/hn-summary/never-gonna-give-you-up-by-rick-astley-reaches-one-billion-views-video.md</code></pre>
<p>Then I open the <code>.md</code> file in a code editor with an AI chat window and have it summarize according to the instructions in the file.</p>
<hr>
<p>Name:</p>






<div class="highlight"><pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>~/bin/hn-summary</span></span></code></pre></div>
<p>Source:</p>






<div class="highlight"><pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:2;-o-tab-size:2;tab-size:2;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic">#!/bin/bash
</span></span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic"></span>
</span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic"># Function to slugify a string for use as a filename</span>
</span></span><span style="display:flex;"><span>slugify<span style="color:#89dceb;font-weight:bold">()</span> <span style="color:#89dceb;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#89dceb">echo</span> <span style="color:#a6e3a1">&#34;</span><span style="color:#f5e0dc">$1</span><span style="color:#a6e3a1">&#34;</span> | sed <span style="color:#a6e3a1">&#39;s/[^a-zA-Z0-9]/-/g&#39;</span> | sed <span style="color:#a6e3a1">&#39;s/--*/-/g&#39;</span> | sed <span style="color:#a6e3a1">&#39;s/^-\|-$//g&#39;</span> | tr <span style="color:#a6e3a1">&#39;[:upper:]&#39;</span> <span style="color:#a6e3a1">&#39;[:lower:]&#39;</span>
</span></span><span style="display:flex;"><span><span style="color:#89dceb;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic"># Extract ID from URL or use direct ID</span>
</span></span><span style="display:flex;"><span><span style="color:#cba6f7">if</span> <span style="color:#89dceb;font-weight:bold">[[</span> <span style="color:#f5e0dc">$1</span> <span style="color:#89dceb;font-weight:bold">=</span>~ ^https?://news<span style="color:#89b4fa">\.</span>ycombinator<span style="color:#89b4fa">\.</span>com/item<span style="color:#89b4fa">\?</span><span style="color:#f5e0dc">id</span><span style="color:#89dceb;font-weight:bold">=([</span>0-9<span style="color:#89dceb;font-weight:bold">]</span>+<span style="color:#89dceb;font-weight:bold">)</span> <span style="color:#89dceb;font-weight:bold">]]</span>; <span style="color:#cba6f7">then</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f5e0dc">id</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;</span><span style="color:#a6e3a1">${</span><span style="color:#f5e0dc">BASH_REMATCH</span>[1]<span style="color:#a6e3a1">}</span><span style="color:#a6e3a1">&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#cba6f7">elif</span> <span style="color:#89dceb;font-weight:bold">[[</span> <span style="color:#f5e0dc">$1</span> <span style="color:#89dceb;font-weight:bold">=</span>~ ^<span style="color:#89dceb;font-weight:bold">[</span>0-9<span style="color:#89dceb;font-weight:bold">]</span>+$ <span style="color:#89dceb;font-weight:bold">]]</span>; <span style="color:#cba6f7">then</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f5e0dc">id</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;</span><span style="color:#f5e0dc">$1</span><span style="color:#a6e3a1">&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#cba6f7">else</span>
</span></span><span style="display:flex;"><span>    <span style="color:#89dceb">echo</span> <span style="color:#a6e3a1">&#34;Please provide a valid Hacker News URL or item ID.&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#89dceb">echo</span>
</span></span><span style="display:flex;"><span>    <span style="color:#89dceb">echo</span> <span style="color:#a6e3a1">&#34;Usage: </span><span style="color:#cba6f7">$(</span>basename <span style="color:#f5e0dc">$0</span><span style="color:#cba6f7">)</span><span style="color:#a6e3a1"> [hn_url_or_id]&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#89dceb">echo</span> <span style="color:#a6e3a1">&#34;Description: Fetches Hacker News comments and saves them as markdown with auto-generated filename&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#89dceb">echo</span> <span style="color:#a6e3a1">&#34;Examples:&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#89dceb">echo</span> <span style="color:#a6e3a1">&#34;  </span><span style="color:#cba6f7">$(</span>basename <span style="color:#f5e0dc">$0</span><span style="color:#cba6f7">)</span><span style="color:#a6e3a1"> https://news.ycombinator.com/item?id=12345&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#89dceb">echo</span> <span style="color:#a6e3a1">&#34;  </span><span style="color:#cba6f7">$(</span>basename <span style="color:#f5e0dc">$0</span><span style="color:#cba6f7">)</span><span style="color:#a6e3a1"> 12345&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#89dceb">exit</span> <span style="color:#fab387">1</span>
</span></span><span style="display:flex;"><span><span style="color:#cba6f7">fi</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic"># Make the curl request to hn.algolia.com and store JSON response</span>
</span></span><span style="display:flex;"><span><span style="color:#f5e0dc">json_response</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#cba6f7">$(</span>curl -s <span style="color:#a6e3a1">&#34;https://hn.algolia.com/api/v1/items/</span><span style="color:#f5e0dc">$id</span><span style="color:#a6e3a1">&#34;</span><span style="color:#cba6f7">)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic"># Extract title for filename</span>
</span></span><span style="display:flex;"><span><span style="color:#f5e0dc">title</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#cba6f7">$(</span><span style="color:#89dceb">echo</span> <span style="color:#a6e3a1">&#34;</span><span style="color:#f5e0dc">$json_response</span><span style="color:#a6e3a1">&#34;</span> | jq -r <span style="color:#a6e3a1">&#39;.title // &#34;untitled&#34;&#39;</span><span style="color:#cba6f7">)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic"># Create output directory</span>
</span></span><span style="display:flex;"><span><span style="color:#f5e0dc">output_dir</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;</span><span style="color:#f5e0dc">$HOME</span><span style="color:#a6e3a1">/Downloads/hn-summary&#34;</span>
</span></span><span style="display:flex;"><span>mkdir -p <span style="color:#a6e3a1">&#34;</span><span style="color:#f5e0dc">$output_dir</span><span style="color:#a6e3a1">&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic"># Generate filename</span>
</span></span><span style="display:flex;"><span><span style="color:#f5e0dc">filename</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#cba6f7">$(</span>slugify <span style="color:#a6e3a1">&#34;</span><span style="color:#f5e0dc">$title</span><span style="color:#a6e3a1">&#34;</span><span style="color:#cba6f7">)</span>.md
</span></span><span style="display:flex;"><span><span style="color:#f5e0dc">filepath</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;</span><span style="color:#f5e0dc">$output_dir</span><span style="color:#a6e3a1">/</span><span style="color:#f5e0dc">$filename</span><span style="color:#a6e3a1">&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic"># Format comments</span>
</span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic">#  uses `#` for comment parent/children indentation</span>
</span></span><span style="display:flex;"><span><span style="color:#f5e0dc">comments</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#cba6f7">$(</span><span style="color:#89dceb">echo</span> <span style="color:#a6e3a1">&#34;</span><span style="color:#f5e0dc">$json_response</span><span style="color:#a6e3a1">&#34;</span> | <span style="color:#89b4fa">\
</span></span></span><span style="display:flex;"><span><span style="color:#89b4fa"></span>  jq -r <span style="color:#a6e3a1">&#39;(&#34;# Article: &#34; + (.title // &#34;No title&#34;)), (&#34;## URL: &#34; + (.url // &#34;No URL&#34;)), &#34;&#34;,
</span></span></span><span style="display:flex;"><span><span style="color:#a6e3a1">        (def walk(d): . as $item | ((&#34;#&#34; * (d+1) + &#34; &#34; + .author + &#34;: &#34; + .text), (.children[]? | walk(d+1))); walk(0))&#39;</span><span style="color:#cba6f7">)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic"># disable command output</span>
</span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic"># set +x</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic"># Create the content with prompt and comments</span>
</span></span><span style="display:flex;"><span><span style="color:#f5e0dc">content</span><span style="color:#89dceb;font-weight:bold">=</span><span style="color:#a6e3a1">&#34;Summarize the themes of the opinions expressed here.
</span></span></span><span style="display:flex;"><span><span style="color:#a6e3a1">  For each theme, output a markdown header.
</span></span></span><span style="display:flex;"><span><span style="color:#a6e3a1">  Under the header, include a sentence or two summarizing the point or quotes of the theme.
</span></span></span><span style="display:flex;"><span><span style="color:#a6e3a1">  Include direct \&#34;quotations\&#34; where appropriate nested as bullet points last.
</span></span></span><span style="display:flex;"><span><span style="color:#a6e3a1">  You MUST quote directly from users when crediting them, with double quotes.
</span></span></span><span style="display:flex;"><span><span style="color:#a6e3a1">  Fix HTML entities. Output markdown. Go short.
</span></span></span><span style="display:flex;"><span><span style="color:#a6e3a1">
</span></span></span><span style="display:flex;"><span><span style="color:#a6e3a1"></span><span style="color:#f5e0dc">$comments</span><span style="color:#a6e3a1">&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic"># Save to file</span>
</span></span><span style="display:flex;"><span><span style="color:#89dceb">echo</span> <span style="color:#a6e3a1">&#34;</span><span style="color:#f5e0dc">$content</span><span style="color:#a6e3a1">&#34;</span> &gt; <span style="color:#a6e3a1">&#34;</span><span style="color:#f5e0dc">$filepath</span><span style="color:#a6e3a1">&#34;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#6c7086;font-style:italic"># Output the saved file path</span>
</span></span><span style="display:flex;"><span><span style="color:#89dceb">echo</span> <span style="color:#a6e3a1">&#34;Saved to: </span><span style="color:#f5e0dc">$filepath</span><span style="color:#a6e3a1">&#34;</span></span></span></code></pre></div>
]]></content:encoded>
    </item>
  </channel>
</rss>
