## 経緯 [[🦉owl-playbook]]や[[WSL2]]環境では[[Bash]]を前提としたシステムを構築していた。ただ、[[Bash]]では補完機能が弱いため、[[Zsh]]へ移行したくなった。 [[fish]]など他のシェルを採用せず、[[Zsh]]にした経緯は以下。 - [[Bash]]との互換性が強い - [[macOS]]がデフォルトシェルとして導入しはじめた 上記からデフォルトの対話型シェルとして使う際のリスクも低いと判断した。 ## 前提 - [[Windows 11]] + [[WSL2]] - [[Windows Terminal]] v1.18.230925001 - [[Ubuntu]] 22.04.3 LTS - [[Starship]]を利用 - [[🦉owl-playbook]]で管理 ## [[Zsh]]のインストール ```console sudo apt-get install -y zsh ``` 起動するとオプションが問われる。 ```console $ zsh This is the Z Shell configuration function for new users, zsh-newuser-install. You are seeing this message because you have no zsh startup files (the files .zshenv, .zprofile, .zshrc, .zlogin in the directory ~). This function can help you with a few settings that should make your use of the shell easier. You can: (q) Quit and do nothing. The function will be run again next time. (0) Exit, creating the file ~/.zshrc containing just a comment. That will prevent this function being run again. (1) Continue to the main menu. (2) Populate your ~/.zshrc with the configuration recommended by the system administrator and exit (you will need to edit the file by hand, if so desired). ``` せっかくなので `(2)` にしてみる。 ## [[asdf]]の設定 インストールは済んでいる前提。 ```zsh source "$HOME/.asdf/asdf.sh" # append completions to fpath fpath=(${ASDF_DIR}/completions $fpath) # initialise completions with ZSH's c autoload -Uz compinit && compinit ``` ## 他の設定 基本的に[[Bash]]と同じ設定が使えそうなのでそのまま`.zshrc`に追加してみる。 ## [[Starship]]の文字化け [[Starship]]のプロンプトが文字化けした。 ![[Pasted image 20231023112937.png]] `.zshrc`の記載が不適切かと思い変更してみた。 ```zsh eval "$(starship init zsh)" ``` ただ、これではテーマが反映されなくなった。`starship`コマンドの中身を見てみた。 ``` #!/usr/bin/env bash # asdf-plugin: starship 1.16.0 exec /home/tadashi-aikawa/.asdf/bin/asdf exec "starship" "$@" # asdf_allow: ' asdf ' ``` ```console $ starship init zsh source <(/home/tadashi-aikawa/.asdf/installs/starship/1.16.0/bin/starship init zsh --print-full-init)% ``` というかそもそも[[Starship]]が起動してなさそう。。コマンドまでは実行されているのに。 `.zshrc`の最後に入れてもダメそう。コマンドは実行されている。 ```zsh eval "$(starship init zsh)" ``` デフォルトで`.zshrc`に設定されているものが余計だったぽい。消したら動いた。 ```zsh # Set up the prompt autoload -Uz promptinit promptinit prompt adam1 setopt histignorealldups sharehistory # Use emacs keybindings even if our EDITOR is set to vi bindkey -e # Keep 1000 lines of history within the shell and save it to ~/.zsh_history: HISTSIZE=1000 SAVEHIST=1000 HISTFILE=~/.zsh_history # Use modern completion system autoload -Uz compinit compinit zstyle ':completion:*' auto-description 'specify: %d' zstyle ':completion:*' completer _expand _complete _correct _approximate zstyle ':completion:*' format 'Completing %d' zstyle ':completion:*' group-name '' zstyle ':completion:*' menu select=2 eval "$(dircolors -b)" zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} zstyle ':completion:*' list-colors '' zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*' zstyle ':completion:*' menu select=long zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s zstyle ':completion:*' use-compctl false zstyle ':completion:*' verbose true zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd' ``` プロンプト設定以外の部分は採用する。 ```zsh setopt histignorealldups sharehistory bindkey -e HISTSIZE=1000 SAVEHIST=1000 HISTFILE=~/.zsh_history autoload -Uz compinit compinit zstyle ':completion:*' auto-description 'specify: %d' zstyle ':completion:*' completer _expand _complete _correct _approximate zstyle ':completion:*' format 'Completing %d' zstyle ':completion:*' group-name '' zstyle ':completion:*' menu select=2 eval "$(dircolors -b)" zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} zstyle ':completion:*' list-colors '' zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*' zstyle ':completion:*' menu select=long zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s zstyle ':completion:*' use-compctl false zstyle ':completion:*' verbose true zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31' zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd' ``` ## [[Zsh]]をデフォルトシェルにする ```console chsh -s /bin/zsh ``` ## [[zsh-autosuggestions]]の導入 以下を参考に。 <div class="link-card-v2"> <div class="link-card-v2-site"> <img class="link-card-v2-site-icon" src="https://static.zenn.studio/images/logo-transparent.png" /> <span class="link-card-v2-site-name">Zenn</span> </div> <div class="link-card-v2-title"> Raspberry Piのzshの拡張設定 </div> <img class="link-card-v2-image" src="https://res.cloudinary.com/zenn/image/upload/s--ZwU4oDe_--/c_fit%2Cg_north_west%2Cl_text:notosansjp-medium.otf_55:Raspberry%2520Pi%25E3%2581%25AEzsh%25E3%2581%25AE%25E6%258B%25A1%25E5%25BC%25B5%25E8%25A8%25AD%25E5%25AE%259A%2Cw_1010%2Cx_90%2Cy_100/g_south_west%2Cl_text:notosansjp-medium.otf_37:tinyreminder%2Cx_203%2Cy_121/g_south_west%2Ch_90%2Cl_fetch:aHR0cHM6Ly9saDMuZ29vZ2xldXNlcmNvbnRlbnQuY29tL2EvQUxtNXd1MFpQNnpwa19pbDJ6Q1BOQzBmem80ZERmejUtNGFteVFtWGZ2RkU9czk2LWM=%2Cr_max%2Cw_90%2Cx_87%2Cy_95/v1627283836/default/og-base-w1200-v2.png" /> <a href="https://zenn.dev/tinyreminder/articles/7e72c46ce2364c"></a> </div> ```console sudo apt install -y zsh-autosuggestions echo "source /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh" >> ~/.zshrc ``` ## [[Broot]] ```console broot --install ``` として再起動してから ```console br ``` で起動してインストール。