adding relative filename expansion

pull/11164/head
Théo Daron 2 months ago
parent e774706440
commit 2f98016038

@ -11,12 +11,14 @@ Helix provides several variables that can be used when typing commands or creati
| --- | --- |
| `%{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. |
| `%{cwd}` | The absolute path of the current working directory of Helix. |
| `%{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. |
| `%sh{cmd}` | Executes `cmd` with the default shell and returns the command output, if any. |

@ -51,6 +51,27 @@ impl Editor {
.and_then(|it| it.to_str())
.unwrap_or(crate::document::SCRATCH_BUFFER_NAME)
.to_owned(),
"filename:git_rel" => {
// This will get git repo root or cwd if not inside a git repo.
let workspace_path = helix_loader::find_workspace().0;
doc.path()
.and_then(|p| {
p.strip_prefix(workspace_path)
.unwrap_or(p)
.to_str()
})
.unwrap_or(crate::document::SCRATCH_BUFFER_NAME)
.to_owned()
}
"filename:rel" => {
let cwd = helix_stdx::env::current_working_dir();
doc.path()
.and_then(|p| {
p.strip_prefix(cwd).unwrap_or(p).to_str()
})
.unwrap_or(crate::document::SCRATCH_BUFFER_NAME)
.to_owned()
}
"dirname" => doc
.path()
.and_then(|p| p.parent())

Loading…
Cancel
Save