Skip to content

Ubuntu 24.04LTS へ peco をインストールする

peco は Python で書かれた percol をベースに、同じコンセプトを Go 言語で実装したもの、だそうです。 percol も peco もかなり歴史があり、開発されてから 10 年程度経過しているようです。 peco の GitHub には以下のように書かれています。

peco (pronounced peh-koh) is based on a python tool, percol. percol was darn useful, but I wanted a tool that was a single binary, and forget about python. peco is written in Go, and therefore you can just grab the binary releases and drop it in your $PATH.

peco can be a great tool to filter stuff like logs, process stats, find files, because unlike grep, you can type as you think and look through the current results.

For basic usage, continue down below. For more cool elaborate usage samples, please see the wiki, and if you have any other tricks you want to share, please add to it!

今回は peco を Ubuntu 24.04LTS へインストールする手順をメモしておきます。

検証環境

対象 バージョン
Ubuntu 24.04.2 LTS
peco 0.5.11

OS 標準リポジトリの peco は正しく動作しない?

peco はUbuntu の標準リポジトリからインストールすることが出来ます。 最新バージョンは 0.5.11 ですが、現時点で Ubuntu 標準リポジトリからインストール出来るのはバージョン 0.5.10 でした。

# apt info peco
Package: peco
Version: 0.5.10-1ubuntu0.24.04.2
Built-Using: golang-1.22 (= 1.22.2-2ubuntu0.3), golang-github-google-btree (= 1.0.0-1), golang-github-lestrrat-go-pdebug (= 0.0~git20180220.0.569c974-3), golang-github-mattn-go-runewidth (= 0.0.15-2), golang-github-nsf-termbox-go (= 0.0~git20160914-3), golang-github-pkg-errors (= 0.9.1-3), golang-github-rivo-uniseg (= 0.4.4-1), golang-go-flags (= 1.4.0-6)
Priority: extra
Section: universe/devel
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian Go Packaging Team <pkg-go-maintainers@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 3607 kB
Homepage: https://github.com/peco/peco
Download-Size: 1209 kB
APT-Sources: http://archive.ubuntu.com/ubuntu noble-updates/universe amd64 Packages
Description: Simplistic interactive filtering tool
 peco Simplistic interactive filtering tool
 .
 peco can be a great tool to filter stuff like logs, process stats, find
 files, because unlike grep, you can type as you think and look through
 the current results.

N: There is 1 additional record. Please use the '-a' switch to see it

インストールします。

apt install -y peco

バージョン 0.5.10 がインストールされました。

# peco --version
peco version v0.5.10 (built with go1.22.2)

しかし、ls -l | peco のように実行すると表示が以下のように乱れてしまい、使い物になりません…

image

mise で peco をインストールする

peco は Go 言語で書かれている為、GitHub の Releases ページ から現時点の最新版であるバージョン 0.5.11 のバイナリをダウンロードし、インストールすることも出来ます。 ですが、それではバージョン管理を手動で行うことになってしまいます。 そこで今回は mise でインストールします。

mise install peco@latest && \
mise use -g peco@latest

peco の設定例

peco に「Ctrl+R でコマンド履歴を表示する」キーバインドを追加してみます ~/.bashrc へ以下を追記します。 追記後は設定を反映する為にログアウト & ログインし直します。

~/.bashrc
peco-select-history() {
  local _cmd=$(HISTTIMEFORMAT= history | tac | sed -e 's/^\s*[0-9]\+\s\+//' | peco --query "$READLINE_LINE")
  READLINE_LINE="$_cmd"
  READLINE_POINT=${#_cmd}
}

bind -x '"\C-r": peco-select-history'

Ctrl+R を押すとターミナルに以下のように表示されます。

image