bluetoothctlはコマンド履歴をどこに保存しますか?

bluetoothctlはコマンド履歴をどこに保存しますか?

man bluetoothctlinfo bluetoothctlそしてコマンド履歴については何もありませんbluetoothctl --help

ベストアンサー1

短い答え

bluetoothctlコマンド履歴を~/.cache/.bluetoothctl_history


長い答え

免責事項:長い答えには、プログラミング言語Cの知識が必要です。

bluetoothctl以下に付属のコマンドラインツールです。BlueZ – Linux用Bluetoothスタック。 BlueZのソースコードを見てみましょう。

私たちはすぐに次のようにbluetoothctl気付くでしょう。GNU Readlineライブラリ対話型シェルです。すべてReadlineのドキュメント、関数をwrite_history使用してファイルに履歴を書き込むことができます。 BlueZソースコードをgrepして関数名を見つけると、次のようになります。

$ grep write_history -r
src/shared/shell.c:             write_history(data.history);

コマンド履歴は、名前が保存されているbluetoothctlファイルに書き込まれます。その後、フィールドを簡単に検索して初期化された場所を見つけることができます。.historystruct data

static void rl_init_history(void)
{
        const char *name;
        char *dir;

        memset(data.history, 0, sizeof(data.history));

        name = strrchr(data.name, '/');
        if (!name)
                name = data.name;
        else
                name++;

        dir = getenv("XDG_CACHE_HOME");
        if (dir) {
                snprintf(data.history, sizeof(data.history), "%s/.%s_history",
                                                        dir, name);
                goto done;
        }

        dir = getenv("HOME");
        if (dir) {
                snprintf(data.history, sizeof(data.history),
                                "%s/.cache/.%s_history", dir, name);
                goto done;
        }

        dir = getenv("PWD");
        if (dir) {
                snprintf(data.history, sizeof(data.history), "%s/.%s_history",
                                                        dir, name);
                goto done;
        }

        return;

done:
        read_history(data.history);
        using_history();
        bt_shell_set_env("HISTORY", data.history);
}

ここXDG_CACHE_HOMEからfreedesktop.orgの仕様。他の環境変数はデフォルトで$HOMEあり、$PWD.fieldsdata.nameは他の場所に設定されます。

void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt)
{
...
    data.name = strrchr(argv[0], '/');
    if (!data.name)
        data.name = strdup(argv[0]);
    else
        data.name = strdup(++data.name);
...
}

したがって、char *name関数の変数にはrl_init_history実行可能ファイルの名前文字列が含まれます。bluetoothctlバラよりargvCでの説明

したがって、freedesktop.org仕様に準拠するほとんどのデスクトップ環境では、コマンドラインツールはコマンド履歴をファイルに保存しbluetoothctlます~/.cache/.bluetoothctl_history。環境変数が定義されると、XDG_CACHE_HOMEコマンド履歴がに保存されます$XDG_CACHE_HOME/.bluetoothctl_history

おすすめ記事