目次
Z shell(Zsh)
本家: Zsh - zsh.org
ソースコード: zsh / Code - sourceforge.net
ドキュメント: zsh.sourceforge.io/Doc/
Z shell (Zsh) は、対話型ログインシェルとして、またシェル スクリプトのコマンド インタープリタとして使用できる Unix シェルである。Zsh は、Bash、ksh、および tcsh のいくつかの機能を含む、多くの改良が施された拡張 Bourne シェルである。
Zsh は、プリンストン大学の学生だった 1990 年に Paul Falstad によって作成された。ksh と tcsh の両方の機能を組み合わせ、プログラム可能なコマンドライン補完、拡張ファイルグロビング、改善された変数/配列処理、テーマ対応プロンプトなどの機能を提供する。
Zsh は、 UnxUtils コレクションの一部として Microsoft Windows で利用でき、macOS および Kali Linux のデフォルト シェルとして採用されています。“Oh My Zsh” ユーザー コミュニティ Web サイトは、サードパーティのプラグインとテーマ用のプラットフォームを提供し、大規模で活発な寄稿者ベースを特徴としている。
Z shell - Wikiwand 翻訳 より
インストール
Fedora
$ sudo dnf install zsh
メタデータの期限切れの最終確認: 0:01:08 時間前の 2023年05月22日 12時10分04秒 に実施しました。 依存関係が解決しました。 ============================================================================================================== パッケージ アーキテクチャー バージョン リポジトリー サイズ ============================================================================================================== インストール: zsh x86_64 5.9-5.fc38 fedora 3.3 M トランザクションの概要 ============================================================================================================== インストール 1 パッケージ ダウンロードサイズの合計: 3.3 M インストール後のサイズ: 8.0 M これでよろしいですか? [y/N]: y パッケージのダウンロード: zsh-5.9-5.fc38.x86_64.rpm 242 kB/s | 3.3 MB 00:13 -------------------------------------------------------------------------------------------------------------- 合計 225 kB/s | 3.3 MB 00:14 トランザクションの確認を実行中 トランザクションの確認に成功しました。 トランザクションのテストを実行中 トランザクションのテストに成功しました。 トランザクションを実行中 準備 : 1/1 インストール中 : zsh-5.9-5.fc38.x86_64 1/1 scriptletの実行中: zsh-5.9-5.fc38.x86_64 1/1 検証 : zsh-5.9-5.fc38.x86_64 1/1 インストール済み: zsh-5.9-5.fc38.x86_64 完了しました!
$ zsh --version
zsh 5.9 (x86_64-redhat-linux-gnu)
DietPi (Raspberry Pi Zero WH)
How to properly switch to zsh and be able to use dietpi commands - General Discussion - DietPi Community Forum 翻訳
DietPi では DietPi 固有のコマンド群が bash でしかサポートされていないが…🤔 無理やり…😅
$ sudo apt install zsh
Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: zsh-common Suggested packages: zsh-doc The following NEW packages will be installed: zsh zsh-common 0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded. Need to get 4,711 kB of archives. After this operation, 17.7 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://raspbian.raspberrypi.org/raspbian bullseye/main armhf zsh-common all 5.8-6+deb11u1 [3,941 kB] Get:2 http://raspbian.raspberrypi.org/raspbian bullseye/main armhf zsh armhf 5.8-6+deb11u1 [770 kB] Fetched 4,711 kB in 6s (782 kB/s) debconf: delaying package configuration, since apt-utils is not installed Selecting previously unselected package zsh-common. (Reading database ... 106351 files and directories currently installed.) Preparing to unpack .../zsh-common_5.8-6+deb11u1_all.deb ... Unpacking zsh-common (5.8-6+deb11u1) ... Selecting previously unselected package zsh. Preparing to unpack .../zsh_5.8-6+deb11u1_armhf.deb ... Unpacking zsh (5.8-6+deb11u1) ... Setting up zsh-common (5.8-6+deb11u1) ... Setting up zsh (5.8-6+deb11u1) ... Processing triggers for man-db (2.9.4-2) ...
$ zsh --version
zsh 5.8 (arm-unknown-linux-gnueabihf)
DietPi の Z shell 対応
~/.zsh_dietpi
を作成する🤔
$ nano ~/.zsh_dietpi
# DietPi-Globals: dietpi-* aliases, G_* functions and variables . /boot/dietpi/func/dietpi-globals || { echo -e '[\e[31mFAILED\e[0m] DietPi-Login | Failed to load DietPi-Globals. Skipping DietPi login scripts...'; return 1; } # Aliases # - sudo alias that allows running other aliases with "sudo": https://github.com/MichaIng/DietPi/issues/424 alias sudo='sudo ' # - DietPi programs alias dietpi-letsencrypt='/boot/dietpi/dietpi-letsencrypt' alias dietpi-autostart='/boot/dietpi/dietpi-autostart' alias dietpi-cron='/boot/dietpi/dietpi-cron' alias dietpi-launcher='/boot/dietpi/dietpi-launcher' alias dietpi-cleaner='/boot/dietpi/dietpi-cleaner' alias dietpi-morsecode='/boot/dietpi/dietpi-morsecode' alias dietpi-sync='/boot/dietpi/dietpi-sync' alias dietpi-backup='/boot/dietpi/dietpi-backup' alias dietpi-bugreport='/boot/dietpi/dietpi-bugreport' alias dietpi-services='/boot/dietpi/dietpi-services' alias dietpi-config='/boot/dietpi/dietpi-config' alias dietpi-software='/boot/dietpi/dietpi-software' alias dietpi-update='/boot/dietpi/dietpi-update' alias dietpi-drive_manager='/boot/dietpi/dietpi-drive_manager' alias dietpi-logclear='/boot/dietpi/func/dietpi-logclear' alias dietpi-survey='/boot/dietpi/dietpi-survey' alias dietpi-explorer='/boot/dietpi/dietpi-explorer' alias dietpi-banner='/boot/dietpi/func/dietpi-banner' alias dietpi-justboom='/boot/dietpi/misc/dietpi-justboom' alias dietpi-led_control='/boot/dietpi/dietpi-led_control' alias dietpi-wifidb='/boot/dietpi/func/dietpi-wifidb' alias dietpi-optimal_mtu='/boot/dietpi/func/dietpi-optimal_mtu' alias dietpi-cloudshell='/boot/dietpi/dietpi-cloudshell' alias dietpi-nordvpn='G_DIETPI-NOTIFY 1 "DietPi-NordVPN has been renamed to DietPi-VPN. Please use the \"dietpi-vpn\" command."' alias dietpi-vpn='/boot/dietpi/dietpi-vpn' alias dietpi-ddns='/boot/dietpi/dietpi-ddns' alias cpu='/boot/dietpi/dietpi-cpuinfo' # - Optional DietPi software aliases [[ -d '/mnt/dietpi_userdata/sonarr' || -d '/mnt/dietpi_userdata/radarr' || -d '/mnt/dietpi_userdata/lidarr' ]] && alias dietpi-arr_to_RAM='/boot/dietpi/misc/dietpi-arr_to_RAM' command -v kodi > /dev/null && alias startkodi='/boot/dietpi/misc/start_kodi' [[ -f '/usr/games/opentyrian/run' ]] && alias opentyrian='/usr/games/opentyrian/run' [[ -f '/mnt/dietpi_userdata/dxx-rebirth/run.sh' ]] && alias dxx-rebirth='/mnt/dietpi_userdata/dxx-rebirth/run.sh' # - 1337 moments ;) alias 1337='echo "Indeed, you are =)"' # "G_DIETPI-NOFITY -2 message" starts a process animation. If scripts fail to kill the animation, e.g. cancelled by user, terminal bash prompt has to do it as last resort. [[ $PROMPT_COMMAND == *'dietpi-process.pid'* ]] || PROMPT_COMMAND="[[ -w '/tmp/dietpi-process.pid' ]] && rm -f /tmp/dietpi-process.pid &> /dev/null && echo -ne '\r\e[J'; $PROMPT_COMMAND" # DietPi-Login: First run setup, autostarts and login banner # - Prevent call if $G_DIETPI_LOGIN has been set. E.g. when shell is called as subshell of G_EXEC or dietpi-login itself, we don't want autostart programs to be launched. [[ $G_DIETPI_LOGIN ]] || /boot/dietpi/dietpi-login
~/.zshrc
から ~/.zsh_dietpi
を呼び出すように設定する🤔
$ nano ~/.zshrc
if [ -f ~/.commonshrc ]; then . ~/.commonshrc fi # Z shell DietPi Support . ~/.zsh_dietpi
参考
MichaIng/DietPi: Lightweight justice for your single-board computer!
+ 参考 そのままでは DietPi の機能でエラーが発生
$ . /etc/bashrc.d/dietpi.bash
/boot/dietpi/.version:6: G_LIVE_PATCH_STATUS: assignment to invalid subscript range /etc/bashrc.d/dietpi.bash:76: closing brace expected
$ cat/etc/bashrc.d/dietpi.bash
#!/bin/bash { #//////////////////////////////////// # DietPi bash init script # #//////////////////////////////////// # Created by MichaIng / micha@dietpi.com / dietpi.com # #//////////////////////////////////// # # Info: # - Location: /etc/bashrc.d/dietpi.bash # - Sourced by all interactive bash shells from: /etc/bash.bashrc # - Prepares shell for DietPi and runs autostarts on /dev/tty1 #//////////////////////////////////// # Failsafe: Never load this script in non-interactive shells, e.g. SFTP, SCP or rsync [[ -t 0 && $- == *'i'* ]] || return 0 # DietPi-Globals: dietpi-* aliases, G_* functions and variables . /boot/dietpi/func/dietpi-globals || { echo -e '[\e[31mFAILED\e[0m] DietPi-Login | Failed to load DietPi-Globals. Skipping DietPi login scripts...'; return 1; } # Aliases # - sudo alias that allows running other aliases with "sudo": https://github.com/MichaIng/DietPi/issues/424 alias sudo='sudo ' # - DietPi programs alias dietpi-letsencrypt='/boot/dietpi/dietpi-letsencrypt' alias dietpi-autostart='/boot/dietpi/dietpi-autostart' alias dietpi-cron='/boot/dietpi/dietpi-cron' alias dietpi-launcher='/boot/dietpi/dietpi-launcher' alias dietpi-cleaner='/boot/dietpi/dietpi-cleaner' alias dietpi-morsecode='/boot/dietpi/dietpi-morsecode' alias dietpi-sync='/boot/dietpi/dietpi-sync' alias dietpi-backup='/boot/dietpi/dietpi-backup' alias dietpi-bugreport='/boot/dietpi/dietpi-bugreport' alias dietpi-services='/boot/dietpi/dietpi-services' alias dietpi-config='/boot/dietpi/dietpi-config' alias dietpi-software='/boot/dietpi/dietpi-software' alias dietpi-update='/boot/dietpi/dietpi-update' alias dietpi-drive_manager='/boot/dietpi/dietpi-drive_manager' alias dietpi-logclear='/boot/dietpi/func/dietpi-logclear' alias dietpi-survey='/boot/dietpi/dietpi-survey' alias dietpi-explorer='/boot/dietpi/dietpi-explorer' alias dietpi-banner='/boot/dietpi/func/dietpi-banner' alias dietpi-justboom='/boot/dietpi/misc/dietpi-justboom' alias dietpi-led_control='/boot/dietpi/dietpi-led_control' alias dietpi-wifidb='/boot/dietpi/func/dietpi-wifidb' alias dietpi-optimal_mtu='/boot/dietpi/func/dietpi-optimal_mtu' alias dietpi-cloudshell='/boot/dietpi/dietpi-cloudshell' alias dietpi-nordvpn='G_DIETPI-NOTIFY 1 "DietPi-NordVPN has been renamed to DietPi-VPN. Please use the \"dietpi-vpn\" command."' alias dietpi-vpn='/boot/dietpi/dietpi-vpn' alias dietpi-ddns='/boot/dietpi/dietpi-ddns' alias cpu='/boot/dietpi/dietpi-cpuinfo' # - Optional DietPi software aliases [[ -d '/mnt/dietpi_userdata/sonarr' || -d '/mnt/dietpi_userdata/radarr' || -d '/mnt/dietpi_userdata/lidarr' ]] && alias dietpi-arr_to_RAM='/boot/dietpi/misc/dietpi-arr_to_RAM' command -v kodi > /dev/null && alias startkodi='/boot/dietpi/misc/start_kodi' [[ -f '/usr/games/opentyrian/run' ]] && alias opentyrian='/usr/games/opentyrian/run' [[ -f '/mnt/dietpi_userdata/dxx-rebirth/run.sh' ]] && alias dxx-rebirth='/mnt/dietpi_userdata/dxx-rebirth/run.sh' [[ -f '/var/www/owncloud/occ' ]] && alias occ='sudo -u www-data php /var/www/owncloud/occ' [[ -f '/var/www/nextcloud/occ' ]] && alias ncc='sudo -u www-data php /var/www/nextcloud/occ' # - 1337 moments ;) alias 1337='echo "Indeed, you are =)"' # "G_DIETPI-NOFITY -2 message" starts a process animation. If scripts fail to kill the animation, e.g. cancelled by user, terminal bash prompt has to do it as last resort. [[ $PROMPT_COMMAND == *'dietpi-process.pid'* ]] || PROMPT_COMMAND="[[ -w '/tmp/dietpi-process.pid' ]] && rm -f /tmp/dietpi-process.pid &> /dev/null && echo -ne '\r\e[J'; $PROMPT_COMMAND" # Workaround if SSH client overrides locale with "POSIX" fallback: https://github.com/MichaIng/DietPi/issues/1540#issuecomment-367066178 if [[ ${LC_ALL:-${LANG:-POSIX}} == 'POSIX' ]] then current_locale=$(sed -n '/^[[:blank:]]*AUTO_SETUP_LOCALE=/{s/^[^=]*=//p;q}' /boot/dietpi.txt) export LC_ALL=${current_locale:=C.UTF-8} LANG=$current_locale unset -v current_locale fi # Workaround if SSH client sets an unsupported $TERM string: https://github.com/MichaIng/DietPi/issues/2034 term="/${TERM::1}/$TERM" if [[ $SSH_TTY && ! -f /lib/terminfo$term && ! -f /usr/share/terminfo$term && ! -f ~/.terminfo$term && ! -f /etc/terminfo$term ]] then TERM_old=$TERM export TERM='xterm' [[ $TERM_old == *'256'* ]] && TERM+='-256color' G_WHIP_MENU_ARRAY=('0' 'Ignore for now, I will change the SSH clients terminal.') ncurses_term= if ! dpkg-query -s ncurses-term &> /dev/null then ncurses_term=' or install the "ncurses-term" APT package, which enables broader terminal support' G_WHIP_MENU_ARRAY+=('1' 'Install "ncurses-term" now to enable broader terminal support.') G_WHIP_DEFAULT_ITEM=1 fi G_PROGRAM_NAME='Unsupported SSH client terminal' G_WHIP_MENU "[WARNING] Your SSH client passed an unsupported terminal: TERM=$TERM_old \nAs a workaround, we fooled the server by setting TERM=$TERM. This is not the cleanest solution as commands may use control sequences which are not supported by the current terminal. \nPlease change your SSH clients terminal, respectively the passed \$TERM string$ncurses_term." && (( $G_WHIP_RETURNED_VALUE )) && G_AGI ncurses-term unset -v TERM_old ncurses_term fi unset -v term # DietPi-Login: First run setup, autostarts and login banner # - Prevent call if $G_DIETPI_LOGIN has been set. E.g. when shell is called as subshell of G_EXEC or dietpi-login itself, we don't want autostart programs to be launched. [[ $G_DIETPI_LOGIN ]] || /boot/dietpi/dietpi-login }
Oh My Zsh のインストール
$ zsh --version
zsh 5.9 (x86_64-redhat-linux-gnu)
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Cloning Oh My Zsh... remote: Enumerating objects: 1361, done. remote: Counting objects: 100% (1361/1361), done. remote: Compressing objects: 100% (1309/1309), done. remote: Total 1361 (delta 33), reused 1132 (delta 28), pack-reused 0 Receiving objects: 100% (1361/1361), 2.00 MiB | 8.84 MiB/s, done. Resolving deltas: 100% (33/33), done. From https://github.com/ohmyzsh/ohmyzsh * [new branch] master -> origin/master branch 'master' set up to track 'origin/master'. Already on 'master' /home/tomoyan Looking for an existing zsh config... Using the Oh My Zsh template file and adding it to /home/tomoyan/.zshrc. I can't change your shell automatically because this system does not have chsh. Please manually change your default shell to zsh __ __ ____ / /_ ____ ___ __ __ ____ _____/ /_ / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ / /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / \____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ /____/ ....is now installed! Before you scream Oh My Zsh! look over the `.zshrc` file to select plugins, themes, and options. • Follow us on Twitter: https://twitter.com/ohmyzsh • Join our Discord community: https://discord.gg/ohmyzsh • Get stickers, t-shirts, coffee mugs and more: https://shop.planetargon.com/collections/oh-my-zsh ➜ ~
サイレント インストールするには...🤔
$ curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh | bat -p --pager no
#!/bin/sh # # This script should be run via curl: # sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" # or via wget: # sh -c "$(wget -qO- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" # or via fetch: # sh -c "$(fetch -o - https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" # # As an alternative, you can first download the install script and run it afterwards: # wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh # sh install.sh # # You can tweak the install behavior by setting variables when running the script. For # example, to change the path to the Oh My Zsh repository: # ZSH=~/.zsh sh install.sh # # Respects the following environment variables: # ZDOTDIR - path to Zsh dotfiles directory (default: unset). See [1][2] # [1] https://zsh.sourceforge.io/Doc/Release/Parameters.html#index-ZDOTDIR # [2] https://zsh.sourceforge.io/Doc/Release/Files.html#index-ZDOTDIR_002c-use-of # ZSH - path to the Oh My Zsh repository folder (default: $HOME/.oh-my-zsh) # REPO - name of the GitHub repo to install from (default: ohmyzsh/ohmyzsh) # REMOTE - full remote URL of the git repo to install (default: GitHub via HTTPS) # BRANCH - branch to check out immediately after install (default: master) # # Other options: # CHSH - 'no' means the installer will not change the default shell (default: yes) # RUNZSH - 'no' means the installer will not run zsh after the install (default: yes) # KEEP_ZSHRC - 'yes' means the installer will not replace an existing .zshrc (default: no) # # You can also pass some arguments to the install script to set some these options: # --skip-chsh: has the same behavior as setting CHSH to 'no' # --unattended: sets both CHSH and RUNZSH to 'no' # --keep-zshrc: sets KEEP_ZSHRC to 'yes' # For example: # sh install.sh --unattended # or: # sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended #
--unattended
オプションを付けて実行する😉
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
実行
$ 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. --- Type one of the keys in parentheses --- 1
これは新規ユーザー向けの Z Shell 設定機能です。 zsh-newuser-install。 zsh 起動ファイルがないため、このメッセージが表示されます。 (ディレクトリ内のファイル .zshenv、.zprofile、.zshrc、.zlogin ~)。この機能は、必要ないくつかの設定に役立ちます。 シェルをより簡単に使用できるようになります。 あなたはできる: (q) やめて何もしないでください。この関数は次回も実行されます。 (0) コメントのみを含むファイル ~/.zshrc を作成して終了します。 これにより、この関数は再度実行されなくなります。 (1) メインメニューに進みます。 --- 括弧内にいずれかのキーを入力します ---
Please pick one of the following options: (1) Configure settings for history, i.e. command lines remembered and saved by the shell. (Recommended.) (2) Configure the new completion system. (Recommended.) (3) Configure how keys behave when editing command lines. (Recommended.) (4) Pick some of the more common shell options. These are simple "on" or "off" switches controlling the shell's features. (0) Exit, creating a blank ~/.zshrc file. (a) Abort all settings and start from scratch. Note this will overwrite any settings from zsh-newuser-install already in the startup file. It will not alter any of your other settings, however. (q) Quit and do nothing else. The function will be run again next time. --- Type one of the keys in parentheses --- 0
次のオプションのいずれかを選択してください。 (1) 履歴の設定を構成します。つまり、コマンドラインを記憶します。 そしてシェルによって保存されます。 (おすすめされた。) (2) 新しい補完システムを構成します。 (おすすめされた。) (3) コマンドライン編集時のキーの動作を設定します。 (おすすめされた。) (4) より一般的なシェル オプションをいくつか選択します。これらは単純に「オン」です またはシェルの機能を制御する「オフ」スイッチ。 (0) 終了し、空の ~/.zshrc ファイルを作成します。 (a) すべての設定を中止し、最初からやり直します。これは上書きされることに注意してください zsh-newuser-install の設定はすでに起動ファイルに含まれています。 ただし、他の設定は変更されません。 (q) 辞めて何もしません。この関数は次回も実行されます。 --- 括弧内にいずれかのキーを入力します ---
設定 (.zshrc)
コマンドを履歴に残さない
参考: bash - Is there any way to keep a command from being added to your history? - Unix & Linux Stack Exchange
zsh: 16 Options
オプション | 説明 |
---|---|
HIST_IGNORE_SPACE (-g) | Remove command lines from the history list when the first character on the line is a space, or when one of the expanded aliases contains a leading space. Only normal aliases (not global or suffix aliases) have this behaviour. Note that the command lingers in the internal history until the next command is entered before it vanishes, allowing you to briefly reuse or edit the line. If you want to make it vanish right away without entering another command, type a space and press return. |
履歴リストからコマンドラインを削除します。 ラインの最初の文字がスペースである場合、または拡張されたエイリアスのいずれかに先頭のスペースが含まれている場合。 この動作には、通常のエイリアス (グローバルまたは接尾辞エイリアスではありません) のみがあります。 コマンドは、次のコマンドが消滅する前に入力されるまで内部履歴に残り、ラインを簡単に再利用または編集できることに注意してください。 別のコマンドを入力せずにすぐに消えたい場合は、スペースを入力して戻ります。 — |
|
HIST_NO_STORE | Remove the history (fc -l) command from the history list when invoked. Note that the command lingers in the internal history until the next command is entered before it vanishes, allowing you to briefly reuse or edit the line. |
呼び出されたときに履歴リストから history (fc -l) コマンドを削除します。 コマンドは、次のコマンドが消滅する前に入力されるまで内部履歴に残り、ラインを簡単に再利用または編集できることに注意してください。 — |
|
HIST_NO_FUNCTIONS | Remove function definitions from the history list. Note that the function lingers in the internal history until the next command is entered before it vanishes, allowing you to briefly reuse or edit the definition. |
履歴リストから関数定義を削除します。 関数は、次のコマンドが消滅する前に入力されるまで内部履歴に残り、定義を簡単に再利用または編集できることに注意してください。 |
先頭のスペースはじまりのコマンドを履歴に残さない…🤔
$ echo 'setopt HIST_IGNORE_SPACE' >> ~/.zshrc $ . ~/.zshrc
設定 (.zlonout)
ssh ログアウト時にスクリーンをクリアしない
$ bat /etc/zlogout
1 # 2 # 3 # /etc/zlogout and ~/.zlogout are run when an interactive session ends 4 # 5 # 6 7 command -v clear &> /dev/null && clear
ログアウト時の /etc/zlogout 読み取りを無効にして、自分の ~/.zlogout ファイルでオーバーライドできる😉
$ echo 'setopt norcs' >> ~/.zlogout
zsh と bash の共通構成ファイル - ~/.commonshrc
この設定を先にしておかないと、bash 環境で追加設定したものが zsh に切り替えた後に、使用できなくなっていることに気が付きます😅
~/.bashrc
と ~/.zshrc
に共通の構成ファイルを読み込むようにする🤔
- ~/.bashrc
if [ -f ~/.commonshrc ]; then . ~/.commonshrc fi
- ~/.zshrc
if [ -f ~/.commonshrc ]; then . ~/.commonshrc fi
共通の構成は ~/.commonshrc
に書く✍ようにする🤔
- ~/.commonshrc
# >>> mamba initialize >>> # !! Contents within this block are managed by 'mamba init' !! export MAMBA_EXE="/home/tomoyan/.local/bin/micromamba"; export MAMBA_ROOT_PREFIX="/home/tomoyan/micromamba"; __mamba_setup="$("$MAMBA_EXE" shell hook --shell bash --prefix "$MAMBA_ROOT_PREFIX" 2> /dev/null)" if [ $? -eq 0 ]; then eval "$__mamba_setup" else if [ -f "/home/tomoyan/micromamba/etc/profile.d/micromamba.sh" ]; then . "/home/tomoyan/micromamba/etc/profile.d/micromamba.sh" else export PATH="/home/tomoyan/micromamba/bin:$PATH" # extra space after export prevents interference from conda init fi fi unset __mamba_setup # <<< mamba initialize <<< # anyenv export PATH="$HOME/.anyenv/bin:$PATH" eval "$(anyenv init -)" # cargo . "$HOME/.cargo/env"
デフォルト シェルの変更
デフォルトを zsh に変更する場合🤔
$ chsh -s $(which zsh)
デフォルトを bash に変更する場合🤔
$ chsh -s $(which bash)
tomoyan のシェルを変更します。 パスワード: ************ シェルを変更しました。
$ bash -l
chsh
コマンドが見つからない場合🤔
$ chsh -s $(which zsh)
-bash: chsh: コマンドが見つかりません
util-linux-user パッケージをインストールする😉
$ dnf provides chsh
メタデータの期限切れの最終確認: 0:00:23 時間前の 2023年09月23日 01時23分36秒 に実施しました。
util-linux-user-2.38.1-1.fc37.x86_64 : util-linux utilities based on libuser
Repo : fedora
一致:
ファイル名 : /usr/bin/chsh
$ sudo dnf install util-linux-user
メタデータの期限切れの最終確認: 1:36:50 時間前の 2023年09月22日 23時53分44秒 に実施しました。
依存関係が解決しました。
==============================================================================================================
パッケージ アーキテクチャー バージョン リポジトリー サイズ
==============================================================================================================
インストール:
util-linux-user x86_64 2.38.1-1.fc37 fedora 30 k
トランザクションの概要
==============================================================================================================
インストール 1 パッケージ
ダウンロードサイズの合計: 30 k
インストール後のサイズ: 60 k
これでよろしいですか? [y/N]: y
パッケージのダウンロード:
util-linux-user-2.38.1-1.fc37.x86_64.rpm 265 kB/s | 30 kB 00:00
--------------------------------------------------------------------------------------------------------------
合計 71 kB/s | 30 kB 00:00
トランザクションの確認を実行中
トランザクションの確認に成功しました。
トランザクションのテストを実行中
トランザクションのテストに成功しました。
トランザクションを実行中
準備 : 1/1
インストール中 : util-linux-user-2.38.1-1.fc37.x86_64 1/1
scriptletの実行中: util-linux-user-2.38.1-1.fc37.x86_64 1/1
検証 : util-linux-user-2.38.1-1.fc37.x86_64 1/1
インストール済み:
util-linux-user-2.38.1-1.fc37.x86_64
完了しました!
テーマ
Oh My Zsh テーマギャラリー
Themes · ohmyzsh/ohmyzsh Wiki 翻訳
Ubunly ZSH Theme
alejandromume/ubunly-zsh-theme: The new Kali Linux console bringed to Ubuntu 翻訳
ubunly のテーマをクローンする🤔
$ mkdir ~/work && cd ~/work $ git clone --depth 1 https://github.com/alejandromume/ubunly-zsh-theme.git
Cloning into 'ubunly-zsh-theme'... remote: Enumerating objects: 6, done. remote: Counting objects: 100% (6/6), done. remote: Compressing objects: 100% (6/6), done. remote: Total 6 (delta 0), reused 2 (delta 0), pack-reused 0 Receiving objects: 100% (6/6), 5.48 KiB | 5.48 MiB/s, done.
テーマをインストールする🤔
$ cd ubunly-zsh-theme $ chmod +x INSTALL.sh $ ./INSTALL.sh
[-] Installing Theme... ╔══════════════════════════════════════════════════════════════════════════════╗ ║ Remeber to add zsh-autosuggestions and zsh-syntax-highlighting to your plugins ║ ╚══════════════════════════════════════════════════════════════════════════════╝ [sudo] tomoyan のパスワード: [✱] Ubunly ZSH Theme Installed successfully! ╔══════════════════════════════════════════╗ ║ Set ubunly as ZSH_THEME in your .zshrc ║ ╚══════════════════════════════════════════╝
~/.zshrc
の設定でテーマを ubunly
に変更する🤔
$ nano ~/.zshrc
- ~/.zshrc
# If you come from bash you might have to change your $PATH. # export PATH=$HOME/bin:/usr/local/bin:$PATH # Path to your oh-my-zsh installation. export ZSH="$HOME/.oh-my-zsh" # Set name of the theme to load --- if set to "random", it will # load a random theme each time oh-my-zsh is loaded, in which case, # to know which specific one was loaded, run: echo $RANDOM_THEME # See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes #ZSH_THEME="robbyrussell" ZSH_THEME="ubunly"
zsh の設定を反映させる😊
$ . ~/.zshrc
┌──(tomoyan WICKED-BEAT)-[~/work/ubunly-zsh-theme]
└─$
Fedoly ZSH Theme (Ubunly カスタム Fedora theme 😅)
ubunly.zsh-theme をコピーして fedoly.zsh-theme に修正する…🤔
$ cp ~/.oh-my-zsh/custom/themes/ubunly.zsh-theme ~/.oh-my-zsh/custom/themes/fedoly.zsh-theme $ nano ~/.oh-my-zsh/custom/themes/fedoly.zsh-theme $ diff -u ~/.oh-my-zsh/custom/themes/ubunly.zsh-theme ~/.oh-my-zsh/custom/themes/fedoly.zsh-theme | bat --style changes -l diff
--- /home/tomoyan/.oh-my-zsh/custom/themes/ubunly.zsh-theme 2023-07-05 04:40:11.485903200 +0900 +++ /home/tomoyan/.oh-my-zsh/custom/themes/fedoly.zsh-theme 2024-04-21 16:36:59.088333447 +0900 @@ -77,7 +77,7 @@ fi if [ "$color_prompt" = yes ]; then - PROMPT=$'%F{%(#.blue.214)}┌──${debian_chroot:+($debian_chroot)──}(%B%F{%(#.red.202)}%n%(#.💀. )%m%b%F {%(#.orange.214)})-[%B%F{reset}%(6~.%-1~/…/%4~.%5~)%b%F{%(#.blue.214)}]\n└─%B%(#.%F{red}#.%F{208}$)%b%F{rese t} ' + PROMPT=$'%F{%(#.057.051)}┌──${debian_chroot:+($debian_chroot)──}(%B%F{%(#.red.033)}%n%(#. 💀 . )%m%b %F{%(#.057.051)})-[%B%F{reset}%(6~.%-1~/…/%4~.%5~)%b%F{%(#.057.051)}]\n└─%B%(#.%F{red}#.%F{033}$)%b%F{reset } ' RPROMPT=$'%(?.. %? %F{red}%B⨯%b%F{reset})%(1j. %j %F{yellow}%B⚙%b%F{reset}.)' # enable syntax-highlighting
PROMPT=$'%F{%(#.057.051)}┌──${debian_chroot:+($debian_chroot)──}(%B%F{%(#.red.033)}%n%(#. 💀 . )%m%b%F{%(#.057.051)})-[%B%F{reset}%(6~.%-1~/…/%4~.%5~)%b%F{%(#.057.051)}]\n└─%B%(#.%F{red}#.%F{033}$)%b%F{reset} '
テーマを ZSH_THEME=“fedoly” に変更する🤔
$ nano ~/.zshrc
# Set name of the theme to load --- if set to "random", it will # load a random theme each time oh-my-zsh is loaded, in which case, # to know which specific one was loaded, run: echo $RANDOM_THEME # See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes #ZSH_THEME="robbyrussell" ZSH_THEME="fedoly"
zsh の設定を反映させる😉
$ . ~/.zshrc
┌──(tomoyan WICKED-BEAT)-[~] └─$
┌──(root 💀 WICKED-BEAT)-[~] └─#
$ curl -L https://www.tomoyan.net/_media/linux/zsh/fedoly.zsh-theme -o ~/.oh-my-zsh/custom/fedoly.zsh-theme $ nano ~/.zshrc $ . ~/.zshrc
OS ロゴの検索
Xterm 256color chart
参考
参考: What color codes can I use in my Bash PS1 prompt? - Unix & Linux Stack Exchange 翻訳
How can I change the color of my prompt in zsh (different from normal text)? - Stack Overflow 翻訳
Dietly ZSH Theme (Ubunly カスタム DietPi theme 😅)
ubunly.zsh-theme をコピーして dietly.zsh-theme に修正する…🤔
$ cp ~/.oh-my-zsh/custom/themes/ubunly.zsh-theme ~/.oh-my-zsh/custom/themes/dietly.zsh-theme $ nano ~/.oh-my-zsh/custom/themes/dietly.zsh-theme $ diff -u ~/.oh-my-zsh/custom/themes/ubunly.zsh-theme ~/.oh-my-zsh/custom/themes/dietly.zsh-theme | bat --style changes -l diff
--- /home/dietpi/.oh-my-zsh/custom/themes/ubunly.zsh-theme 2023-08-08 04:19:56.183862288 +0900 +++ /home/dietpi/.oh-my-zsh/custom/themes/dietly.zsh-theme 2024-04-22 06:34:35.501186304 +0900 @@ -77,7 +77,7 @@ fi if [ "$color_prompt" = yes ]; then - PROMPT=$'%F{%(#.blue.214)}┌──${debian_chroot:+($debian_chroot)──}(%B%F{%(#.red.202)}%n%(#.💀. )%m%b%F {%(#.orange.214)})-[%B%F{reset}%(6~.%-1~/…/%4~.%5~)%b%F{%(#.blue.214)}]\n└─%B%(#.%F{red}#.%F{208}$)%b%F{rese t} ' + PROMPT=$'%F{%(#.blue.156)}┌──${debian_chroot:+($debian_chroot)──}(%B%F{%(#.red.154)}%n%(#. 💀 . )%m%b %F{%(#.orange.156)})-[%B%F{reset}%(6~.%-1~/…/%4~.%5~)%b%F{%(#.blue.156)}]\n└─%B%(#.%F{red}#.%F{154}$)%b%F{re set} ' RPROMPT=$'%(?.. %? %F{red}%B⨯%b%F{reset})%(1j. %j %F{yellow}%B⚙%b%F{reset}.)' # enable syntax-highlighting
テーマを ZSH_THEME=“dietly” に変更する🤔
$ nano ~/.zshrc
# Set name of the theme to load --- if set to "random", it will # load a random theme each time oh-my-zsh is loaded, in which case, # to know which specific one was loaded, run: echo $RANDOM_THEME # See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes #ZSH_THEME="robbyrussell" ZSH_THEME="dietly"
zsh の設定を反映させる😉
$ . ~/.zshrc
┌──(dietpi dietpi-001)-[~] └─$
┌──(root 💀 dietpi-001)-[~] └─#
キーバインディング
参考: questions/1056394/in-bash-how-does-one-clear-the-current-input 翻訳
A User's Guide to the Z-Shell
バインディング | 説明 |
---|---|
Ctrl + A | 行の先頭に移動する |
Ctrl + E | 行の最終に移動する |
|
|
Ctrl + C | 入力しているものを中止する |
|
|
Ctrl + L | 画面をクリアする |
|
|
Ctrl + U | 行全体をバッファに切り取る |
Ctrl + Y | バッファから貼り付ける |
|
|
Ctrl + R | 歴史の検索する |
Ctrl + P | 歴史の以前のアイテムに移動する |
Ctrl + N | 歴史の次のアイテムに移動する |
|
|
Ctrl + W | カーソルからワードバックを削除する |
定義一覧 - [bindkey -L]
現在の定義を確認する…🤔
$ bindkey -L | bat -p -l sh --pager no
bindkey "^@" set-mark-command bindkey "^A" beginning-of-line bindkey "^B" backward-char bindkey "^D" delete-char-or-list bindkey "^E" end-of-line bindkey "^F" forward-char bindkey "^G" send-break bindkey "^H" backward-delete-char bindkey "^I" expand-or-complete bindkey "^J" accept-line bindkey "^K" kill-line bindkey "^L" clear-screen bindkey "^M" accept-line bindkey "^N" down-line-or-history bindkey "^O" accept-line-and-down-history bindkey "^P" up-line-or-history bindkey "^Q" push-line bindkey "^R" history-incremental-search-backward bindkey "^S" history-incremental-search-forward bindkey "^T" transpose-chars bindkey "^U" kill-whole-line bindkey "^V" quoted-insert bindkey "^W" backward-kill-word bindkey "^X^B" vi-match-bracket bindkey "^X^E" edit-command-line bindkey "^X^F" vi-find-next-char bindkey "^X^J" vi-join bindkey "^X^K" kill-buffer bindkey "^X^N" infer-next-history bindkey "^X^O" overwrite-mode bindkey "^X^R" _read_comp bindkey "^X^U" undo bindkey "^X^V" vi-cmd-mode bindkey "^X^X" exchange-point-and-mark bindkey "^X*" expand-word bindkey "^X=" what-cursor-position bindkey "^X?" _complete_debug bindkey "^XC" _correct_filename bindkey "^XG" list-expand bindkey "^Xa" _expand_alias bindkey "^Xc" _correct_word bindkey "^Xd" _list_expansions bindkey "^Xe" _expand_word bindkey "^Xg" list-expand bindkey "^Xh" _complete_help bindkey "^Xm" _most_recent_file bindkey "^Xn" _next_tags bindkey "^Xr" history-incremental-search-backward bindkey "^Xs" history-incremental-search-forward bindkey "^Xt" _complete_tag bindkey "^Xu" undo bindkey "^X~" _bash_list-choices bindkey "^Y" yank bindkey "^[^D" list-choices bindkey "^[^G" send-break bindkey "^[^H" backward-kill-word bindkey "^[^I" self-insert-unmeta bindkey "^[^J" self-insert-unmeta bindkey "^[^L" clear-screen bindkey "^[^M" self-insert-unmeta bindkey "^[^_" copy-prev-word bindkey "^[ " expand-history bindkey "^[!" expand-history bindkey "^[\"" quote-region bindkey "^[\$" spell-word bindkey "^['" quote-line bindkey "^[," _history-complete-newer bindkey "^[-" neg-argument bindkey "^[." insert-last-word bindkey "^[/" _history-complete-older bindkey "^[0" digit-argument bindkey "^[1" digit-argument bindkey "^[2" digit-argument bindkey "^[3" digit-argument bindkey "^[4" digit-argument bindkey "^[5" digit-argument bindkey "^[6" digit-argument bindkey "^[7" digit-argument bindkey "^[8" digit-argument bindkey "^[9" digit-argument bindkey "^[<" beginning-of-buffer-or-history bindkey "^[>" end-of-buffer-or-history bindkey "^[?" which-command bindkey "^[A" accept-and-hold bindkey "^[B" backward-word bindkey "^[C" capitalize-word bindkey "^[D" kill-word bindkey "^[F" forward-word bindkey "^[G" get-line bindkey "^[H" run-help bindkey "^[L" down-case-word bindkey "^[N" history-search-forward bindkey "^[OA" up-line-or-beginning-search bindkey "^[OB" down-line-or-beginning-search bindkey "^[OC" forward-char bindkey "^[OD" backward-char bindkey "^[OF" end-of-line bindkey "^[OH" beginning-of-line bindkey "^[P" history-search-backward bindkey "^[Q" push-line bindkey "^[S" spell-word bindkey "^[T" transpose-words bindkey "^[U" up-case-word bindkey "^[W" copy-region-as-kill bindkey "^[[1;5C" forward-word bindkey "^[[1;5D" backward-word bindkey "^[[200~" bracketed-paste bindkey "^[[3;5~" kill-word bindkey "^[[3~" delete-char bindkey "^[[5~" beginning-of-buffer-or-history bindkey "^[[6~" end-of-buffer-or-history bindkey "^[[A" up-line-or-beginning-search bindkey "^[[B" down-line-or-beginning-search bindkey "^[[C" forward-word bindkey "^[[D" backward-word bindkey "^[[Z" undo bindkey "^[_" insert-last-word bindkey "^[a" accept-and-hold bindkey "^[b" backward-word bindkey "^[c" capitalize-word bindkey "^[d" kill-word bindkey "^[f" forward-word bindkey "^[g" get-line bindkey "^[h" run-help bindkey -s "^[l" "ls^J" bindkey "^[m" copy-prev-shell-word bindkey "^[n" history-search-forward bindkey "^[p" history-search-backward bindkey "^[q" push-line bindkey "^[s" spell-word bindkey "^[t" transpose-words bindkey "^[u" up-case-word bindkey "^[w" kill-region bindkey "^[x" execute-named-cmd bindkey "^[y" yank-pop bindkey "^[z" execute-last-named-cmd bindkey "^[|" vi-goto-column bindkey "^[~" _bash_complete-word bindkey "^[^?" backward-kill-word bindkey "^_" undo bindkey " " magic-space bindkey -R "!"-"~" self-insert bindkey "^?" backward-delete-char bindkey -R "\M-^@"-"\M-^?" self-insert
トラブルシューティング
Fedora アップグレード後に argcomplete モジュールがインポートエラーを起こす...😇
Traceback (most recent call last): File "/home/tomoyan/.local/bin/register-python-argcomplete", line 29, in <module> import argcomplete ModuleNotFoundError: No module named 'argcomplete'
python3-argcomplete をインストールすると直る😉
$ sudo dnf install python3-argcomplete -y
リポジトリの更新を読み込み中: RPM Fusion for Fedora 41 - Nonfree - Updates 100% | 22.7 KiB/s | 17.0 KiB | 00m01s Remi's RPM repository - Fedora 41 - x86_64 100% | 4.1 KiB/s | 4.7 KiB | 00m01s Fedora 41 - x86_64 - Updates 100% | 7.9 KiB/s | 7.4 KiB | 00m01s Copr repo for dotnet owned by @dotnet-sig 100% | 1.2 KiB/s | 1.5 KiB | 00m01s packages-microsoft-com-prod 100% | 11.9 KiB/s | 1.5 KiB | 00m00s RPM Fusion for Fedora 41 - Free - Updates 100% | 14.3 KiB/s | 12.4 KiB | 00m01s Remi's Modular repository - Fedora 41 - x86_64 100% | 4.7 KiB/s | 5.2 KiB | 00m01s RPM Fusion for Fedora 41 - Nonfree - Updates 100% | 28.6 KiB/s | 54.5 KiB | 00m02s Remi's RPM repository - Fedora 41 - x86_64 100% | 279.6 KiB/s | 418.5 KiB | 00m01s Fedora 41 - x86_64 - Updates 100% | 3.1 MiB/s | 3.5 MiB | 00m01s packages-microsoft-com-prod 100% | 795.4 KiB/s | 320.6 KiB | 00m00s RPM Fusion for Fedora 41 - Free - Updates 100% | 33.9 KiB/s | 51.7 KiB | 00m02s Remi's Modular repository - Fedora 41 - x86_64 100% | 151.1 KiB/s | 218.2 KiB | 00m01s リポジトリを読み込みました。 Package Arch Version Repository Size Installing: python3-argcomplete noarch 3.5.3-1.fc41 updates 314.0 KiB Transaction Summary: Installing: 1 package パッケージサイズ 97 KiB 、ダウンロードサイズ 97 KiB 。 完了後、314 KiB のサイズが利用されます(インストール 314 KiB、削除 0 B)。 [1/1] python3-argcomplete-0:3.5.3-1.fc41.noarch 100% | 1.0 MiB/s | 97.3 KiB | 00m00s -------------------------------------------------------------------------------------------------------------- [1/1] Total 100% | 268.0 KiB/s | 97.3 KiB | 00m00s トランザクションを実行中 [1/3] パッケージ ファイルを検証 100% | 250.0 B/s | 1.0 B | 00m00s [2/3] トランザクションの準備 100% | 2.0 B/s | 1.0 B | 00m00s [3/3] インストール中 python3-argcomplete-0:3.5.3-1.fc41.noarch 100% | 214.1 KiB/s | 327.8 KiB | 00m02s 完了しました!
参考文献
How to install ZSH on Fedora🚀 翻訳
Dotfiles - Shared Config for ZSH and Bash - DEV Community 翻訳
bashとzshの違い。bashからの乗り換えで気をつけるべき16の事柄
macos - ZSH: .zprofile, .zshrc, .zlogin - What goes where? - Ask Different 翻訳
terminal - What ZSH theme does Kali use? - Unix & Linux Stack Exchange 翻訳
zsh compinit: insecure directories and files on macos catalina when using sudo · Issue #680 · zsh-users/zsh-completions 翻訳
autocomplete - zsh: command not found: {compinstall,compinit,compdef} - Unix & Linux Stack Exchange 翻訳
In bash, how does one clear the current input? - Stack Overflow翻訳