Help us understand the problem. What is going on with this article?

ターミナルでコマンド履歴の入力補完

More than 1 year has passed since last update.

やりたいこと

  • 文字入力時に直近の履歴を表示させたい

3月-06-2018 20-30-18.gif

準備

インストール

zshとoh-my-zshを使った二種類の方法を紹介します

zsh

  • zsh-autosuggestionsをクローン (ここでは~/.zsh/zsh-autosuggestionへ)
% git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
  • ~/.zshrcに以下を記入
.zshrc
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
  • 設定を更新
% source ~/.zshrc

Oh My Zsh

  • $ZSH_CUSTOM/pluginszsh-autosuggestionsをクローン
  • $ZSH_CUSTOMはデフォルトだと ~/.oh-my-zsh/custom
% git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
  • .zshrcのpluginsにzsh-autosuggestionsを追記
~/.zshrc
plugins=(
    git,
    zsh-autosuggestions
)
  • 設定を更新
% source ~/.zshrc

使い方

  • 文字を入力すると薄地でサジェストが表示される
  • C-fC-eで確定 3月-06-2018 20-30-18.gif
  • 色は以下を.zshrcへ追記しfgの値で変更できる。デフォルトは8
~/.zshrc
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=5'

参考

 

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away