動かざることバグの如し

近づきたいよ 君の理想に

UbuntuにPreztoをインストールしてみた

環境

多分Macもいける

やりたいこと

今まではzshフレームワークでoh-my-zsh使ってたが、起動がやっぱり遅いとかあったのでPreztoに乗り換えてみたメモ

github.com

インストール

公式のREADMEやれば問題ない 先にzshbrewなりaptでインストールしておく必要はある

現状がbashの場合は

zsh

clone

git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"

設定ファイルを作成 すでに.zshrcがある場合はうまくいかないので事前に退避させておくこと

setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
  ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done

成功するとシンボリックリンクがはられていることが確認できる

❯ ls -la | grep zprezto/runcoms
lrwxrwxrwx 1 vagrant vagrant    37 May  4 00:48 .zlogin -> /home/vagrant/.zprezto/runcoms/zlogin
lrwxrwxrwx 1 vagrant vagrant    38 May  4 00:48 .zlogout -> /home/vagrant/.zprezto/runcoms/zlogout
lrwxrwxrwx 1 vagrant vagrant    40 May  4 00:48 .zpreztorc -> /home/vagrant/.zprezto/runcoms/zpreztorc
lrwxrwxrwx 1 vagrant vagrant    39 May  4 00:48 .zprofile -> /home/vagrant/.zprezto/runcoms/zprofile
lrwxrwxrwx 1 vagrant vagrant    37 May  4 00:48 .zshenv -> /home/vagrant/.zprezto/runcoms/zshenv
lrwxrwxrwx 1 vagrant vagrant    36 May  4 00:48 .zshrc -> /home/vagrant/.zprezto/runcoms/zshrc

デフォルトのシェルをzshに変更する

chsh -s /bin/zsh

テーマの変更

デフォルトでいくつか有名どころのテーマがインストールされている

prompt -p

テーマ変更は~/.zpreztorcを編集する 今回はpureに変更した

- zstyle ':prezto:module:prompt' theme 'sorin'
+ zstyle ':prezto:module:prompt' theme 'pure'

デフォルトのエディタをVimに変更

なぜかデフォルトがnanoになってるので.zprofileを書き換えてvimにしておく

- export EDITOR='nano'
- export VISUAL='nano'
+ export EDITOR='vim'
+ export VISUAL='vim'

各種設定

現行の.zpreztorc設定は以下

--- runcoms-orig/zpreztorc   2022-08-12 22:01:09.000000000 +0900
+++ /Users/thr3a/.zpreztorc   2022-08-12 22:14:41.000000000 +0900
@@ -34,19 +34,19 @@
   'terminal' \
   'editor' \
   'history' \
-  'directory' \
   'spectrum' \
   'utility' \
   'completion' \
   'history-substring-search' \
-  'prompt'
-
+  'autosuggestions' \
+  'prompt' \
+  'syntax-highlighting'
 #
 # Autosuggestions
 #
 
 # Set the query found color.
-# zstyle ':prezto:module:autosuggestions:color' found ''
+# zstyle ':prezto:module:autosuggestions:color' found 'fg=red'
 
 #
 # Completions
@@ -61,7 +61,7 @@
 #
 
 # Set the key mapping style to 'emacs' or 'vi'.
-zstyle ':prezto:module:editor' key-bindings 'emacs'
+zstyle ':prezto:module:editor' key-bindings 'vi'
 
 # Auto convert .... to ../..
 # zstyle ':prezto:module:editor' dot-expansion 'yes'
@@ -130,7 +130,7 @@
 # Set the prompt theme to load.
 # Setting it to 'random' loads a random theme.
 # Auto set to 'off' on dumb terminals.
-zstyle ':prezto:module:prompt' theme 'sorin'
+zstyle ':prezto:module:prompt' theme 'pure'
 
 # Set the working directory prompt display length.
 # By default, it is set to 'short'. Set it to 'long' (without '~' expansion)
@@ -181,13 +181,9 @@
 
 # Set syntax highlighters.
 # By default, only the main highlighter is enabled.
-# zstyle ':prezto:module:syntax-highlighting' highlighters \
-#   'main' \
-#   'brackets' \
-#   'pattern' \
-#   'line' \
-#   'cursor' \
-#   'root'
+ zstyle ':prezto:module:syntax-highlighting' highlighters \
+   'main' \
+   'brackets'
 #
 # Set syntax highlighting styles.
 # zstyle ':prezto:module:syntax-highlighting' styles \

詳しく説明すると

.zshrcはどうなの

brew install fzf して以下のようにCtrl+rでインクリメント履歴検索出来るように

function select-history() {
  BUFFER=$(history -n -r 1 | fzf --no-sort +m --query "$LBUFFER" --prompt="History > ")
  CURSOR=$#BUFFER
}
zle -N select-history
bindkey '^r' select-history

参考リンク