task: Add ZED_DIRNAME and ZED_RELATIVE_FILE task variables (#12245)

Release Notes:

- Added ZED_RELATIVE_FILE (path to current file relative to worktree
root) and ZED_DIRNAME (path to the directory containing current file)
task variables.
This commit is contained in:
Piotr Osiewicz 2024-05-24 16:04:24 +02:00 committed by GitHub
parent b0d89d6f34
commit 0eff1eae76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 45 additions and 16 deletions

View file

@ -124,9 +124,13 @@ impl ResolvedTask {
pub enum VariableName {
/// An absolute path of the currently opened file.
File,
/// the currently opened filename.
/// A path of the currently opened file (relative to worktree root).
RelativeFile,
/// The currently opened filename.
Filename,
/// stem (filename without extension) of the currently opened file.
/// The path to a parent directory of a currently opened file.
Dirname,
/// Stem (filename without extension) of the currently opened file.
Stem,
/// An absolute path of the currently opened worktree, that contains the file.
WorktreeRoot,
@ -165,6 +169,8 @@ impl std::fmt::Display for VariableName {
match self {
Self::File => write!(f, "{ZED_VARIABLE_NAME_PREFIX}FILE"),
Self::Filename => write!(f, "{ZED_VARIABLE_NAME_PREFIX}FILENAME"),
Self::RelativeFile => write!(f, "{ZED_VARIABLE_NAME_PREFIX}RELATIVE_FILE"),
Self::Dirname => write!(f, "{ZED_VARIABLE_NAME_PREFIX}DIRNAME"),
Self::Stem => write!(f, "{ZED_VARIABLE_NAME_PREFIX}STEM"),
Self::WorktreeRoot => write!(f, "{ZED_VARIABLE_NAME_PREFIX}WORKTREE_ROOT"),
Self::Symbol => write!(f, "{ZED_VARIABLE_NAME_PREFIX}SYMBOL"),