From d30dfc89bf1b673b2fdc0638766b930adaec228c Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 29 Mar 2025 00:47:55 +0900 Subject: feat(blog/nuldoc): migrate syntax highlighter from highlight.js to shiki.js --- .../index.html | 27 +++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'vhosts/blog/public/posts/2024-04-29') diff --git a/vhosts/blog/public/posts/2024-04-29/zsh-file-completion-for-composer-custom-commands/index.html b/vhosts/blog/public/posts/2024-04-29/zsh-file-completion-for-composer-custom-commands/index.html index 99216975..c1390ced 100644 --- a/vhosts/blog/public/posts/2024-04-29/zsh-file-completion-for-composer-custom-commands/index.html +++ b/vhosts/blog/public/posts/2024-04-29/zsh-file-completion-for-composer-custom-commands/index.html @@ -14,8 +14,7 @@ 【Zsh】 Composer のカスタムコマンドに対する Zsh 補完で引数にファイルを補完させる|REPL: Rest-Eat-Program Loop - - +
@@ -98,11 +97,13 @@ このことは、先ほどリンクを載せた _composer 関数を定義しているファイルの冒頭にも書かれている。

-
# - @todo We don't complete custom commands (including script aliases). This is
-#   easy to do in the general case, but it probably requires some clever caching
-#   to avoid introducing a noticeable lag to every completion operation, due to
-#   the way command resolution works and the fact that discovering custom
-#   commands requires making slow calls to Composer
+
+
# - @todo We don't complete custom commands (including script aliases). This is
+#   easy to do in the general case, but it probably requires some clever caching
+#   to avoid introducing a noticeable lag to every completion operation, due to
+#   the way command resolution works and the fact that discovering custom
+#   commands requires making slow calls to Composer
+
@@ -122,7 +123,9 @@ まずは、Zsh で補完関数を提供する場合のボイラープレートコードを書く。以下は ~/.zshrc にすべて書く前提だが、autoload を設定するなどすれば別ファイルに分離できる (詳細な手順は割愛)。

-
compdef _my_composer composer composer.phar
+
+
compdef _my_composer composer composer.phar
+

compdef は Zsh が用意している関数で、第一引数に補完関数の名前、第二引数以降に補完を適用するコマンド名を並べる。この場合は、composer コマンドや composer.phar コマンドに対して _my_composer を使って補完をおこなうよう定義している。 @@ -132,9 +135,11 @@ 次に _my_composer を定義する。基本的にはデフォルトの composer コマンドの補完関数 (つまり _composer 関数) を使い、それが何も返さなかった場合に限り、Zsh のファイル・ディレクトリ補完へフォールバックする。

-
function _my_composer() {
-    _composer "$@" || _files "$@"
-}
+
+
function _my_composer() {
+    _composer "$@" || _files "$@"
+}
+

_composer コマンドは何も補完候補がなかったとき非ゼロな exit status で終了するので、そうであったなら _files を呼び出す。_files は、Zsh がデフォルトで用意しているファイル・ディレクトリの補完をおこなう関数である。 -- cgit v1.2.3-70-g09d2