Oh My Zshインストール
Oh My Zshとは、zsh(Macのデフォルトシェル)を良い感じにしてくれる便利ツールです。詳しくはこちらの記事がとても参考になります!
▶︎ 公式ページ
以下でインストールができます。
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Git補完
こちらのカスタマイズを適用すると、Gitコマンドやブランチ名などのサジェストをCtrl + i
で表示してくれます。コマンドやブランチのスペルミスなどが減ります。とても便利です。
下記コマンドを順に実行するとインストールが完了します。
mkdir -p ~/.zsh
cd ~/.zsh
curl -o git-completion.bash https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
curl -o _git https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.zsh
インストールしたプラグインを有効化します。~/.zshrc
に以下の記述を追加してください。
zstyle ':completion:*:*:git:*' script ~/.zsh/git-completion.bash
fpath=(~/.zsh $fpath)
autoload -Uz compinit && compinit
コマンドサジェスト
このカスタマイズにより、以下のように、過去に実行したコマンドを元に薄色でサジェストを表示してくれます。
サジェストが表示されている状態で右矢印キーを押すと勝手にコマンドを入力してくれます。とっても便利です。
下記コマンドを順に実行するとインストールが完了します。
git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
インストールしたプラグインを有効化します。~/.zshrc
に以下の記載がある行があると思うので、以下のように修正してください。
plugins=(git)
👇
plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
設定の読み込み
以下コマンド実行、またはターミナルの再起動で、インストールしたカスタムが反映されます。
source ~/.zshrc
テーマ変更
自分の好みに合わせてターミナルのテーマを変更してみるのも楽しいです。
~/.zshrc
に、以下のような記述があると思います。これが適用されるテーマの名前になります。
ZSH_THEME="dallas"
ここが参照するのは、Oh My Zshインストール時に作成される~/.oh-my-zsh
ディレクトリ配下のthemes
ディレクトリ配下になります。
.zsh-theme
という拡張子のファイルがたくさんあると思いますが、これらがそれぞれのテーマを定義するファイルになります。
僕の場合は、dallasというテーマを設定しているので、dallas.zsh-theme
が適用されているデザインファイルになります。
Oh-My-Zshの公式Wikiにて、テーマ一覧が掲載されています。お好みに合わせてターミナルをカスタマイズしてみましょう!
▶︎ https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
また、これらは自分なりにカスタマイズすることもできます。僕の場合、dallasに少し絵文字などを追加しています✨
以下がテーマファイルになりますので、よかったら参考にしてみてください😀
# Personalized!
# Grab the current date (%D) and time (%T) wrapped in {}: {%D %T}
DALLAS_CURRENT_TIME_="%{$fg[white]%}🍔{%{$fg[yellow]%}%D %T%{$fg[white]%}}%{$reset_color%}"
# Grab the current machine name: muscato
DALLAS_CURRENT_MACH_="%{$fg[green]%}WHOPPER%{$fg[white]%}:%{$reset_color%}"
# Grab the current filepath, use shortcuts: ~/Desktop
# Append the current git branch, if in a git repository: ~aw@master
DALLAS_CURRENT_LOCA_="%{$fg[cyan]%}%~\$(git_prompt_info)%{$reset_color%}\$(parse_git_dirty)"
# Grab the current username: dallas
DALLAS_CURRENT_USER_="%{$fg[blue]%}%%{$reset_color%}"
# Use a % for normal users and a # for privileged (root) users.
DALLAS_PROMPT_CHAR_="%{$fg[blue]%}==👉%{$reset_color%}"
# For the git prompt, use a white @ and blue text for the branch name
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%}@(%{$fg[red]%}"
# Close it all off by resetting the color and styles.
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}%{$fg[green]%})"
# Do nothing if the branch is clean (no changes).
ZSH_THEME_GIT_PROMPT_CLEAN=""
# Add 3 cyan ✗s if this branch is diiirrrty! Dirty branch!
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[yellow]%}✗✗✗"
ZSH_THEME_RUBY_PROMPT_PREFIX="%{$fg[white]%}[%{$fg[magenta]%}"
ZSH_THEME_RUBY_PROMPT_SUFFIX="%{$fg[white]%}]%{$reset_color%}"
# Put it all together!
PROMPT="$DALLAS_CURRENT_TIME_\$(ruby_prompt_info)$DALLAS_CURRENT_MACH_$DALLAS_CURRENT_LOCA_$DALLAS_PROMPT_CHAR_ "
快適なターミナルライフを🤞✨