adding git_repo variable

This commit is contained in:
Théo Daron 2024-09-12 09:18:56 +02:00
parent 2f98016038
commit 385ea7c07e
2 changed files with 11 additions and 5 deletions

View File

@ -10,13 +10,14 @@ ## Using variables in typed commands and mapped shortcuts
| Variable | Description | | Variable | Description |
| --- | --- | | --- | --- |
| `%{basename}` | The name and extension of the currently focused file. | | `%{basename}` | The name and extension of the currently focused file. |
| `%{filename}` | The absolute path of the currently focused file. |
| `%{filename:rel}` | The relative path of the file according to the current working directory (will give absolute path if the file is not a child of the current working directory) |
| `%{filename:git_rel}` | The relative path of the file according to the git repo, or current working directory if not inside a git repo. (will give absolute path if the file is not a child of the git directory or the cwd) |
| `%{ext}` | The extension of the current file |
| `%{lang}` | The language of the current file |
| `%{dirname}` | The absolute path of the parent directory of the currently focused file. | | `%{dirname}` | The absolute path of the parent directory of the currently focused file. |
| `%{cwd}` | The absolute path of the current working directory of Helix. | | `%{cwd}` | The absolute path of the current working directory of Helix. |
| `%{git_repo}` | The absolute path of the git repository helix is opened in. Fallback to `cwd` if not inside a git repository|
| `%{filename}` | The absolute path of the currently focused file. |
| `%{filename:rel}` | The relative path of the file according to `cwd` (will give absolute path if the file is not a child of the current working directory) |
| `%{filename:git_rel}` | The relative path of the file according to `git_repo` (will give absolute path if the file is not a child of the git directory or the cwd) |
| `%{ext}` | The extension of the current file |
| `%{lang}` | The language of the current file |
| `%{linenumber}` | The line number where the primary cursor is positioned. | | `%{linenumber}` | The line number where the primary cursor is positioned. |
| `%{cursorcolumn}` | The position of the primary cursor inside the current line. | | `%{cursorcolumn}` | The position of the primary cursor inside the current line. |
| `%{selection}` | The text selected by the primary cursor. | | `%{selection}` | The text selected by the primary cursor. |

View File

@ -78,6 +78,11 @@ pub fn expand_variable_in_string<'a>(&self, input: &'a str) -> anyhow::Result<Co
.and_then(std::path::Path::to_str) .and_then(std::path::Path::to_str)
.unwrap_or(crate::document::SCRATCH_BUFFER_NAME) .unwrap_or(crate::document::SCRATCH_BUFFER_NAME)
.to_owned(), .to_owned(),
"git_repo" => helix_loader::find_workspace()
.0
.to_str()
.unwrap_or("")
.to_owned(),
"cwd" => helix_stdx::env::current_working_dir() "cwd" => helix_stdx::env::current_working_dir()
.to_str() .to_str()
.unwrap() .unwrap()