LoginSignup
1
0

More than 1 year has passed since last update.

【Zsh】コマンド履歴から補完する方法

Last updated at Posted at 2023-03-06

はじめに

zsh-autosuggestionsを使用すると以下のようにコマンド履歴に基づいて補完できます。

スクリーンショット 2022-12-09 19.57.38.png

zsh-autosuggestionsの導入方法について記載します。

導入方法

以下のコマンドを実行してzsh-autosuggestionsをクローンします。
パスは任意です。

git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions

~/.zshrcに以下を追記します。

.zshrc
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh

記述後に.zshrcを再読み込みします。

source ~/.zshrc

するとコマンド履歴に基づいて補完できるようになります。

スクリーンショット 2022-12-09 19.57.38.png

候補が表示された状態で「→」を押下すると候補が自動で入力されます。

Oh My Zshを使用する場合

Oh My Zshをインストール

まずOh My Zshをインストールします。

以下のいずれかのコマンドを実行します。

  • curl
sh -c "$(curl -fsSL <https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh>)"
  • wget
sh -c "$(wget -O- <https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh>)"
  • fetch
sh -c "$(fetch -o - <https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh>)" 

上記のコマンドを実行すると既存の.zshrc.zshrc.pre-oh-my-zshに変更されます。

zsh-autosuggestionsをクローン

zsh-autosuggestionsを次のコマンドでクローンします。

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

ZSH_CUSTOMのパスか設定されていなければ~/.oh-my-zsh/custom以下にクローンされます。

.zshrcに設定を記述

zsh-autosuggestionsを使用可能にするため.zshrcを編集します。

.zshrc
...

plugins=( 
    # other plugins...
    zsh-autosuggestions
)

...

記述後に.zshrcを再読み込みします。

source ~/.zshrc
1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0