両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン |
linux:zsh [2025/02/15 11:01] – [設定 (.zshrc)] ともやん | linux:zsh [2025/04/06 11:00] (現在) – [Fedora アップグレード後に argcomplete モジュールがインポートエラーを起こす...😇] ともやん |
---|
本家: [[https://www.zsh.org|Zsh - zsh.org]]\\ | 本家: [[https://www.zsh.org|Zsh - zsh.org]]\\ |
ソースコード: [[sf1>zsh/code/ci/master/tree/|zsh / Code - sourceforge.net]]\\ | ソースコード: [[sf1>zsh/code/ci/master/tree/|zsh / Code - sourceforge.net]]\\ |
| ドキュメント: [[sfio>zsh.sourceforge.io/Doc/]] |
| |
**Z shell (Zsh)** は、対話型ログインシェルとして、またシェル スクリプトのコマンド インタープリタとして使用できる Unix シェルである。Zsh は、Bash、ksh、および tcsh のいくつかの機能を含む、多くの改良が施された拡張 Bourne シェルである。\\ | **Z shell (Zsh)** は、対話型ログインシェルとして、またシェル スクリプトのコマンド インタープリタとして使用できる Unix シェルである。Zsh は、Bash、ksh、および tcsh のいくつかの機能を含む、多くの改良が施された拡張 Bourne シェルである。\\ |
</pre></html></WRAP> | </pre></html></WRAP> |
</WRAP> | </WRAP> |
| |
| <WRAP round tip 90%> |
| === サイレント インストールするには...🤔 === |
| <WRAP color_term> |
| <WRAP color_command><html><pre> |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269">curl</font> <font color="#A347BA">-fsSL</font> https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh <font color="#2A7BDE"><b>|</b></font> <font color="#26A269">bat</font> <font color="#A347BA">-p</font> <font color="#A347BA">--pager</font> no |
| </pre></html></WRAP> |
| <WRAP color_mincode_hlong><html><pre> |
| <font color="#7C7865">#!/bin/sh</font> |
| <font color="#7C7865">#</font> |
| <font color="#7C7865"># This script should be run via curl:</font> |
| <font color="#7C7865"># sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"</font> |
| <font color="#7C7865"># or via wget:</font> |
| <font color="#7C7865"># sh -c "$(wget -qO- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"</font> |
| <font color="#7C7865"># or via fetch:</font> |
| <font color="#7C7865"># sh -c "$(fetch -o - https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"</font> |
| <font color="#7C7865">#</font> |
| <font color="#7C7865"># As an alternative, you can first download the install script and run it afterwards:</font> |
| <font color="#7C7865"># wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh</font> |
| <font color="#7C7865"># sh install.sh</font> |
| <font color="#7C7865">#</font> |
| <font color="#7C7865"># You can tweak the install behavior by setting variables when running the script. For</font> |
| <font color="#7C7865"># example, to change the path to the Oh My Zsh repository:</font> |
| <font color="#7C7865"># ZSH=~/.zsh sh install.sh</font> |
| <font color="#7C7865">#</font> |
| <font color="#7C7865"># Respects the following environment variables:</font> |
| <font color="#7C7865"># ZDOTDIR - path to Zsh dotfiles directory (default: unset). See [1][2]</font> |
| <font color="#7C7865"># [1] https://zsh.sourceforge.io/Doc/Release/Parameters.html#index-ZDOTDIR</font> |
| <font color="#7C7865"># [2] https://zsh.sourceforge.io/Doc/Release/Files.html#index-ZDOTDIR_002c-use-of</font> |
| <font color="#7C7865"># ZSH - path to the Oh My Zsh repository folder (default: $HOME/.oh-my-zsh)</font> |
| <font color="#7C7865"># REPO - name of the GitHub repo to install from (default: ohmyzsh/ohmyzsh)</font> |
| <font color="#7C7865"># REMOTE - full remote URL of the git repo to install (default: GitHub via HTTPS)</font> |
| <font color="#7C7865"># BRANCH - branch to check out immediately after install (default: master)</font> |
| <font color="#7C7865">#</font> |
| <font color="#7C7865"># Other options:</font> |
| <font color="#7C7865"># CHSH - 'no' means the installer will not change the default shell (default: yes)</font> |
| <font color="#7C7865"># RUNZSH - 'no' means the installer will not run zsh after the install (default: yes)</font> |
| <font color="#7C7865"># KEEP_ZSHRC - 'yes' means the installer will not replace an existing .zshrc (default: no)</font> |
| <font color="#7C7865">#</font> |
| <font color="#7C7865"># You can also pass some arguments to the install script to set some these options:</font> |
| <font color="#7C7865"># --skip-chsh: has the same behavior as setting CHSH to 'no'</font> |
| <font color="#7C7865"># --unattended: sets both CHSH and RUNZSH to 'no'</font> |
| <font color="#7C7865"># --keep-zshrc: sets KEEP_ZSHRC to 'yes'</font> |
| <font color="#7C7865"># For example:</font> |
| <font color="#7C7865"># sh install.sh --unattended</font> |
| <font color="#7C7865"># or:</font> |
| <font color="#7C7865"># sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended</font> |
| <font color="#7C7865">#</font> |
| </pre></html></WRAP> |
| </WRAP> |
| |
| ''%%--unattended%%'' オプションを付けて実行する😉\\ |
| <WRAP color_term> |
| <WRAP color_command><html><pre> |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269">sh</font> <font color="#A347BA">-c</font> <font color="#A2734C">"</font><font color="#A347BA">$</font><font color="#2A7BDE"><b>(</b></font><font color="#26A269">curl</font> <font color="#A347BA">-fsSL</font> https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh<font color="#2A7BDE"><b>)</b></font><font color="#A2734C">"</font> <font color="#A2734C">""</font> <font color="#A347BA">--unattended</font> |
| </pre></html></WRAP> |
| </WRAP> |
| |
| </WRAP> |
| |
===== 実行 ===== | ===== 実行 ===== |
<html><style> | <html><style> |
</WRAP> | </WRAP> |
| |
===== zsh と bash の共通構成ファイル - ~/.commonshrc ===== | ===== 設定 (.zshrc) ===== |
| |
| ==== コマンドを履歴に残さない ==== |
| 参考: [[https://unix.stackexchange.com/questions/6094/is-there-any-way-to-keep-a-command-from-being-added-to-your-history|bash - Is there any way to keep a command from being added to your history? - Unix & Linux Stack Exchange]]\\ |
| [[https://zsh.sourceforge.io/Doc/Release/Options.html#Description-of-Options|zsh: 16 Options]]\\ |
| |
| <WRAP mintbl> |
| ^ オプション ^ 説明 ^ |
| | 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. | |
| | ::: | 履歴リストから関数定義を削除します。\\ 関数は、次のコマンドが消滅する前に入力されるまで内部履歴に残り、定義を簡単に再利用または編集できることに注意してください。 | |
| </WRAP> |
| |
| **先頭のスペースはじまりのコマンドを履歴に残さない...🤔**\\ |
| <WRAP color_term> |
| <WRAP color_command><html><pre> |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269">echo</font><font color="#FF9999"> </font><font color="#A2734C">'setopt HIST_IGNORE_SPACE'</font><font color="#FF9999"> </font><font color="#12488B"><b>>></b></font><font color="#FF9999"> </font><font color="#FF9999"><u style="text-decoration-style:solid">~/.zshrc</u></font> |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269">.</font> <u style="text-decoration-style:solid">~/.zs</u><font color="#999999"><u style="text-decoration-style:solid">hrc</u></font> |
| </pre></html></WRAP> |
| </WRAP> |
| |
| ===== 設定 (.zlonout) ===== |
| |
| ==== ssh ログアウト時にスクリーンをクリアしない === |
| 参考: [[https://unix.stackexchange.com/questions/70955/preventing-the-screen-from-being-cleared-when-exiting-an-ssh-session|zsh - preventing the screen from being cleared when exiting an ssh session - Unix & Linux Stack Exchange]]\\ |
| |
| <WRAP color_term> |
| <WRAP color_command><html><pre> |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269">bat</font> <u style="text-decoration-style:solid">/etc/zlogout</u> |
| </pre></html></WRAP> |
| <WRAP color_result><html><pre> |
| <font color="#444444"> 1</font> <font color="#FFFFFF">#</font> |
| <font color="#444444"> 2</font> <font color="#FFFFFF">#</font> |
| <font color="#444444"> 3</font> <font color="#FFFFFF"># /etc/zlogout and ~/.zlogout are run when an interactive session ends</font> |
| <font color="#444444"> 4</font> <font color="#FFFFFF">#</font> |
| <font color="#444444"> 5</font> <font color="#FFFFFF">#</font> |
| <font color="#444444"> 6</font> |
| <font color="#444444"> 7</font> <font color="#FFFFFF">command -v clear &> /dev/null && clear</font> |
| </pre></html></WRAP> |
| </WRAP> |
| |
| ログアウト時の /etc/zlogout 読み取りを無効にして、自分の ~/.zlogout ファイルでオーバーライドできる😉\\ |
| <WRAP color_term> |
| <WRAP color_command><html><pre> |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269">echo</font><font color="#999999"> </font><font color="#A2734C">'setopt norcs'</font><font color="#999999"> </font><font color="#12488B"><b>>></b></font><font color="#999999"> </font><font color="#999999"><u style="text-decoration-style:solid">~/.zlogout</u></font> |
| </pre></html></WRAP> |
| </WRAP> |
| |
| ==== zsh と bash の共通構成ファイル - ~/.commonshrc ==== |
<wrap em>__この設定を先にしておかないと、bash 環境で追加設定したものが zsh に切り替えた後に、使用できなくなっていることに気が付きます😅__</wrap>\\ | <wrap em>__この設定を先にしておかないと、bash 環境で追加設定したものが zsh に切り替えた後に、使用できなくなっていることに気が付きます😅__</wrap>\\ |
| |
<WRAP color_mincode><code bash ~/.bashrc> | <WRAP color_mincode><code bash ~/.bashrc> |
if [ -f ~/.commonshrc ]; then | if [ -f ~/.commonshrc ]; then |
. ~/.commonshrc | . ~/.commonshrc |
fi | fi |
</code></WRAP> | </code></WRAP> |
<WRAP color_mincode><code bash ~/.zshrc> | <WRAP color_mincode><code bash ~/.zshrc> |
if [ -f ~/.commonshrc ]; then | if [ -f ~/.commonshrc ]; then |
. ~/.commonshrc | . ~/.commonshrc |
fi | fi |
</code></WRAP> | </code></WRAP> |
| |
==== Fedoly ZSH Theme (Ubunly カスタム Fedora theme 😅) ==== | ==== Fedoly ZSH Theme (Ubunly カスタム Fedora theme 😅) ==== |
ubunly.zsh-theme をコピーして fedoly.zsh-theme に修正する...🤔\\ | ubunly.zsh-theme をコピーして fedoly.zsh-theme を修正する...🤔\\ |
<WRAP color_term> | <WRAP color_term> |
<WRAP color_command><html><pre> | <WRAP color_command><html><pre> |
<font color="#0087FF"><b>$</b></font> <font color="#26A269">cp</font><font color="#FF9999"> </font><font color="#FF9999"><u style="text-decoration-style:single">~/.oh-my-zsh/custom/themes/ubunly.zsh-theme</u></font><font color="#FF9999"> </font><font color="#FF9999"><u style="text-decoration-style:single">~/.oh-my-zsh/custom/themes/fedoly.zsh-theme</u></font> | <font color="#0087FF"><b>$</b></font> <font color="#26A269">cp</font><font color="#999999"> </font><font color="#999999"><u style="text-decoration-style:solid">~/.oh-my-zsh/custom/themes/ubunly.zsh-theme</u></font><font color="#999999"> </font><font color="#999999"><u style="text-decoration-style:solid">~/.oh-my-zsh/custom/themes/fedoly.zsh-theme.new</u></font> |
<font color="#0087FF"><b>$</b></font> <font color="#26A269">nano</font> <u style="text-decoration-style:single">~/.oh-my-zsh/custom/themes/fedoly.zsh-theme</u> | <font color="#0087FF"><b>$</b></font> <font color="#26A269">nano</font> <u style="text-decoration-style:single">~/.oh-my-zsh/custom/themes/fedoly.zsh-theme.new</u> |
<font color="#0087FF"><b>$</b></font> <font color="#26A269">diff</font> <font color="#A347BA">-u</font> <u style="text-decoration-style:single">~/.oh-my-zsh/custom/themes/ubunly.zsh-theme</u> <u style="text-decoration-style:single">~/.oh-my-zsh/custom/themes/fedoly.zsh-theme</u> <font color="#12488B"><b>|</b></font> <font color="#26A269">bat</font> <font color="#A347BA">--style</font> changes <font color="#A347BA">-l</font> diff | <font color="#0087FF"><b>$</b></font> <font color="#26A269">cp</font><font color="#999999"> </font><font color="#999999"><u style="text-decoration-style:solid">~/.oh-my-zsh/custom/themes/ubunly.zsh-theme</u></font><font color="#999999"> </font><font color="#999999"><u style="text-decoration-style:solid">~/.oh-my-zsh/custom/themes/fedoly.zsh-theme</u></font> |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269">diff</font> <font color="#A347BA">-u</font> <u style="text-decoration-style:solid">~/.oh-my-zsh/custom/themes/fedoly.zsh-theme</u> <u style="text-decoration-style:solid">~/.oh-my-zsh/custom/themes/fedoly.zsh-theme.new</u> <font color="#2A7BDE"><b>|</b></font> <font color="#26A269">bat</font> <font color="#A347BA">--style</font> plain <font color="#A347BA">-l</font> diff |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_result><html><pre class=Bat> | <WRAP color_result><html><pre> |
<font color="#75715E">--- /home/tomoyan/.oh-my-zsh/custom/themes/ubunly.zsh-theme 2023-07-05 04:40:11.485903200 +0900</font> | <font color="#75715E">--- /home/tomoyan/.oh-my-zsh/custom/themes/fedoly.zsh-theme</font> <font color="#75715E">2025-03-30 08:41:46.993230434 +0900</font> |
<font color="#75715E">+++ /home/tomoyan/.oh-my-zsh/custom/themes/fedoly.zsh-theme 2024-04-21 16:36:59.088333447 +0900</font> | <font color="#75715E">+++ /home/tomoyan/.oh-my-zsh/custom/themes/fedoly.zsh-theme.new</font> <font color="#75715E">2025-03-30 08:40:45.436946033 +0900</font> |
<font color="#3BC0F0">@@ -77,7 +77,7 @@</font> | <font color="#3BC0F0">@@ -77,7 +77,7 @@</font> |
<font color="#F8F8F2"> fi</font> | <font color="#F8F8F2"> fi</font> |
<font color="#F8F8F2"> </font> | <font color="#F8F8F2"> </font> |
<font color="#F8F8F2"> if [ "$color_prompt" = yes ]; then</font> | <font color="#F8F8F2"> if [ "$color_prompt" = yes ]; then</font> |
<font color="#F92672">- PROMPT=$'%F{%(#.blue.214)}┌──${debian_chroot:+($debian_chroot)──}(%B%F{%(#.red.202)}%n%(#.💀. )%m%b%F</font> | <font color="#F92672">- 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{reset} '</font> |
<font color="#F92672">{%(#.orange.214)})-[%B%F{reset}%(6~.%-1~/…/%4~.%5~)%b%F{%(#.blue.214)}]\n└─%B%(#.%F{red}#.%F{208}$)%b%F{rese</font> | <font color="#A6E22E">+ 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} '</font> |
<font color="#F92672">t} '</font> | <font color="#F8F8F2"> RPROMPT=$'%(?.. %? %F{red}%B⨯%b%F{reset})%(1j. %j %F{yellow}%B⚙%b%F{reset}.)'</font> |
<font color="#A6E22E">+ PROMPT=$'%F{%(#.057.051)}┌──${debian_chroot:+($debian_chroot)──}(%B%F{%(#.red.033)}%n%(#. 💀 . )%m%b</font> | <font color="#F8F8F2"> </font> |
<font color="#A6E22E">%F{%(#.057.051)})-[%B%F{reset}%(6~.%-1~/…/%4~.%5~)%b%F{%(#.057.051)}]\n└─%B%(#.%F{red}#.%F{033}$)%b%F{reset</font> | <font color="#F8F8F2"> # enable syntax-highlighting</font> |
<font color="#A6E22E">} '</font> | |
<font color="#F8F8F2"> RPROMPT=$'%(?.. %? %F{red}%B⨯%b%F{reset})%(1j. %j %F{yellow}%B⚙%b%F{reset}.)'</font> | |
<font color="#F8F8F2"> </font> | |
<font color="#F8F8F2"> # enable syntax-highlighting</font> | |
</pre></html></WRAP> | </pre></html></WRAP> |
<WRAP color_mincode><html><pre> | <WRAP color_command><html><pre> |
<font color="#A6E22E">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} '</font> | <font color="#0087FF"><b>$</b></font> <font color="#26A269">cd</font> <u style="text-decoration-style:solid">~</u> |
| <font color="#0087FF"><b>$</b></font> <font color="#26A269">patch</font> <font color="#A347BA">-u</font> <font color="#A347BA">-p3</font> <font color="#2A7BDE"><b><<</b></font> <font color="#A2734C">'EOF'</font> |
| <font color="#F66151"><b>---</b></font> <u style="text-decoration-style:solid">/home/tomoyan/.oh-my-zsh/custom/themes/fedoly.zsh-theme</u> 2025-03-19 06:34:56.931728677 +0900 |
| <font color="#F66151"><b>+++</b></font> <u style="text-decoration-style:solid">/home/tomoyan/.oh-my-zsh/custom/themes/fedoly.zsh-theme.new</u> 2025-03-30 07:57:28.297283583 +0900 |
| <font color="#F66151"><b>@@</b></font> <font color="#A347BA">-77,7</font> +77,7 @@ |
| <font color="#F66151"><b>fi</b></font> |
| |
| <font color="#33C7DE"><b>if</b></font> <font color="#2A7BDE"><b>[</b></font> <font color="#A2734C">"</font><font color="#A347BA">$color_prompt</font><font color="#A2734C">"</font> = yes <font color="#2A7BDE"><b>];</b></font> <font color="#33C7DE"><b>then</b></font> |
| <font color="#26A269">-</font> PROMPT=<font color="#A2734C">$'%F</font><font color="#2A7BDE"><b>{</b></font><font color="#A2734C">%</font><font color="#33D17A"><b>(</b></font><font color="#A2734C">#.blue.214</font><font color="#33D17A"><b>)</b></font><font color="#2A7BDE"><b>}</b></font><font color="#A2734C">┌──$</font><font color="#2A7BDE"><b>{</b></font><font color="#A2734C">debian_chroot:+</font><font color="#33D17A"><b>(</b></font><font color="#A2734C">$debian_chroot</font><font color="#33D17A"><b>)</b></font><font color="#A2734C">──</font><font color="#2A7BDE"><b>}(</b></font><font color="#A2734C">%B%F</font><font color="#33D17A"><b>{</b></font><font color="#A2734C">%</font><font color="#C061CB"><b>(</b></font><font color="#A2734C">#.red.202</font><font color="#C061CB"><b>)</b></font><font color="#33D17A"><b>}</b></font><font color="#A2734C">%n%</font><font color="#33D17A"><b>(</b></font><font color="#A2734C">#.💀. </font><font color="#33D17A"><b>)</b></font><font color="#A2734C">%m%b%F</font><font color="#33D17A"><b>{</b></font><font color="#A2734C">%</font><font color="#C061CB"><b>(</b></font><font color="#A2734C">#.orange.214</font><font color="#C061CB"><b>)</b></font><font color="#33D17A"><b>}</b></font><font color="#2A7BDE"><b>)</b></font><font color="#A2734C">-</font><font color="#2A7BDE"><b>[</b></font><font color="#A2734C">%B%F</font><font color="#33D17A"><b>{</b></font><font color="#A2734C">reset</font><font color="#33D17A"><b>}</b></font><font color="#A2734C">%</font><font color="#33D17A"><b>(</b></font><font color="#A2734C">6~.%-1~/…/%4~.%5~</font><font color="#33D17A"><b>)</b></font><font color="#A2734C">%b%F</font><font color="#33D17A"><b>{</b></font><font color="#A2734C">%</font><font color="#C061CB"><b>(</b></font><font color="#A2734C">#.blue.214</font><font color="#C061CB"><b>)</b></font><font color="# |