From 253540811a0aeeceebda974c7e9a3c3fd1debd10 Mon Sep 17 00:00:00 2001 From: Paul Delafosse Date: Wed, 18 Sep 2024 08:03:31 +0200 Subject: [PATCH] fix: fix shellexpand again --- bats-tests/tests.sh | 17 ++++++++--------- bats-tests/tom_home/dotfiles/bombadil.toml | 14 ++++++-------- bats-tests/tom_home/dotfiles/{bashrc => shrc} | 0 src/paths/mod.rs | 8 ++++++-- 4 files changed, 20 insertions(+), 19 deletions(-) rename bats-tests/tom_home/dotfiles/{bashrc => shrc} (100%) diff --git a/bats-tests/tests.sh b/bats-tests/tests.sh index 3ed144e4..e0b8933d 100644 --- a/bats-tests/tests.sh +++ b/bats-tests/tests.sh @@ -106,24 +106,23 @@ setup() { @test "Profile should override default vars" { run bombadil link assert_success - assert_file_exist "$HOME/.bashrc" - assert_symlink_to "$HOME/dotfiles/.dots/bashrc" "$HOME/.bashrc" - assert_file_contains "$HOME/.bashrc" "export JAVA_HOME=/etc/java11-openjdk" + assert_file_exist "$HOME/.shrc" + assert_symlink_to "$HOME/dotfiles/.dots/shrc" "$HOME/.shrc" + assert_file_contains "$HOME/.shrc" "export JAVA_HOME=/etc/java11-openjdk" run bombadil link -p java-16 assert_success - assert_file_contains "$HOME/.bashrc" "export JAVA_HOME=/etc/java16-openjdk" + assert_file_contains "$HOME/.shrc" "export JAVA_HOME=/etc/java16-openjdk" } @test "Profile should override scoped vars" { run bombadil link assert_success - assert_file_exist "$HOME/.bashrc" - assert_symlink_to "$HOME/dotfiles/.dots/bashrc" "$HOME/.bashrc" - assert_file_contains "$HOME/.bashrc" "export JAVA_HOME=/etc/java11-openjdk" + assert_file_exist "$HOME/.shrc" + assert_symlink_to "$HOME/dotfiles/.dots/shrc" "$HOME/.shrc" + assert_file_contains "$HOME/.shrc" "export JAVA_HOME=/etc/java11-openjdk" run bombadil link -p java-17 assert_success - assert_file_contains "$HOME/.bashrc" "export JAVA_HOME=/etc/java17-openjdk" + assert_file_contains "$HOME/.shrc" "export JAVA_HOME=/etc/java17-openjdk" } - diff --git a/bats-tests/tom_home/dotfiles/bombadil.toml b/bats-tests/tom_home/dotfiles/bombadil.toml index 82eef274..53fc9659 100644 --- a/bats-tests/tom_home/dotfiles/bombadil.toml +++ b/bats-tests/tom_home/dotfiles/bombadil.toml @@ -3,30 +3,28 @@ dotfiles_dir = "dotfiles" gpg_user_id = "test@toml.bombadil.org" [settings] -prehooks = [ "echo Hello from bombadil" ] -vars = [ "vars.toml"] +prehooks = ["echo Hello from bombadil"] +vars = ["vars.toml"] [settings.dots] alacritty = { source = "dummy.dot", target = ".config/dummy.dot" } maven = { source = "maven/settings.xml", target = ".m2/settings.xml" } -bash = { source = "bashrc", target = "~/.bashrc" } +bash = { source = "shrc", target = "~/.shrc" } [profiles.corporate.dots] maven = { source = "maven/corporate.settings.xml", target = ".m2/settings.xml" } [profiles.i3.dots] -i3 = { source = "i3", target = ".config/i3" } +i3 = { source = "i3", target = ".config/i3" } [profiles.sway.dots] -sway = { source = "sway", target = ".config/sway" } +sway = { source = "sway", target = ".config/sway" } [profiles.java-16] -vars = [ "profiles/java16.toml"] +vars = ["profiles/java16.toml"] [profiles.java-17.dots] bash = { vars = "profiles/java17.toml" } [profiles.corporate-sway] extra_profiles = ["corporate", "sway"] - - diff --git a/bats-tests/tom_home/dotfiles/bashrc b/bats-tests/tom_home/dotfiles/shrc similarity index 100% rename from bats-tests/tom_home/dotfiles/bashrc rename to bats-tests/tom_home/dotfiles/shrc diff --git a/src/paths/mod.rs b/src/paths/mod.rs index 05a0a4ff..42b0f3cb 100644 --- a/src/paths/mod.rs +++ b/src/paths/mod.rs @@ -32,8 +32,12 @@ pub trait DotPaths { impl DotPaths for Dot { fn target(&self) -> Result { - if self.target.is_absolute() { - Ok(self.target.clone()) + let path = &self.target.to_string_lossy(); + let path = shellexpand::tilde(path.as_ref()); + let path = Path::new(path.as_ref()); + + if path.is_absolute() { + Ok(path.to_path_buf()) } else { home_dir() .map(|home| home.join(&self.target))