zshのプラグインマネージャーをzplugからsheldonに移行した際の記録です。
単なる設定移行だけでなく、インストール手順そのものでも複数の問題に遭遇したため、それらも含めて備忘録としてまとめています。
なぜzplugから移行しようと思ったのか
もともとzplugを使っていた理由は、プラグインの導入が非常に手軽だったためです。
.zshrcにzplug 'owner/repo'と書くだけでインストールや読み込みまで完結し、さらにPreztoやoh-my-zshのプラグインも同じ記法で扱うことができました。その柔軟さと導入の容易さが気に入っており、長らくzplugを使い続けていました。
しかし、zplugの最終リリースであるv2.4.2は2017年で止まっており、masterブランチに取り込まれたPull Requestも2022年6月が最後で、それ以降はほとんど活動が見られません。ここまで長期間動きが無い状態は、将来的なメンテナンス性や互換性の面で不安があり、そろそろ代替先を検討したほうが良いと感じていました。
移行先としてはPreztoやoh-my-zshといった大規模なフレームワークも候補に上がりましたが、調べていく中でSheldonがRust製で動作が高速だという話を耳にしました。また、社内でRustを利用しているメンバーやSheldonをすでに運用しているメンバーがいたことも後押しとなり、今回Sheldonへの移行を試してみることにしました。
環境
1. はじめに:sheldonを入れる前に感じた抵抗
1-1. 「curl | sh」するのには抵抗がある
昨今はサプライチェーン攻撃なども話題になっており、インストール作業でいきなり「curlで取得したスクリプトをそのままシェルに流す」という行為には多少の抵抗を感じます。
sheldonはRust製のツールで、公式のインストーラはcurl | sh形式です。便利ではありますが、心理的にあまり使いたくありませんでした。
1-2. Rustが入っていなかったためrustupを入れる必要があった
そこで代替方法として考えたのがcargo(Rust)経由でのインストールです。sheldonはcargoでもインストールできますが、そもそもcargo自体が入っておらず、まずrustupの導入が必要でした。
ところがrustupもまた「curl | sh」形式で、同じ抵抗感があり、判断を少し迷いました。
ビルド済バイナリをリリースページから直接ダウンロードすれば解決しますが、それはそれで管理が大変なので、何かしらのマネージャーツールで管理したい思惑がありました。
1-3. 「snapで入れれば?」と思うかもしれないが…
Ubuntu、もといLinux環境であればsnapでRustツールチェーンを入れる選択肢もあります。しかし、私自身aptとsnapの二重管理は(出来るだけ)避けたいという気持ちもあり、今回は選びませんでした。
1-4. 最終的にはcurlでダウンロードして確認した上で利用することに
今回の抵抗は「コードが改変されていないか」という観点であり、URL先のスクリプト内容自体を一旦ダウンロードしてshellcheckしたり、意図しない動作がないか確認すれば一定の安心感が得られました。
そのため、curl -sSLでスクリプトをファイルとして保存し、中身を確認した上でshを実行し、rustup→cargo→sheldonの順に環境を整えました。
1-4-1. インストールスクリプトをダウンロードする
curl https://sh.rustup.rs -sSf -o rustup-init.sh
1-4-2. インストールスクリプトを確認する
お好きなエディタで確認します。
nano rustup-init.sh
1-4-3. インストールする
スクリプトを実行するとインストールオプションが選べるのでお好みで調整します(特にこだわりが無かったのでEnterキーを押して1番を選択しました)。
sh rustup-init.sh
...
You can uninstall at any time with rustup self uninstall and
these changes will be reverted.
Current installation options:
default host triple: x86_64-unknown-linux-gnu
default toolchain: stable (default)
profile: default
modify PATH variable: yes
1) Proceed with standard installation (default - just press enter)
2) Customize installation
3) Cancel installation
1-4-4. シェルを再読み込みする
インストールが終わったらシェルを再起動するか設定を読み込みます(私はzshを使っているので. "$HOME/.cargo/env"を実行しました)。
info: default toolchain set to 'stable-x86_64-unknown-linux-gnu'
stable-x86_64-unknown-linux-gnu installed - rustc 1.91.1 (ed61e7d7e 2025-11-07)
Rust is installed now. Great!
To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).
To configure your current shell, you need to source
the corresponding env file under $HOME/.cargo.
This is usually done by running one of the following (note the leading DOT):
. "$HOME/.cargo/env" # For sh/bash/zsh/ash/dash/pdksh
source "$HOME/.cargo/env.fish" # For fish
source $"($nu.home-path)/.cargo/env.nu" # For nushell
2. sheldonインストールでopenssl-sysに阻まれる
cargoのインストールが終わったのでsheldonをインストールしようとした際、最初の障害が発生しました。
cargo install sheldon
実行すると、以下のようなエラーが表示されました。
error: failed to run custom build command for `openssl-sys ...`
Could not find directory of OpenSSL installation
The pkg-config command could not be found.
要は
-
openssl-sysクレートのビルドにOpenSSLの開発パッケージが必要 -
pkg-configが見つからないことも原因 - 従ってcargo installが途中で失敗する
ということのようでした。
2-1. 解決策A: pkg-configとOpenSSLをインストールする
Ubuntuの場合は以下で解決します。
sudo apt install pkg-config libssl-dev
cargo install sheldon # 再度インストール
2-2. 解決策B: cargoを使わずSheldon公式インストーラを利用する
curl | shを使っても良ければ、OpenSSLに依存せずにバイナリを展開してくれる公式インストーラを利用する方法もあります。
curl --proto '=https' -fLsS https://rossmacarthur.github.io/install/crate.sh \
| bash -s -- --repo rossmacarthur/sheldon --to ~/.local/bin
3. zplug→sheldonへの移行
cargoまたは公式インストーラでsheldon --versionが確認できる状態になったら、本題の移行作業に進みます。
3-1. sheldonの初期化
sheldon init --shell zsh
これで~/.config/sheldon/plugins.tomlが生成されます。ここに後ほど紹介するプラグイン定義を書き込みます。
4. .zshrcの変更(before → after)
4-1. .zshrc(before:zplug利用時)
以下のようなzplugの設定を全て消し去ります。
## zplug installation
if [[ ! -d ~/.zplug ]]; then
git clone https://github.com/zplug/zplug ~/.zplug
fi
## zplug init
source ~/.zplug/init.zsh
zplug 'zsh-users/zsh-completions'
zplug 'zsh-users/zaw'
zplug 'zsh-users/zsh-syntax-highlighting', defer:2
zplug 'plugins/git', from:oh-my-zsh
zplug 'peterhurford/git-aliases.zsh'
zplug 'zsh-users/zsh-autosuggestions'
zplug 'zsh-users/zsh-history-substring-search', defer:3
zplug 'junegunn/fzf', as:command, from:github, rename-to:fzf
zplug 'mollifier/anyframe'
zplug 'b4b4r07/enhancd', use:init.sh
zplug 'zplug/zplug', hook-build:'zplug --self-manage'
zplug "bhilburn/powerlevel9k", use:powerlevel9k.zsh-theme
zplug load
if ! zplug check --verbose; then
printf "Install?[y/n]: "
if read -q; then
echo; zplug install
chmod 755 ~/.zplug
fi
fi
4-2. .zshrc(after:sheldonの読み込みのみ)
その後、以下の設定を追加します。
## sheldon
if command -v sheldon >/dev/null 2>&1; then
eval "$(sheldon source)"
fi
zplugで行っていたプラグイン一覧管理は、次に紹介する~/.config/sheldon/plugins.tomlにすべて移します。
5. プラグインの移行(zplug → sheldon)
~/.config/sheldon/plugins.tomlを以下のように変更します。
shell = "zsh"
[plugins.zsh_completions]
github = "zsh-users/zsh-completions"
[plugins.zaw]
github = "zsh-users/zaw"
[plugins.zsh_syntax_highlighting]
github = "zsh-users/zsh-syntax-highlighting"
[plugins.git_ohmyzsh]
github = "ohmyzsh/ohmyzsh"
dir = "plugins/git"
apply = ["source"]
[plugins.git_aliases]
github = "peterhurford/git-aliases.zsh"
use = ["git-aliases.plugin.zsh"]
[plugins.zsh_autosuggestions]
github = "zsh-users/zsh-autosuggestions"
[plugins.zsh_history_substring_search]
github = "zsh-users/zsh-history-substring-search"
[plugins.fzf]
github = "junegunn/fzf"
dir = "bin"
apply = ["PATH"]
[plugins.anyframe]
github = "mollifier/anyframe"
[plugins.enhancd]
github = "b4b4r07/enhancd"
use = ["init.sh"]
[plugins.powerlevel9k]
github = "bhilburn/powerlevel9k"
use = ["powerlevel9k.zsh-theme"]
6. ロックファイル生成と確認
プラグイン定義を記述したら、以下でロックファイルを生成します。
sheldon lock --update
その後、zshを再読み込みして問題なくサジェスト、補完、fzf、powerlevel9k等が動作すれば移行は完了です。
7. まとめ
- 「curl | sh」を避けたい場合でもsheldonは導入可能であり、スクリプト内容を確認した上で実行する形で対応しました。
- cargo経由でのインストールは
openssl-sys依存により失敗しましたが、pkg-configとlibssl-devを入れることで解決できます。 - zplugの宣言はplugins.tomlに素直に移せば問題ありませんが、
useで指定するファイル名は実際のリポジトリ内容を確認する必要があります。 - sheldonはzplugより設定がシンプルになり、plugins.tomlによる集中管理が便利に感じました。