task: Add ZED_RELATIVE_DIR task variable (#31657)
This is my first contribution to zed, let me know if I missed anything.
There is no corresponding issue/discussion.
`$ZED_RELATIVE_DIR` can be used in cases where a task's command's
filesystem namespace (e.g. inside a container) is different than the
host, where absolute paths cannot work.
I modified `relative_path` to `relative_file` after the addition of
`relative_dir`.
For top-level files, where `relative_file.parent() == Some("")`, I use
`"."` for `$ZED_RELATIVE_DIR`, which is a valid relative path in both
*nix and windows.
Thank you for building zed, and open-sourcing it. I hope to contribute
more as I use it as my primary editor.
Release Notes:
- Added ZED_RELATIVE_DIR (path to current file's directory relative to
worktree root) task variable.
This commit is contained in:
@@ -151,6 +151,8 @@ pub enum VariableName {
|
||||
File,
|
||||
/// A path of the currently opened file (relative to worktree root).
|
||||
RelativeFile,
|
||||
/// A path of the currently opened file's directory (relative to worktree root).
|
||||
RelativeDir,
|
||||
/// The currently opened filename.
|
||||
Filename,
|
||||
/// The path to a parent directory of a currently opened file.
|
||||
@@ -194,6 +196,7 @@ impl FromStr for VariableName {
|
||||
"FILE" => Self::File,
|
||||
"FILENAME" => Self::Filename,
|
||||
"RELATIVE_FILE" => Self::RelativeFile,
|
||||
"RELATIVE_DIR" => Self::RelativeDir,
|
||||
"DIRNAME" => Self::Dirname,
|
||||
"STEM" => Self::Stem,
|
||||
"WORKTREE_ROOT" => Self::WorktreeRoot,
|
||||
@@ -226,6 +229,7 @@ impl std::fmt::Display for VariableName {
|
||||
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::RelativeDir => write!(f, "{ZED_VARIABLE_NAME_PREFIX}RELATIVE_DIR"),
|
||||
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"),
|
||||
|
||||
Reference in New Issue
Block a user