Skip to content

Commit

Permalink
fix: fix shellexpand again
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Sep 18, 2024
1 parent 65b2318 commit 2535408
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
17 changes: 8 additions & 9 deletions bats-tests/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

14 changes: 6 additions & 8 deletions bats-tests/tom_home/dotfiles/bombadil.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,28 @@ dotfiles_dir = "dotfiles"
gpg_user_id = "[email protected]"

[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"]


File renamed without changes.
8 changes: 6 additions & 2 deletions src/paths/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ pub trait DotPaths {

impl DotPaths for Dot {
fn target(&self) -> Result<PathBuf> {
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))
Expand Down

0 comments on commit 2535408

Please sign in to comment.