<?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>fzf on tac lifelog</title>
    <link>https://tro3373.github.io/tags/fzf/</link>
    <description>Recent content in fzf on tac lifelog</description>
    <image>
      <title>tac lifelog</title>
      <url>https://tro3373.github.io/favicon.png</url>
      <link>https://tro3373.github.io/favicon.png</link>
    </image>
    <generator>Hugo</generator>
    <language>ja</language>
    <lastBuildDate>Fri, 16 Oct 2026 13:48:23 +0900</lastBuildDate>
    <atom:link href="https://tro3373.github.io/tags/fzf/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>スクリプトから呼ぶ fzf が返す値と終了コード</title>
      <link>https://tro3373.github.io/posts/2026/2026-10-16-fzf-in-shell-scripts-pitfalls/</link>
      <pubDate>Fri, 16 Oct 2026 13:48:23 +0900</pubDate>
      <guid>https://tro3373.github.io/posts/2026/2026-10-16-fzf-in-shell-scripts-pitfalls/</guid>
      <description>&lt;h2 id=&#34;結論&#34;&gt;結論&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;--select-1&lt;/code&gt; は候補が 1 件なら、&lt;code&gt;--exit-0&lt;/code&gt; は 0 件なら、一覧を出さずに終わる。「fzf で人が選ぶ」前提の導線でも、1 件に絞れた候補はそのまま確定する&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--query&lt;/code&gt; の既定はあいまい一致で、行全体を照合する。&lt;code&gt;api&lt;/code&gt; は &lt;code&gt;apps-migration&lt;/code&gt; に当たり、&lt;code&gt;--exact&lt;/code&gt; でも &lt;code&gt;main&lt;/code&gt; は &lt;code&gt;domain-model&lt;/code&gt; に当たる。行と完全に一致させるのは &lt;code&gt;^main$&lt;/code&gt; だけ&lt;/li&gt;
&lt;li&gt;fzf は &lt;code&gt;--filter&lt;/code&gt; 以外では起動時に &lt;code&gt;/dev/tty&lt;/code&gt; を開く。制御端末の無いプロセスでは、&lt;code&gt;--select-1&lt;/code&gt; で 1 件に絞れても &lt;code&gt;failed to open /dev/tty&lt;/code&gt; で exit 2 になる&lt;/li&gt;
&lt;li&gt;終了コードは 0 (選んだ) / 1 (一致なし) / 2 (エラー) / 130 (中断)。&lt;code&gt;--expect=&lt;/code&gt; (キー無し) は 2。&lt;code&gt;producer | fzf&lt;/code&gt; は、fzf が先に終わると producer が SIGPIPE の 141 で終わり、&lt;code&gt;pipefail&lt;/code&gt; で全体が 141 になる&lt;/li&gt;
&lt;li&gt;&lt;code&gt;{}&lt;/code&gt; &lt;code&gt;{1}&lt;/code&gt; はシングルクォートで囲んだ 1 引数に展開される。自分で &lt;code&gt;&amp;quot;{}&amp;quot;&lt;/code&gt; と囲むと、そのクォートが値に混ざる&lt;/li&gt;
&lt;li&gt;preview は行ごとに別の &lt;code&gt;$SHELL -c&lt;/code&gt; で走り、呼び出し元の関数と export していない変数は見えない&lt;/li&gt;
&lt;li&gt;&lt;code&gt;--multi&lt;/code&gt; の出力は選んだ順。&lt;code&gt;--tac&lt;/code&gt; は入力の並びを反転するだけで、カーソルは常に並びの先頭に乗る&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;以下は fzf 0.74.3 / bash 5.3.15 / linux/amd64 で実測した。対話の操作は &lt;code&gt;script&lt;/code&gt; コマンドが作る疑似端末 (pty) の中で fzf を動かし、キーを送って再現した。&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
