From 6dedddc545e2f1930bdc2256784eb1551bd4231d Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 1 Feb 2026 00:49:15 +0900 Subject: feat(nuldoc): rewrite nuldoc in Ruby --- .../index.html | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'services/nuldoc/public/blog/posts/2024-04-29') diff --git a/services/nuldoc/public/blog/posts/2024-04-29/zsh-file-completion-for-composer-custom-commands/index.html b/services/nuldoc/public/blog/posts/2024-04-29/zsh-file-completion-for-composer-custom-commands/index.html index 39ccf3a6..4ef3d064 100644 --- a/services/nuldoc/public/blog/posts/2024-04-29/zsh-file-completion-for-composer-custom-commands/index.html +++ b/services/nuldoc/public/blog/posts/2024-04-29/zsh-file-completion-for-composer-custom-commands/index.html @@ -116,11 +116,12 @@ このことは、先ほどリンクを載せた _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
+
@@ -138,7 +139,8 @@ まずは、Zsh で補完関数を提供する場合のボイラープレートコードを書く。以下は ~/.zshrc にすべて書く前提だが、autoload を設定するなどすれば別ファイルに分離できる (詳細な手順は割愛)。

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

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

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

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