feat: Detect relative window root, join with project root

Signed-off-by: Andrew Kofink <ajkofink@gmail.com>
This commit is contained in:
Andrew Kofink
2024-06-07 19:18:11 -04:00
parent 1d6a53efac
commit a9a85fdfff
3 changed files with 25 additions and 20 deletions

View File

@@ -1,4 +1,6 @@
## Unreleased
### Enhancements
- Detect relative window root, join with project root
### Fixes
- Session path is project root, not first window root
### Misc

View File

@@ -36,12 +36,16 @@ module Tmuxinator
yaml["synchronize"] || false
end
# The expanded, joined window root path
# Relative paths are joined to the project root
def root
_yaml_root || _project_root
return _project_root unless _yaml_root
File.expand_path(_yaml_root, _project_root).shellescape
end
def _yaml_root
File.expand_path(yaml["root"]).shellescape if yaml["root"]
yaml["root"]
end
def _project_root

View File

@@ -7,6 +7,8 @@ describe Tmuxinator::Window do
let(:panes) { ["vim", nil, "top"] }
let(:window_name) { "editor" }
let(:synchronize) { false }
let(:root) {}
let(:root?) { root }
let(:yaml) do
{
window_name => {
@@ -16,27 +18,14 @@ describe Tmuxinator::Window do
],
"synchronize" => synchronize,
"layout" => "main-vertical",
"panes" => panes
}
}
end
let(:yaml_root) do
{
"editor" => {
"root" => "/project/override",
"root?" => true,
"pre" => [
"echo 'I get run in each pane. Before each pane command!'",
nil
],
"layout" => "main-vertical",
"panes" => panes
"panes" => panes,
"root" => root,
"root?" => root?,
}
}
end
let(:window) { described_class.new(yaml, 0, project) }
let(:window_root) { described_class.new(yaml_root, 0, project) }
shared_context "window command context" do
let(:project) { double(:project) }
@@ -81,9 +70,19 @@ describe Tmuxinator::Window do
end
end
context "with window root" do
context "with absolute window root" do
let(:root) { "/project/override" }
it "gets the window root" do
expect(window_root.root).to include("/project/override")
expect(window.root).to include("/project/override")
end
end
context "with relative window root" do
let(:root) { "relative" }
it "joins the project root" do
expect(window.root).to include("/project/tmuxinator/relative")
end
end
end