📢 Webサイト閉鎖と移転のお知らせ
このWebサイトは2026年9月に閉鎖いたします。
新しい記事は移転先で追加しております。(旧サイトでは記事を追加しておりません)

 
(同じ利用者による、間の1版が非表示)
202行目: 202行目:
== 組み込み関数 ==
== 組み込み関数 ==
Fishには補完を支援するための多くの組み込み関数がある。<br>
Fishには補完を支援するための多くの組み込み関数がある。<br>
<br>
組み込み関数を組み合わせてカスタム関数内で使用することにより、より複雑な補完ロジックを実現することができる。<br>
<br>
<br>
* <code>__fish_complete_directories</code>
* <code>__fish_complete_directories</code>
257行目: 259行目:
*: <syntaxhighlight lang="fish">complete -c openfile -f -a "(__fish_complete_suffix .txt)"</syntaxhighlight>
*: <syntaxhighlight lang="fish">complete -c openfile -f -a "(__fish_complete_suffix .txt)"</syntaxhighlight>
*: <br>
*: <br>
* <code>__fish_complete_history</code>
*: コマンド履歴から項目を補完する。
* <code>__fish_print_hostnames</code>
* <code>__fish_print_hostnames</code>
*: <u>/etc/hosts</u>ファイルとmDNSから取得したホスト名を補完する。
*: <u>/etc/hosts</u>ファイルとmDNSから取得したホスト名を補完する。
264行目: 264行目:
*: 以下の例では、some_commandコマンドに対して、システムが知りうるホスト名を補完候補として提供している。
*: 以下の例では、some_commandコマンドに対して、システムが知りうるホスト名を補完候補として提供している。
*: <syntaxhighlight lang="fish">complete -c some_command -f -a "(__fish_print_hostnames)"</syntaxhighlight>
*: <syntaxhighlight lang="fish">complete -c some_command -f -a "(__fish_print_hostnames)"</syntaxhighlight>
*: <br>
* <code>__fish_complete_history</code>
*: コマンド履歴から項目を補完する。
*: <br>
*: 以下の例では、rerunコマンドに対して、過去に実行したコマンドを補完候補として提供している。
*: <syntaxhighlight lang="fish">complete -c rerun -f -a "(__fish_complete_history)"</syntaxhighlight>
*: <br>
*: <br>
* <code>__fish_print_interfaces</code>
* <code>__fish_print_interfaces</code>
*: システムのネットワークインターフェースを補完する。
*: システムのネットワークインターフェースを補完する。
*: <br>
*: 以下の例では、ifconfigコマンドに対して、利用可能なネットワークインターフェース (例: eth0, wlan0等) を補完候補として提供している。
*: <syntaxhighlight lang="fish">complete -c ifconfig -f -a "(__fish_print_interfaces)"</syntaxhighlight>
*: <br>
* <code>__fish_print_filesystems</code>
* <code>__fish_print_filesystems</code>
*: 利用可能なファイルシステムタイプを補完する。
*: システムでサポートされているファイルシステムの一覧を補完する。
*: <br>
*: 以下の例では、mountコマンドに対して、利用可能なファイルシステムタイプ (例: ext4, ntfs, vfat等) を補完候補として提供している。
*: <syntaxhighlight lang="fish">complete -c mount -f -a "(__fish_print_filesystems)"</syntaxhighlight>
*: <br>
* <code>__fish_print_packages</code>
* <code>__fish_print_packages</code>
*: システムのパッケージマネージャーからパッケージ名を補完する。
*: パッケージ管理システムからインストールされたパッケージの一覧を補完する。
*: <br>
*: 以下の例では、zepper removeコマンドに対して、インストール済みのパッケージ名を補完候補として提供している。
*: <syntaxhighlight lang="fish">complete -c apt-get -f -n "__fish_seen_subcommand_from remove" -a "(__fish_print_packages)"</syntaxhighlight>
*: <br>
* <code>__fish_complete_uninstalled_packages</code>
*: システムにインストールされていないが利用可能なパッケージの一覧を補完する。
*: <br>
*: 以下の例では、zypper installコマンドに対して、インストールされていない利用可能なパッケージ名を補完候補として提供している。
*: <syntaxhighlight lang="fish">complete -c apt-get -f -n "__fish_seen_subcommand_from install" -a "(__fish_complete_uninstalled_packages)"</syntaxhighlight>
*: <br>
* <code>__fish_complete_man</code>
* <code>__fish_complete_man</code>
*: manページの名前を補完する。
*: システムで利用可能なmanページの名前を補完する。
*: <br>
*: 以下の例では、mymanviewerというカスタムコマンドに対して、全ての利用可能なmanページのタイトルを補完候補として提供している。
*: これにより、ユーザは素早くに特定のmanページを選択することができる。
*: <syntaxhighlight lang="fish">complete -c mymanviewer -f -a "(__fish_complete_man)"</syntaxhighlight>
*: <br>
* <code>__fish_complete_time</code>
* <code>__fish_complete_time</code>
*: 時間関連の補完を提供する。
*: 時間関連の補完を提供する。
* <code>__fish_complete_uninstalled_packages</code>
*: <br>
*: インストールされていないパッケージを補完する。
*: 以下の例では、mytimeというカスタムコマンドに対して、時間関連の補完 (例: 今日の日付、現在の時刻等) を提供している。
*: 具体的な補完内容はシステムの設定や現在の時刻に依存することに注意する。
*: <syntaxhighlight lang="fish">complete -c mytime -f -a "(__fish_complete_time)"</syntaxhighlight>
*: <br>
* <code>__fish_apropos</code>
* <code>__fish_apropos</code>
*: aproposコマンドの結果を基に補完候補を生成する。
*: aproposコマンドの結果を基に補完候補を生成する。
<br>
*: ユーザが指定したキーワードに関連するコマンドやドキュメントを素早く見つけることができる。
また、組み込み関数を組み合わせてカスタム関数内で使用することにより、より複雑な補完ロジックを実現することができる。<br>
*: <br>
*: 以下の例では、search-commandsというカスタムコマンドに対して、現在のコマンドライン入力 (例: commandline -ctで取得) に基づいて、関連するコマンドやmanページを補完候補として提供している。
*: <syntaxhighlight lang="fish">complete -c search-commands -f -a "(__fish_apropos (commandline -ct))"</syntaxhighlight>
<br><br>
<br><br>