feat: add {{project_name}} expansion variable

This commit is contained in:
CJ van den Berg 2026-02-24 17:30:13 +01:00
parent ff0495a265
commit f1a8efa318
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -1,5 +1,6 @@
/// Expand variables in arg
/// {{project}} - The path to the current project directory
/// {{project_name}} - The basename of the current project directory
/// {{file}} - The path to the current file
/// {{line}} - The line number of the primary cursor
/// {{column}} - The column of the primary cursor
@ -76,6 +77,13 @@ const functions = struct {
return try allocator.dupe(u8, tp.env.get().str("project"));
}
pub fn project_name(allocator: Allocator) Error![]const u8 {
const project_ = tp.env.get().str("project");
const basename_begin = std.mem.lastIndexOfScalar(u8, project_, std.fs.path.sep);
const basename = if (basename_begin) |begin| project_[begin + 1 ..] else project_;
return try allocator.dupe(u8, basename);
}
pub fn file(allocator: Allocator) Error![]const u8 {
const mv = tui.mainview() orelse return &.{};
const ed = mv.get_active_editor() orelse return &.{};