diff --git a/src/tui/expansion.zig b/src/tui/expansion.zig index c98ab39..d705078 100644 --- a/src/tui/expansion.zig +++ b/src/tui/expansion.zig @@ -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 &.{};