From 6ab04ce298129a6b1d803326542dd58c1ceb9990 Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Sun, 3 Dec 2023 11:46:07 -0300 Subject: [PATCH 01/39] Update cheatsheet_syntax.md --- docs/cheatsheet_syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cheatsheet_syntax.md b/docs/cheatsheet_syntax.md index bd114588..e7db5834 100644 --- a/docs/cheatsheet_syntax.md +++ b/docs/cheatsheet_syntax.md @@ -33,7 +33,7 @@ All the other non-empty lines are considered as executable commands. ### Folder structure -It's irrelevant how many files are used to store cheatsheets. They can be all in a single file if you wish, as long as you split them accordingly with lines starting with `%`. +The cheat file should be stored at `~/.local/share/navi/cheats`. It's irrelevant how many files are used to store cheatsheets. They can be all in a single file if you wish, as long as you split them accordingly with lines starting with `%`. ### Variables From 2ae23b8980a8b2a199186025fed7de3d8cdf8721 Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Sun, 3 Dec 2023 12:04:16 -0300 Subject: [PATCH 02/39] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dd043763..866983b9 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ In particular, check [these instructions](https://github.com/denisidoro/navi/iss ## Cheatsheet repositories -Running **navi** for the first time will help you download and manage cheatsheets. +Running **navi** for the first time will help you download and manage cheatsheets. They are stored at `~/.local/share/navi/cheats`. You can also: From eb5c12658ba2c5c041d8c66f24dc45736a278cf2 Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Sun, 3 Dec 2023 19:54:28 -0300 Subject: [PATCH 03/39] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 866983b9..fa65af2e 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ In particular, check [these instructions](https://github.com/denisidoro/navi/iss ## Cheatsheet repositories -Running **navi** for the first time will help you download and manage cheatsheets. They are stored at `~/.local/share/navi/cheats`. +Running **navi** for the first time will help you download and manage cheatsheets. By default, they are soted at `~/.local/share/navi/cheats`. You can also: From ec1eb7e2a1a76892e75d2625c05cafd41faa590a Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Sun, 3 Dec 2023 19:55:41 -0300 Subject: [PATCH 04/39] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fa65af2e..582dca14 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ In particular, check [these instructions](https://github.com/denisidoro/navi/iss ## Cheatsheet repositories -Running **navi** for the first time will help you download and manage cheatsheets. By default, they are soted at `~/.local/share/navi/cheats`. +Running **navi** for the first time will help you download and manage cheatsheets. By default, they are soted at `~/.local/share/navi/cheats/`. You can also: From e0111140f52805666c0a211bffb54f870ff5e2af Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Sun, 3 Dec 2023 19:57:53 -0300 Subject: [PATCH 05/39] Update cheatsheet_syntax.md --- docs/cheatsheet_syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cheatsheet_syntax.md b/docs/cheatsheet_syntax.md index e7db5834..2f2ff9f6 100644 --- a/docs/cheatsheet_syntax.md +++ b/docs/cheatsheet_syntax.md @@ -33,7 +33,7 @@ All the other non-empty lines are considered as executable commands. ### Folder structure -The cheat file should be stored at `~/.local/share/navi/cheats`. It's irrelevant how many files are used to store cheatsheets. They can be all in a single file if you wish, as long as you split them accordingly with lines starting with `%`. +By default, the `.cheat` files should be stored at `~/.local/share/navi/cheats/`, but you can add more paths in the in the [config file](https://github.com/denisidoro/navi/blob/master/docs/config_file.md). It's irrelevant how many files are used to store cheatsheets. They can be all in a single file if you wish, as long as you split them accordingly with lines starting with `%`. ### Variables From df168032becfaa47bc0a0fcf48077603eb3c4455 Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Sun, 3 Dec 2023 20:00:32 -0300 Subject: [PATCH 06/39] Update cheatsheet_syntax.md --- docs/cheatsheet_syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cheatsheet_syntax.md b/docs/cheatsheet_syntax.md index 2f2ff9f6..4ae580db 100644 --- a/docs/cheatsheet_syntax.md +++ b/docs/cheatsheet_syntax.md @@ -33,7 +33,7 @@ All the other non-empty lines are considered as executable commands. ### Folder structure -By default, the `.cheat` files should be stored at `~/.local/share/navi/cheats/`, but you can add more paths in the in the [config file](https://github.com/denisidoro/navi/blob/master/docs/config_file.md). It's irrelevant how many files are used to store cheatsheets. They can be all in a single file if you wish, as long as you split them accordingly with lines starting with `%`. +By default, the `.cheat` files should be stored at `~/.local/share/navi/cheats/`, but you can add more paths in the in the [config file](https://github.com/denisidoro/navi/blob/master/docs/config_file.md). The command `navi info cheats-path` print to you all paths used for search for `.cheat` files. It's irrelevant how many files are used to store cheatsheets. They can be all in a single file if you wish, as long as you split them accordingly with lines starting with `%`. ### Variables From 96ff6fe07014ada3de172373bf5ef4b122d416a2 Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Sun, 3 Dec 2023 20:01:15 -0300 Subject: [PATCH 07/39] Update cheatsheet_syntax.md --- docs/cheatsheet_syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cheatsheet_syntax.md b/docs/cheatsheet_syntax.md index 4ae580db..cd94d618 100644 --- a/docs/cheatsheet_syntax.md +++ b/docs/cheatsheet_syntax.md @@ -33,7 +33,7 @@ All the other non-empty lines are considered as executable commands. ### Folder structure -By default, the `.cheat` files should be stored at `~/.local/share/navi/cheats/`, but you can add more paths in the in the [config file](https://github.com/denisidoro/navi/blob/master/docs/config_file.md). The command `navi info cheats-path` print to you all paths used for search for `.cheat` files. It's irrelevant how many files are used to store cheatsheets. They can be all in a single file if you wish, as long as you split them accordingly with lines starting with `%`. +By default, the `.cheat` files should be stored at `~/.local/share/navi/cheats/`, but you can add more paths in the in the [config file](https://github.com/denisidoro/navi/blob/master/docs/config_file.md). The command `navi info cheats-path` print to you all paths used to search for `.cheat` files. It's irrelevant how many files are used to store cheatsheets. They can be all in a single file if you wish, as long as you split them accordingly with lines starting with `%`. ### Variables From 6689cfd79892d69bb6f2d972c8f99a6aaa81fac8 Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Sun, 3 Dec 2023 20:02:09 -0300 Subject: [PATCH 08/39] Update cheatsheet_syntax.md --- docs/cheatsheet_syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cheatsheet_syntax.md b/docs/cheatsheet_syntax.md index cd94d618..50011f2b 100644 --- a/docs/cheatsheet_syntax.md +++ b/docs/cheatsheet_syntax.md @@ -33,7 +33,7 @@ All the other non-empty lines are considered as executable commands. ### Folder structure -By default, the `.cheat` files should be stored at `~/.local/share/navi/cheats/`, but you can add more paths in the in the [config file](https://github.com/denisidoro/navi/blob/master/docs/config_file.md). The command `navi info cheats-path` print to you all paths used to search for `.cheat` files. It's irrelevant how many files are used to store cheatsheets. They can be all in a single file if you wish, as long as you split them accordingly with lines starting with `%`. +By default, the `.cheat` files should be stored at `~/.local/share/navi/cheats/`, but you can add more paths in the in the [config file](https://github.com/denisidoro/navi/blob/master/docs/config_file.md). The command `navi info cheats-path` prints to you all paths used to search for `.cheat` files. It's irrelevant how many files are used to store cheatsheets. They can be all in a single file if you wish, as long as you split them accordingly with lines starting with `%`. ### Variables From dbd077435e4d63a625fc7c49c8ea048b5c3351ab Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Sun, 3 Dec 2023 20:08:03 -0300 Subject: [PATCH 09/39] Update cheatsheet_syntax.md --- docs/cheatsheet_syntax.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/cheatsheet_syntax.md b/docs/cheatsheet_syntax.md index 50011f2b..4dbb74e4 100644 --- a/docs/cheatsheet_syntax.md +++ b/docs/cheatsheet_syntax.md @@ -33,7 +33,11 @@ All the other non-empty lines are considered as executable commands. ### Folder structure -By default, the `.cheat` files should be stored at `~/.local/share/navi/cheats/`, but you can add more paths in the in the [config file](https://github.com/denisidoro/navi/blob/master/docs/config_file.md). The command `navi info cheats-path` prints to you all paths used to search for `.cheat` files. It's irrelevant how many files are used to store cheatsheets. They can be all in a single file if you wish, as long as you split them accordingly with lines starting with `%`. +By default, the `.cheat` files should be stored at `~/.local/share/navi/cheats/`, but you can add more paths in the in the [config file](https://github.com/denisidoro/navi/blob/master/docs/config_file.md). The command +``` +navi info cheats-path +``` +prints to you all paths used to search for `.cheat` files. It's irrelevant how many files are used to store cheatsheets. They can be all in a single file if you wish, as long as you split them accordingly with lines starting with `%`. ### Variables From 0f41e07073b48461a1db47cf4a191ad5f9f44e7f Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Sun, 3 Dec 2023 20:24:13 -0300 Subject: [PATCH 10/39] Update cheatsheet_syntax.md --- docs/cheatsheet_syntax.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/cheatsheet_syntax.md b/docs/cheatsheet_syntax.md index 4dbb74e4..c5a44b6a 100644 --- a/docs/cheatsheet_syntax.md +++ b/docs/cheatsheet_syntax.md @@ -37,7 +37,11 @@ By default, the `.cheat` files should be stored at `~/.local/share/navi/cheats/` ``` navi info cheats-path ``` -prints to you all paths used to search for `.cheat` files. It's irrelevant how many files are used to store cheatsheets. They can be all in a single file if you wish, as long as you split them accordingly with lines starting with `%`. +prints to you all paths used to search for `.cheat` files. You can also use the `--path` option to pass custom colon-separed paths to `navi` at runtime, e.g., +``` +navi --path '/some/dir:/other/dir' +``` +It's irrelevant how many files are used to store cheatsheets. They can be all in a single file if you wish, as long as you split them accordingly with lines starting with `%`. ### Variables From 7accaa4c78c17862de40cab6307d61ea58d2c11b Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Sun, 3 Dec 2023 21:38:11 -0300 Subject: [PATCH 11/39] Rename cheatsheet_syntax.md to cheatsheet_settings.md --- docs/{cheatsheet_syntax.md => cheatsheet_settings.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/{cheatsheet_syntax.md => cheatsheet_settings.md} (100%) diff --git a/docs/cheatsheet_syntax.md b/docs/cheatsheet_settings.md similarity index 100% rename from docs/cheatsheet_syntax.md rename to docs/cheatsheet_settings.md From 18c549bf98537b43d5223e0f94f32457779f5df8 Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Sun, 3 Dec 2023 21:40:47 -0300 Subject: [PATCH 12/39] Rename cheatsheet_settings.md to cheatsheet_syntax.md --- docs/{cheatsheet_settings.md => cheatsheet_syntax.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/{cheatsheet_settings.md => cheatsheet_syntax.md} (100%) diff --git a/docs/cheatsheet_settings.md b/docs/cheatsheet_syntax.md similarity index 100% rename from docs/cheatsheet_settings.md rename to docs/cheatsheet_syntax.md From 2af65719e6764fa38d1a003fda77d1bd1624e5c8 Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Sun, 3 Dec 2023 21:43:38 -0300 Subject: [PATCH 13/39] Rename config_file.md to navi_config.md --- docs/{config_file.md => navi_config.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/{config_file.md => navi_config.md} (100%) diff --git a/docs/config_file.md b/docs/navi_config.md similarity index 100% rename from docs/config_file.md rename to docs/navi_config.md From 924ffb82ad02d1c1a183b435b8c2f93642893bf3 Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Sun, 3 Dec 2023 21:44:48 -0300 Subject: [PATCH 14/39] Update cheatsheet_syntax.md --- docs/cheatsheet_syntax.md | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/docs/cheatsheet_syntax.md b/docs/cheatsheet_syntax.md index c5a44b6a..ace9df68 100644 --- a/docs/cheatsheet_syntax.md +++ b/docs/cheatsheet_syntax.md @@ -31,18 +31,6 @@ Lines starting with: All the other non-empty lines are considered as executable commands. -### Folder structure - -By default, the `.cheat` files should be stored at `~/.local/share/navi/cheats/`, but you can add more paths in the in the [config file](https://github.com/denisidoro/navi/blob/master/docs/config_file.md). The command -``` -navi info cheats-path -``` -prints to you all paths used to search for `.cheat` files. You can also use the `--path` option to pass custom colon-separed paths to `navi` at runtime, e.g., -``` -navi --path '/some/dir:/other/dir' -``` -It's irrelevant how many files are used to store cheatsheets. They can be all in a single file if you wish, as long as you split them accordingly with lines starting with `%`. - ### Variables The interface prompts for variable names inside brackets (eg ``). From fdc5603278016cab01074909fb4507411011e012 Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Mon, 4 Dec 2023 03:17:34 -0300 Subject: [PATCH 15/39] Update navi_config.md --- docs/navi_config.md | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/docs/navi_config.md b/docs/navi_config.md index d7db5731..eb0bebf0 100644 --- a/docs/navi_config.md +++ b/docs/navi_config.md @@ -1,31 +1,32 @@ -## Config file - -- [Example](#example) -- [Location](#location) -- [Creating the file](#creating-the-file) - -### Example - -An example config can be found by running: +## Config file path +The default config file path is set by the `$NAVI_CONFIG`environment variable. If it is not set, it fallbacks to `~/.config/navi/config.yaml`. The command +```sh +navi info config-path +``` +prints which config file path is being used. You can get an config file example by running ```sh navi info config-example ``` - -You can also read it online by clicking [here](./config_file_example.yaml). - -### Location - -Run the following command to check where the config file is/should be located: +or by clicking [here](./config_file_example.yaml). To this this example your config file, run ```sh -navi info config-path +navi info config-example > "$(navi info config-path)" ``` +## Cheat sheet paths -### Creating the file - -Run the following command to generate a config file with the default parameters: +The default `.cheat` files paths are defined in the `$NAVI_PATH` environment variable in a colon-separated list, e.g., +``` +export NAVI_PATH='/path/to/a/dir:/path/to/another/dir:/yet/another/dir' +``` +If this environment variable is unset or if all directories do not exist, `navi` uses that paths defined in its config files. Finally, if there is no config file or if there is no `.cheat` file paths settings there, the default `.cheat` file path fallbacks to `~/.local/share/navi/cheats/`. The command +```sh +navi info cheats-path +``` +prints to you all paths used to search for `.cheat` files. +You can also add other paths at runtime by running `navi` with the `--path` option and a colon-separed paths list, e.g., ```sh -navi info config-example > "$(navi info config-path)" +navi --path '/some/dir:/other/dir' ``` +It's irrelevant the directory structure within each path. They can even be all in a single file if you wish, as long as you split them accordingly with lines starting with `%`. From ef1521f5531209a20023f225d7246a7eb31dd466 Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Mon, 4 Dec 2023 03:48:37 -0300 Subject: [PATCH 16/39] Update cheatsheet_syntax.md --- docs/cheatsheet_syntax.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/docs/cheatsheet_syntax.md b/docs/cheatsheet_syntax.md index ace9df68..7e9173f0 100644 --- a/docs/cheatsheet_syntax.md +++ b/docs/cheatsheet_syntax.md @@ -142,3 +142,42 @@ cat $ jsons: find . -iname '*.json' -type f -print --- --multi --expand ``` +### Aliases + +**navi** doesn't have support for aliases as first-class citizens at the moment. + +However, it is trivial to create aliases using **navi** + a few conventions. + +For example, suppose you decide to end some of your commands with `:: `: + +```bash +% aliases + +# This is one command :: el +echo lorem ipsum + +# This is another command :: ef +echo foo bar +``` + +Then, if you use **navi** as a [shell scripting tool](shell_scripting.md), you could add something similar to this in your `.bashrc`-like file: + +```bash +navialias() { + navi --query ":: $1" --best-match +} + +alias el="navialias el" +alias ef="navialias ef" +``` + +If you don't want to use these conventions, you can even add full comments in your aliases: + +```bash +navibestmatch() { + navi --query "$1" --best-match +} + +alias el="navibestmatch 'This is one command'" +alias ef="navibestmatch 'This is another command'" +``` From 4e1aada97b2425d58733fe16201d97f27f7c8f32 Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Mon, 4 Dec 2023 03:49:11 -0300 Subject: [PATCH 17/39] Update cheatsheet_syntax.md --- docs/cheatsheet_syntax.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/cheatsheet_syntax.md b/docs/cheatsheet_syntax.md index 7e9173f0..ea0aefdb 100644 --- a/docs/cheatsheet_syntax.md +++ b/docs/cheatsheet_syntax.md @@ -7,6 +7,7 @@ - [Variable dependency](#variable-dependency) - [Multiline snippets](#multiline-snippets) - [Variable as multiple arguments](#variable-as-multiple-arguments) +- [Aliases](#aliases) ### Syntax overview From 3b7f5b9fceae663c9a6e2e8150d8c6e26bb49af8 Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Mon, 4 Dec 2023 03:49:51 -0300 Subject: [PATCH 18/39] Delete docs/aliases.md --- docs/aliases.md | 39 --------------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 docs/aliases.md diff --git a/docs/aliases.md b/docs/aliases.md deleted file mode 100644 index 9c298b13..00000000 --- a/docs/aliases.md +++ /dev/null @@ -1,39 +0,0 @@ -## Aliases - -**navi** doesn't have support for aliases as first-class citizens at the moment. - -However, it is trivial to create aliases using **navi** + a few conventions. - -For example, suppose you decide to end some of your commands with `:: `: - -```bash -% aliases - -# This is one command :: el -echo lorem ipsum - -# This is another command :: ef -echo foo bar -``` - -Then, if you use **navi** as a [shell scripting tool](shell_scripting.md), you could add something similar to this in your `.bashrc`-like file: - -```bash -navialias() { - navi --query ":: $1" --best-match -} - -alias el="navialias el" -alias ef="navialias ef" -``` - -If you don't want to use these conventions, you can even add full comments in your aliases: - -```bash -navibestmatch() { - navi --query "$1" --best-match -} - -alias el="navibestmatch 'This is one command'" -alias ef="navibestmatch 'This is another command'" -``` From ddf6e9c9d0d794f3e170d996329e365408967362 Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Mon, 4 Dec 2023 04:07:51 -0300 Subject: [PATCH 19/39] Update navi_config.md --- docs/navi_config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/navi_config.md b/docs/navi_config.md index eb0bebf0..d3668d95 100644 --- a/docs/navi_config.md +++ b/docs/navi_config.md @@ -1,6 +1,6 @@ ## Config file path -The default config file path is set by the `$NAVI_CONFIG`environment variable. If it is not set, it fallbacks to `~/.config/navi/config.yaml`. The command +The default config file path is set by the `$NAVI_CONFIG` environment variable. If it is not set, it fallbacks to `~/.config/navi/config.yaml`. The command ```sh navi info config-path ``` From 6118a85d91462c8f6c91cc241237ded63b1e7d73 Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Mon, 4 Dec 2023 04:08:30 -0300 Subject: [PATCH 20/39] Update navi_config.md --- docs/navi_config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/navi_config.md b/docs/navi_config.md index d3668d95..ea66d1bb 100644 --- a/docs/navi_config.md +++ b/docs/navi_config.md @@ -8,7 +8,7 @@ prints which config file path is being used. You can get an config file example ```sh navi info config-example ``` -or by clicking [here](./config_file_example.yaml). To this this example your config file, run +or by clicking [here](./config_file_example.yaml). To turn this this example your config file, run ```sh navi info config-example > "$(navi info config-path)" From 1180e8cb55cb19a718d7fd759ef03a50450597f2 Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Mon, 4 Dec 2023 04:08:41 -0300 Subject: [PATCH 21/39] Update navi_config.md --- docs/navi_config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/navi_config.md b/docs/navi_config.md index ea66d1bb..a64e294d 100644 --- a/docs/navi_config.md +++ b/docs/navi_config.md @@ -8,7 +8,7 @@ prints which config file path is being used. You can get an config file example ```sh navi info config-example ``` -or by clicking [here](./config_file_example.yaml). To turn this this example your config file, run +or by clicking [here](./config_file_example.yaml). To turn this example your config file, run ```sh navi info config-example > "$(navi info config-path)" From 6f16237783590da1861094f257133bd8c69befbc Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Mon, 4 Dec 2023 04:09:23 -0300 Subject: [PATCH 22/39] Update navi_config.md --- docs/navi_config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/navi_config.md b/docs/navi_config.md index a64e294d..1882cb72 100644 --- a/docs/navi_config.md +++ b/docs/navi_config.md @@ -16,7 +16,7 @@ navi info config-example > "$(navi info config-path)" ## Cheat sheet paths The default `.cheat` files paths are defined in the `$NAVI_PATH` environment variable in a colon-separated list, e.g., -``` +```sh export NAVI_PATH='/path/to/a/dir:/path/to/another/dir:/yet/another/dir' ``` If this environment variable is unset or if all directories do not exist, `navi` uses that paths defined in its config files. Finally, if there is no config file or if there is no `.cheat` file paths settings there, the default `.cheat` file path fallbacks to `~/.local/share/navi/cheats/`. The command From 1119164edb8546b7302dc093e3eb09ff55a20fbe Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Mon, 4 Dec 2023 04:10:25 -0300 Subject: [PATCH 23/39] Update navi_config.md --- docs/navi_config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/navi_config.md b/docs/navi_config.md index 1882cb72..41006d82 100644 --- a/docs/navi_config.md +++ b/docs/navi_config.md @@ -19,7 +19,7 @@ The default `.cheat` files paths are defined in the `$NAVI_PATH` environment var ```sh export NAVI_PATH='/path/to/a/dir:/path/to/another/dir:/yet/another/dir' ``` -If this environment variable is unset or if all directories do not exist, `navi` uses that paths defined in its config files. Finally, if there is no config file or if there is no `.cheat` file paths settings there, the default `.cheat` file path fallbacks to `~/.local/share/navi/cheats/`. The command +If this environment variable is unset or if all directories do not exist, `navi` uses that paths defined in its config files. Finally, if there is no config file or if the `.cheat` file paths was not set, the default `.cheat` file path fallbacks to `~/.local/share/navi/cheats/`. The command ```sh navi info cheats-path ``` From eb9ad7c09ff468eb045f3e3a714822ea30777858 Mon Sep 17 00:00:00 2001 From: Rubem Pacelli Date: Mon, 4 Dec 2023 04:11:06 -0300 Subject: [PATCH 24/39] Update navi_config.md --- docs/navi_config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/navi_config.md b/docs/navi_config.md index 41006d82..6b53af8b 100644 --- a/docs/navi_config.md +++ b/docs/navi_config.md @@ -19,7 +19,7 @@ The default `.cheat` files paths are defined in the `$NAVI_PATH` environment var ```sh export NAVI_PATH='/path/to/a/dir:/path/to/another/dir:/yet/another/dir' ``` -If this environment variable is unset or if all directories do not exist, `navi` uses that paths defined in its config files. Finally, if there is no config file or if the `.cheat` file paths was not set, the default `.cheat` file path fallbacks to `~/.local/share/navi/cheats/`. The command +If this environment variable is unset or if all directories do not exist, `navi` uses that paths defined in its config files. Finally, if there is no config file or if the `.cheat` file paths was not set, the default `.cheat` file paths fallbacks to `~/.local/share/navi/cheats/`. The command ```sh navi info cheats-path ``` From 196872b1091adf843bda7bd5397a1cf3bc4fd903 Mon Sep 17 00:00:00 2001 From: zjp Date: Fri, 12 May 2023 17:01:49 +0800 Subject: [PATCH 25/39] introduce use env_logger related to https://github.com/denisidoro/navi/issues/576 For the following config cheats: paths: - C:\\Users\\Administrator\\AppData\\Roaming\\navi\\cheat - C:\\Users\\Administrator\\AppData\\Roaming\\navi\\cheat navi now gets incorrect paths on Windows, since the seperator `:` for path join is a valid component. [2023-05-12T08:58:26Z DEBUG navi::commands::core] Filesystem( Some( "C:\\\\Users\\\\Administrator\\\\AppData\\\\Roaming\\\\navi\\\\cheat:C:\\\\Users\\\\Administrator\\\\AppData\\\\Roaming\\\\navi\\\\cheat", ), ) [2023-05-12T08:58:28Z DEBUG navi::filesystem] filesystem::Fetcher = Fetcher { path: Some( "C:\\\\Users\\\\Administrator\\\\AppData\\\\Roaming\\\\navi\\\\cheat:C:\\\\Users\\\\Administrator\\\\AppData\\\\Roaming\\\\navi\\\\cheat", ), files: RefCell { value: [], }, } --- .gitignore | 1 + Cargo.lock | 22 ++++++++++++++++++++-- Cargo.toml | 2 ++ src/bin/main.rs | 16 ++++++++++++++-- src/commands/core/mod.rs | 4 +++- src/commands/mod.rs | 1 + src/config/cli.rs | 1 + src/config/env.rs | 1 + src/config/mod.rs | 1 + src/config/yaml.rs | 16 ++++++++-------- src/filesystem.rs | 2 ++ src/lib.rs | 2 -- 12 files changed, 54 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 53eaa219..3f2d71bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target **/*.rs.bk +navi.log diff --git a/Cargo.lock b/Cargo.lock index bbdffeef..58753adf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -260,6 +260,16 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" +[[package]] +name = "env_logger" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +dependencies = [ + "humantime", + "log", +] + [[package]] name = "errno" version = "0.3.0" @@ -344,6 +354,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "indexmap" version = "1.9.3" @@ -412,9 +428,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.14" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", ] @@ -456,8 +472,10 @@ dependencies = [ "dns_common", "dns_common_derive", "edit", + "env_logger", "etcetera", "lazy_static", + "log", "regex", "remove_dir_all 0.8.2", "serde", diff --git a/Cargo.toml b/Cargo.toml index a9dc3d12..0115aca4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,8 @@ serde_yaml = "0.9.21" dns_common_derive = { version = "0.2.1" } dns_common = { version = "0.2.1", default-features = false, features = ["yaml", "json"] } unicode-width = "0.1.10" +log = "0.4" +env_logger = { version = "0.10", default_features = false, features = ["humantime"] } [lib] name = "navi" diff --git a/src/bin/main.rs b/src/bin/main.rs index ad67e718..48c2fa0c 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -1,6 +1,5 @@ extern crate navi; -use std::fmt::Debug; use thiserror::Error; #[derive(Error, Debug)] @@ -25,5 +24,18 @@ impl FileAnIssue { } fn main() -> Result<(), anyhow::Error> { - navi::handle().map_err(|e| FileAnIssue::new(e).into()) + init_logger()?; + navi::handle().map_err(|e| { + log::error!("{e:?}"); + FileAnIssue::new(e).into() + }) +} + +fn init_logger() -> anyhow::Result<()> { + let file = std::fs::File::create("navi.log")?; + env_logger::builder() + .target(env_logger::Target::Pipe(Box::new(file))) + .init(); + + Ok(()) } diff --git a/src/commands/core/mod.rs b/src/commands/core/mod.rs index ded24f1f..2a3d3347 100644 --- a/src/commands/core/mod.rs +++ b/src/commands/core/mod.rs @@ -44,7 +44,9 @@ pub fn init(fetcher: Box) -> Result<()> { } pub fn get_fetcher() -> Result> { - match CONFIG.source() { + let source = CONFIG.source(); + log::debug!("{source:#?}"); + match source { Source::Cheats(query) => { let lines = cheatsh::call(&query)?; let fetcher = Box::new(StaticFetcher::new(lines)); diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 783cbad5..257df1c8 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -12,6 +12,7 @@ use crate::prelude::*; pub fn handle() -> Result<()> { use crate::config::Command::*; + log::debug!("CONFIG = {:#?}", &*CONFIG); match CONFIG.cmd() { None => commands::core::main(), diff --git a/src/config/cli.rs b/src/config/cli.rs index 7e2ec20e..c6f86f99 100644 --- a/src/config/cli.rs +++ b/src/config/cli.rs @@ -117,6 +117,7 @@ pub enum Command { Info(commands::info::Input), } +#[derive(Debug)] pub enum Source { Filesystem(Option), Tldr(String), diff --git a/src/config/env.rs b/src/config/env.rs index 7afd27e1..ba428fc3 100644 --- a/src/config/env.rs +++ b/src/config/env.rs @@ -2,6 +2,7 @@ use crate::env_var; use crate::finder::FinderChoice; use crate::prelude::*; +#[derive(Debug)] pub struct EnvConfig { pub config_yaml: Option, pub config_path: Option, diff --git a/src/config/mod.rs b/src/config/mod.rs index 774f9300..68638cfc 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -12,6 +12,7 @@ use yaml::YamlConfig; lazy_static! { pub static ref CONFIG: Config = Config::new(); } +#[derive(Debug)] pub struct Config { yaml: YamlConfig, clap: ClapConfig, diff --git a/src/config/yaml.rs b/src/config/yaml.rs index 8c4a693e..70a5a17a 100644 --- a/src/config/yaml.rs +++ b/src/config/yaml.rs @@ -6,7 +6,7 @@ use crate::prelude::*; use crossterm::style::Color as TerminalColor; use serde::de; -#[derive(Deserialize)] +#[derive(Deserialize, Debug)] pub struct Color(#[serde(deserialize_with = "color_deserialize")] TerminalColor); impl Color { @@ -24,7 +24,7 @@ where .map_err(|_| de::Error::custom(format!("Failed to deserialize color: {s}"))) } -#[derive(Deserialize)] +#[derive(Deserialize, Debug)] #[serde(default)] pub struct ColorWidth { pub color: Color, @@ -32,7 +32,7 @@ pub struct ColorWidth { pub min_width: u16, } -#[derive(Deserialize)] +#[derive(Deserialize, Debug)] #[serde(default)] pub struct Style { pub tag: ColorWidth, @@ -40,7 +40,7 @@ pub struct Style { pub snippet: ColorWidth, } -#[derive(Deserialize)] +#[derive(Deserialize, Debug)] #[serde(default)] pub struct Finder { #[serde(deserialize_with = "finder_deserialize")] @@ -58,27 +58,27 @@ where .map_err(|_| de::Error::custom(format!("Failed to deserialize finder: {s}"))) } -#[derive(Deserialize, Default)] +#[derive(Deserialize, Default, Debug)] #[serde(default)] pub struct Cheats { pub path: Option, pub paths: Vec, } -#[derive(Deserialize, Default)] +#[derive(Deserialize, Default, Debug)] #[serde(default)] pub struct Search { pub tags: Option, } -#[derive(Deserialize)] +#[derive(Deserialize, Debug)] #[serde(default)] pub struct Shell { pub command: String, pub finder_command: Option, } -#[derive(Deserialize, Default)] +#[derive(Deserialize, Default, Debug)] #[serde(default)] pub struct YamlConfig { pub style: Style, diff --git a/src/filesystem.rs b/src/filesystem.rs index 6340f82e..ed0f32e6 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -125,6 +125,7 @@ fn interpolate_paths(paths: String) -> String { newtext } +#[derive(Debug)] pub struct Fetcher { path: Option, files: RefCell>, @@ -180,6 +181,7 @@ impl fetcher::Fetcher for Fetcher { } } + log::debug!("filesystem::Fetcher = {self:#?}"); Ok(found_something) } diff --git a/src/lib.rs b/src/lib.rs index cbae52d9..f4a434f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,5 @@ #[macro_use] extern crate lazy_static; -// #[macro_use] -// extern crate anyhow; mod clients; mod commands; From e2c4b2b67eac9ff067b072f630468d5f925e2849 Mon Sep 17 00:00:00 2001 From: zjp Date: Fri, 12 May 2023 19:13:50 +0800 Subject: [PATCH 26/39] rm env_logger; use tracing instead --- Cargo.lock | 18 ------------------ Cargo.toml | 2 -- src/bin/main.rs | 17 +++++++++++------ src/commands/core/mod.rs | 2 +- src/commands/mod.rs | 2 +- src/filesystem.rs | 2 +- 6 files changed, 14 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 58753adf..ac4c0ef3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -260,16 +260,6 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" -[[package]] -name = "env_logger" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" -dependencies = [ - "humantime", - "log", -] - [[package]] name = "errno" version = "0.3.0" @@ -354,12 +344,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "indexmap" version = "1.9.3" @@ -472,10 +456,8 @@ dependencies = [ "dns_common", "dns_common_derive", "edit", - "env_logger", "etcetera", "lazy_static", - "log", "regex", "remove_dir_all 0.8.2", "serde", diff --git a/Cargo.toml b/Cargo.toml index 0115aca4..a9dc3d12 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,8 +36,6 @@ serde_yaml = "0.9.21" dns_common_derive = { version = "0.2.1" } dns_common = { version = "0.2.1", default-features = false, features = ["yaml", "json"] } unicode-width = "0.1.10" -log = "0.4" -env_logger = { version = "0.10", default_features = false, features = ["humantime"] } [lib] name = "navi" diff --git a/src/bin/main.rs b/src/bin/main.rs index 48c2fa0c..a9b90b05 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -1,5 +1,6 @@ extern crate navi; +use dns_common::prelude::{debug, error, tracing, tracing_subscriber}; use thiserror::Error; #[derive(Error, Debug)] @@ -26,16 +27,20 @@ impl FileAnIssue { fn main() -> Result<(), anyhow::Error> { init_logger()?; navi::handle().map_err(|e| { - log::error!("{e:?}"); + error!("{e:?}"); FileAnIssue::new(e).into() }) } fn init_logger() -> anyhow::Result<()> { - let file = std::fs::File::create("navi.log")?; - env_logger::builder() - .target(env_logger::Target::Pipe(Box::new(file))) - .init(); - + tracing::subscriber::set_global_default( + tracing_subscriber::fmt() + .with_ansi(false) + // TODO: config_path/navi.log + .with_writer(std::fs::File::create("navi.log")?) + .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) + .finish(), + )?; + debug!("tracing initialized"); Ok(()) } diff --git a/src/commands/core/mod.rs b/src/commands/core/mod.rs index 2a3d3347..80551252 100644 --- a/src/commands/core/mod.rs +++ b/src/commands/core/mod.rs @@ -45,7 +45,7 @@ pub fn init(fetcher: Box) -> Result<()> { pub fn get_fetcher() -> Result> { let source = CONFIG.source(); - log::debug!("{source:#?}"); + debug!("{source:#?}"); match source { Source::Cheats(query) => { let lines = cheatsh::call(&query)?; diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 257df1c8..4537177a 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -12,7 +12,7 @@ use crate::prelude::*; pub fn handle() -> Result<()> { use crate::config::Command::*; - log::debug!("CONFIG = {:#?}", &*CONFIG); + debug!("CONFIG = {:#?}", &*CONFIG); match CONFIG.cmd() { None => commands::core::main(), diff --git a/src/filesystem.rs b/src/filesystem.rs index ed0f32e6..fe4df977 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -181,7 +181,7 @@ impl fetcher::Fetcher for Fetcher { } } - log::debug!("filesystem::Fetcher = {self:#?}"); + debug!("filesystem::Fetcher = {self:#?}"); Ok(found_something) } From 4d077ba61283cddcf72fd868d8d8c5931313052f Mon Sep 17 00:00:00 2001 From: zjp Date: Fri, 12 May 2023 23:32:00 +0800 Subject: [PATCH 27/39] mv navi.log under config dir; debug folders on Windows 2023-05-12T15:51:54.280707Z DEBUG navi::filesystem: read cheat files in `"C"`: [] 2023-05-12T15:51:54.281083Z DEBUG navi::filesystem: read cheat files in `"\\Users\\Administrator\\AppData\\Roaming\\navi\\cheats"`: [] --- src/bin/main.rs | 10 +++++++--- src/filesystem.rs | 6 ++++-- src/lib.rs | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index a9b90b05..01f9ffb7 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -1,6 +1,6 @@ extern crate navi; -use dns_common::prelude::{debug, error, tracing, tracing_subscriber}; +use dns_common::prelude::*; use thiserror::Error; #[derive(Error, Debug)] @@ -33,14 +33,18 @@ fn main() -> Result<(), anyhow::Error> { } fn init_logger() -> anyhow::Result<()> { + const FILE_NAME: &str = "navi.log"; + let mut file = navi::default_config_pathbuf()?; + file.set_file_name(FILE_NAME); + tracing::subscriber::set_global_default( tracing_subscriber::fmt() .with_ansi(false) - // TODO: config_path/navi.log - .with_writer(std::fs::File::create("navi.log")?) + .with_writer(std::fs::File::create(file)?) .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) .finish(), )?; debug!("tracing initialized"); + Ok(()) } diff --git a/src/filesystem.rs b/src/filesystem.rs index fe4df977..bebe1d87 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -166,7 +166,9 @@ impl fetcher::Fetcher for Fetcher { None => folder.to_string(), }; let folder_pathbuf = PathBuf::from(interpolated_folder); - for file in all_cheat_files(&folder_pathbuf) { + let cheat_files = all_cheat_files(&folder_pathbuf); + debug!("read cheat files in `{folder_pathbuf:?}`: {cheat_files:#?}"); + for file in cheat_files { self.files.borrow_mut().push(file.clone()); let index = self.files.borrow().len() - 1; let read_file_result = { @@ -181,7 +183,7 @@ impl fetcher::Fetcher for Fetcher { } } - debug!("filesystem::Fetcher = {self:#?}"); + debug!("{self:#?}"); Ok(found_something) } diff --git a/src/lib.rs b/src/lib.rs index f4a434f6..bc2bdf6b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,4 +14,4 @@ mod prelude; mod structures; mod welcome; -pub use commands::handle; +pub use {commands::handle, filesystem::default_config_pathbuf}; From 13318c449477a7091f4239b2f2403117e33c8dee Mon Sep 17 00:00:00 2001 From: zjp Date: Sat, 13 May 2023 11:27:27 +0800 Subject: [PATCH 28/39] Fix multiple paths: define the platform-specific join separator --- src/config/mod.rs | 2 +- src/filesystem.rs | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 68638cfc..b6526081 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -70,7 +70,7 @@ impl Config { if p.is_empty() { None } else { - Some(p.join(":")) + Some(p.join(crate::filesystem::JOIN_SEPARATOR)) } }) .or_else(|| self.yaml.cheats.path.clone()) diff --git a/src/filesystem.rs b/src/filesystem.rs index bebe1d87..a53f2461 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -12,6 +12,13 @@ use std::path::MAIN_SEPARATOR; use walkdir::WalkDir; +/// Multiple paths are joint by a platform-specific separator. +/// FIXME: it's actually incorrect to assume a path doesn't containing this separator +#[cfg(target_family = "windows")] +pub const JOIN_SEPARATOR: &str = ";"; +#[cfg(not(target_family = "windows"))] +pub const JOIN_SEPARATOR: &str = ":"; + pub fn all_cheat_files(path: &Path) -> Vec { WalkDir::new(path) .follow_links(true) @@ -23,7 +30,7 @@ pub fn all_cheat_files(path: &Path) -> Vec { } fn paths_from_path_param(env_var: &str) -> impl Iterator { - env_var.split(':').filter(|folder| folder != &"") + env_var.split(JOIN_SEPARATOR).filter(|folder| folder != &"") } fn compiled_default_path(path: Option<&str>) -> Option { @@ -284,4 +291,12 @@ mod tests { assert_eq!(expected, cheats.to_string_lossy().to_string()) } + + #[test] + #[cfg(target_family = "windows")] + fn multiple_paths() { + let p = r#"C:\Users\Administrator\AppData\Roaming\navi\config.yaml"#; + let paths = &[p; 2].join(JOIN_SEPARATOR); + assert_eq!(paths_from_path_param(paths).collect::>(), [p; 2]); + } } From 2026b708cfe4994e283f64d080df1ed0e9b0d9cc Mon Sep 17 00:00:00 2001 From: zjp Date: Sat, 13 May 2023 13:47:21 +0800 Subject: [PATCH 29/39] eprintln init_logger failure (may need redir if it's flushed away) and add a description on logging --- docs/config_file.md | 37 +++++++++++++++++++++++++++++++++++++ src/bin/main.rs | 7 +++++-- 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 docs/config_file.md diff --git a/docs/config_file.md b/docs/config_file.md new file mode 100644 index 00000000..25498c09 --- /dev/null +++ b/docs/config_file.md @@ -0,0 +1,37 @@ +## Config file + +- [Example](#example) +- [Location](#location) +- [Creating the file](#creating-the-file) + +### Example + +An example config can be found by running: + +```sh +navi info config-example +``` + +You can also read it online by clicking [here](./config_file_example.yaml). + +### Location + +Run the following command to check where the config file is/should be located: + +```sh +navi info config-path +``` + +### Creating the file + +Run the following command to generate a config file with the default parameters: + +```sh +navi info config-example > "$(navi info config-path)" +``` + +### Logging + +The log file will be created under the same directory where the config locates. + +And you can use the `RUST_LOG` env to set the log level, e.g. `RUST_LOG=debug navi`. diff --git a/src/bin/main.rs b/src/bin/main.rs index 01f9ffb7..fa12d648 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -24,8 +24,11 @@ impl FileAnIssue { } } -fn main() -> Result<(), anyhow::Error> { - init_logger()?; +fn main() -> anyhow::Result<()> { + if let Err(err) = init_logger() { + // may need redir stderr to a file to show this log initialization error + eprintln!("failed to initialize logging: {err:?}"); + } navi::handle().map_err(|e| { error!("{e:?}"); FileAnIssue::new(e).into() From 6822f1d51bf7b37f1886677ed8dc110af2887da1 Mon Sep 17 00:00:00 2001 From: zjp Date: Sat, 13 May 2023 13:57:32 +0800 Subject: [PATCH 30/39] update config_file_example: add a cheats path example on Windows --- docs/config_file_example.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/config_file_example.yaml b/docs/config_file_example.yaml index 2344dec3..ce143652 100644 --- a/docs/config_file_example.yaml +++ b/docs/config_file_example.yaml @@ -19,9 +19,9 @@ finder: # overrides_var: --tac # equivalent to the --fzf-overrides-var option # cheats: -# paths: -# - /path/to/some/dir -# - /path/to/another/dir +# paths: +# - /path/to/some/dir # on unix-like os +# - F:\\path\\to\\dir # on Windows # path: /path/to/some/dir # (DEPRECATED) equivalent to the --path option # search: From 2933740c1786a6652157bcf492dd4119c21d2195 Mon Sep 17 00:00:00 2001 From: zjp Date: Sat, 13 May 2023 14:14:36 +0800 Subject: [PATCH 31/39] If config path doesn't exist, navi won't log. --- src/bin/main.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index fa12d648..8c4856a9 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -40,10 +40,16 @@ fn init_logger() -> anyhow::Result<()> { let mut file = navi::default_config_pathbuf()?; file.set_file_name(FILE_NAME); + // If config path doesn't exist, navi won't log. + if file.parent().map(|p| !p.exists()).unwrap_or(true) { + return Ok(()); + } + + let writer = std::fs::File::create(&file).with_context(|| format!("{file:?} is not created"))?; tracing::subscriber::set_global_default( tracing_subscriber::fmt() .with_ansi(false) - .with_writer(std::fs::File::create(file)?) + .with_writer(writer) .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) .finish(), )?; From 2f175e6eb23162d3e93f626b5c8a1659ef285b4a Mon Sep 17 00:00:00 2001 From: zjp Date: Sat, 13 May 2023 15:51:39 +0800 Subject: [PATCH 32/39] config_file_example: shell command should be `cmd.exe` on Windows and add shell command debug in logging --- docs/config_file_example.yaml | 5 ++++- src/common/shell.rs | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/config_file_example.yaml b/docs/config_file_example.yaml index ce143652..1eb7ab7c 100644 --- a/docs/config_file_example.yaml +++ b/docs/config_file_example.yaml @@ -28,5 +28,8 @@ finder: # tags: git,!checkout # equivalent to the --tag-rules option shell: - command: bash # shell used for shell out. possible values: bash, zsh, dash, ... + # Shell used for shell out. Possible values: bash, zsh, dash, ... + # For Windows, use `cmd.exe` instead. + command: bash + # finder_command: bash # similar, but for fzf's internals diff --git a/src/common/shell.rs b/src/common/shell.rs index 331eb32b..976128b9 100644 --- a/src/common/shell.rs +++ b/src/common/shell.rs @@ -42,5 +42,6 @@ pub fn out() -> Command { cmd.args(words); let dash_c = if words_str.contains("cmd.exe") { "/c" } else { "-c" }; cmd.arg(dash_c); + debug!("shell cmd = `{cmd:#?}`"); cmd } From 6a0accface7e0abcfd91184ea13726b15e432dbc Mon Sep 17 00:00:00 2001 From: zjp Date: Sat, 13 May 2023 22:41:02 +0800 Subject: [PATCH 33/39] debug log --- src/commands/core/actor.rs | 14 ++++++++------ src/commands/core/mod.rs | 4 +++- src/commands/preview/var_stdin.rs | 9 ++++----- src/common/shell.rs | 1 - src/filesystem.rs | 2 +- src/finder/mod.rs | 8 +++++--- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/commands/core/actor.rs b/src/commands/core/actor.rs index 9d497179..91a18466 100644 --- a/src/commands/core/actor.rs +++ b/src/commands/core/actor.rs @@ -41,9 +41,10 @@ fn prompt_finder( } } - let child = shell::out() - .stdout(Stdio::piped()) - .arg(suggestion_command) + let mut cmd = shell::out(); + cmd.stdout(Stdio::piped()).arg(suggestion_command); + debug!(cmd = ?cmd); + let child = cmd .spawn() .map_err(|e| ShellSpawnError::new(suggestion_command, e))?; @@ -236,9 +237,10 @@ pub fn act( clipboard::copy(interpolated_snippet)?; } _ => { - shell::out() - .arg(&interpolated_snippet[..]) - .spawn() + let mut cmd = shell::out(); + cmd.arg(&interpolated_snippet[..]); + debug!(cmd = ?cmd); + cmd.spawn() .map_err(|e| ShellSpawnError::new(&interpolated_snippet[..], e))? .wait() .context("bash was not running")?; diff --git a/src/commands/core/mod.rs b/src/commands/core/mod.rs index 80551252..00e3a35a 100644 --- a/src/commands/core/mod.rs +++ b/src/commands/core/mod.rs @@ -13,6 +13,7 @@ use crate::welcome; pub fn init(fetcher: Box) -> Result<()> { let config = &CONFIG; let opts = FinderOpts::snippet_default(); + debug!("opts = {opts:#?}"); // let fetcher = config.fetcher(); let (raw_selection, (variables, files)) = config @@ -32,6 +33,7 @@ pub fn init(fetcher: Box) -> Result<()> { }) .context("Failed getting selection and variables from finder")?; + debug!(raw_selection = ?raw_selection); let extractions = deser::terminal::read(&raw_selection, config.best_match()); if extractions.is_err() { @@ -45,7 +47,7 @@ pub fn init(fetcher: Box) -> Result<()> { pub fn get_fetcher() -> Result> { let source = CONFIG.source(); - debug!("{source:#?}"); + debug!(source = ?source); match source { Source::Cheats(query) => { let lines = cheatsh::call(&query)?; diff --git a/src/commands/preview/var_stdin.rs b/src/commands/preview/var_stdin.rs index 4b8ddfb5..78cc8efa 100755 --- a/src/commands/preview/var_stdin.rs +++ b/src/commands/preview/var_stdin.rs @@ -30,11 +30,10 @@ impl Runnable for Input { if !extra.is_empty() { print!(""); - shell::out() - .arg(extra) - .spawn() - .map_err(|e| ShellSpawnError::new(extra, e))? - .wait()?; + let mut cmd = shell::out(); + cmd.arg(extra); + debug!(?cmd); + cmd.spawn().map_err(|e| ShellSpawnError::new(extra, e))?.wait()?; } } diff --git a/src/common/shell.rs b/src/common/shell.rs index 976128b9..331eb32b 100644 --- a/src/common/shell.rs +++ b/src/common/shell.rs @@ -42,6 +42,5 @@ pub fn out() -> Command { cmd.args(words); let dash_c = if words_str.contains("cmd.exe") { "/c" } else { "-c" }; cmd.arg(dash_c); - debug!("shell cmd = `{cmd:#?}`"); cmd } diff --git a/src/filesystem.rs b/src/filesystem.rs index a53f2461..b8c4a03a 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -190,7 +190,7 @@ impl fetcher::Fetcher for Fetcher { } } - debug!("{self:#?}"); + debug!("FilesystemFetcher = {self:#?}"); Ok(found_something) } diff --git a/src/finder/mod.rs b/src/finder/mod.rs index b18888f4..9b4ccfd1 100644 --- a/src/finder/mod.rs +++ b/src/finder/mod.rs @@ -152,11 +152,13 @@ impl FinderChoice { }); } - let child = command + command .env("SHELL", CONFIG.finder_shell()) .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .spawn(); + .stdout(Stdio::piped()); + debug!(cmd = ?command); + + let child = command.spawn(); let mut child = match child { Ok(x) => x, From aeb9cd4b8baf80cb19a2de31c634437c847ea236 Mon Sep 17 00:00:00 2001 From: zjp Date: Sat, 13 May 2023 22:44:13 +0800 Subject: [PATCH 34/39] Fix preview: handle Windows NT UNC paths (`\\?\C:\foo`) --- Cargo.lock | 7 +++++++ Cargo.toml | 3 +++ src/common/fs.rs | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index ac4c0ef3..a379f1b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -244,6 +244,12 @@ dependencies = [ "synstructure", ] +[[package]] +name = "dunce" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" + [[package]] name = "edit" version = "0.1.4" @@ -455,6 +461,7 @@ dependencies = [ "crossterm", "dns_common", "dns_common_derive", + "dunce", "edit", "etcetera", "lazy_static", diff --git a/Cargo.toml b/Cargo.toml index a9dc3d12..fa054ccb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,9 @@ dns_common_derive = { version = "0.2.1" } dns_common = { version = "0.2.1", default-features = false, features = ["yaml", "json"] } unicode-width = "0.1.10" +[target.'cfg(windows)'.dependencies] +dunce = "1" + [lib] name = "navi" path = "src/lib.rs" diff --git a/src/common/fs.rs b/src/common/fs.rs index 32c8b1e7..cf8a7372 100644 --- a/src/common/fs.rs +++ b/src/common/fs.rs @@ -78,6 +78,11 @@ fn follow_symlink(pathbuf: PathBuf) -> Result { fn exe_pathbuf() -> Result { let pathbuf = std::env::current_exe().context("Unable to acquire executable's path")?; + + #[cfg(target_family = "windows")] + let pathbuf = dunce::canonicalize(pathbuf)?; + + debug!(current_exe = ?pathbuf); follow_symlink(pathbuf) } From 422d37f328b6d2e1d9edf383f246b60756c5f498 Mon Sep 17 00:00:00 2001 From: tjex Date: Sat, 4 Nov 2023 20:53:33 +0100 Subject: [PATCH 35/39] documentation on paths and environment vars --- README.md | 1 + docs/paths_and_environment_variables.md | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 docs/paths_and_environment_variables.md diff --git a/README.md b/README.md index 582dca14..7d63a8aa 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,7 @@ The full syntax and examples can be found [here](docs/cheatsheet_syntax.md). You can: - [setup your own config file](docs/config_file.md) +- [set custom paths for your config file and cheat sheets](docs/paths_and_environment_variables.md) - [change colors](docs/customization.md#changing-colors) - [resize columns](docs/customization.md#resizing-columns) - [change how search is performed](docs/customization.md#overriding-fzf-options) diff --git a/docs/paths_and_environment_variables.md b/docs/paths_and_environment_variables.md new file mode 100644 index 00000000..c53e828c --- /dev/null +++ b/docs/paths_and_environment_variables.md @@ -0,0 +1,21 @@ +# Paths and Environment Variables + +Navi uses the [`directories-next`](https://crates.io/crates/directories-next) package, which +defines platform-specific standard locations of directories for config, cache and other data. + +Mac users, this is why your files are being stored in `~/Library/Application Support/navi`. + +To set custom paths for your config and cheat sheets, you can set the following +environment variables: + +```zsh +export NAVI_CONFIG="~/.config/navi/config.yaml" +export NAVI_PATH="~/.local/share/navi" +``` +Note! Even when set, `$NAVI_PATH` will not be used when installing cheat +sheets directly via navi's own commands. + +For example when running `navi add repo `~/Library/...` will still be used. + +Instead, you may clone repos directly into `$NAVI_PATH`, or write your own +manually. From cac329e60c6287e057fd60bcca221ee33240913a Mon Sep 17 00:00:00 2001 From: tjex Date: Sat, 4 Nov 2023 20:54:49 +0100 Subject: [PATCH 36/39] doc: typo --- docs/paths_and_environment_variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/paths_and_environment_variables.md b/docs/paths_and_environment_variables.md index c53e828c..62662660 100644 --- a/docs/paths_and_environment_variables.md +++ b/docs/paths_and_environment_variables.md @@ -15,7 +15,7 @@ export NAVI_PATH="~/.local/share/navi" Note! Even when set, `$NAVI_PATH` will not be used when installing cheat sheets directly via navi's own commands. -For example when running `navi add repo `~/Library/...` will still be used. +For example when running `navi add repo `, `~/Library/...` will still be used. Instead, you may clone repos directly into `$NAVI_PATH`, or write your own manually. From 449141a9d57d930e308eb9df978e9ba5f85ec812 Mon Sep 17 00:00:00 2001 From: tjex Date: Sat, 4 Nov 2023 20:56:48 +0100 Subject: [PATCH 37/39] docs: clarity --- docs/paths_and_environment_variables.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/paths_and_environment_variables.md b/docs/paths_and_environment_variables.md index 62662660..99eb490d 100644 --- a/docs/paths_and_environment_variables.md +++ b/docs/paths_and_environment_variables.md @@ -15,7 +15,8 @@ export NAVI_PATH="~/.local/share/navi" Note! Even when set, `$NAVI_PATH` will not be used when installing cheat sheets directly via navi's own commands. -For example when running `navi add repo `, `~/Library/...` will still be used. +For example when running `navi add repo `, the default paths as per the `directories-next` +package will still be used. -Instead, you may clone repos directly into `$NAVI_PATH`, or write your own -manually. +To avoid this, you may simply clone repos via a regular `git clone` command, +directly into `$NAVI_PATH`. From be8326df6b6910880f96751b82224daa7ec03a99 Mon Sep 17 00:00:00 2001 From: tjex Date: Sat, 4 Nov 2023 21:03:10 +0100 Subject: [PATCH 38/39] docs: extra clarity --- docs/paths_and_environment_variables.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/paths_and_environment_variables.md b/docs/paths_and_environment_variables.md index 99eb490d..f0cdbb9c 100644 --- a/docs/paths_and_environment_variables.md +++ b/docs/paths_and_environment_variables.md @@ -12,7 +12,7 @@ environment variables: export NAVI_CONFIG="~/.config/navi/config.yaml" export NAVI_PATH="~/.local/share/navi" ``` -Note! Even when set, `$NAVI_PATH` will not be used when installing cheat +Despite `$NAVI_PATH` being set, it will not be used when installing cheat sheets directly via navi's own commands. For example when running `navi add repo `, the default paths as per the `directories-next` @@ -20,3 +20,6 @@ package will still be used. To avoid this, you may simply clone repos via a regular `git clone` command, directly into `$NAVI_PATH`. + +Note! `navi info cheats-path` and `navi info config-path` display the *default* path, not +the path set by the user. [It is known that this is a little misleading!](https://github.com/denisidoro/navi/issues/664#issuecomment-1004721178). From 00d5e9d815f5d5b1a7111014afb9ca6fa9581e28 Mon Sep 17 00:00:00 2001 From: tjex Date: Sat, 4 Nov 2023 21:04:15 +0100 Subject: [PATCH 39/39] doc: file rename --- README.md | 2 +- ...paths_and_environment_variables.md => paths_and_env_vars.md} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename docs/{paths_and_environment_variables.md => paths_and_env_vars.md} (100%) diff --git a/README.md b/README.md index 7d63a8aa..62f37865 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ The full syntax and examples can be found [here](docs/cheatsheet_syntax.md). You can: - [setup your own config file](docs/config_file.md) -- [set custom paths for your config file and cheat sheets](docs/paths_and_environment_variables.md) +- [set custom paths for your config file and cheat sheets](docs/paths_and_env_vars.md) - [change colors](docs/customization.md#changing-colors) - [resize columns](docs/customization.md#resizing-columns) - [change how search is performed](docs/customization.md#overriding-fzf-options) diff --git a/docs/paths_and_environment_variables.md b/docs/paths_and_env_vars.md similarity index 100% rename from docs/paths_and_environment_variables.md rename to docs/paths_and_env_vars.md