diff --git a/config.yaml b/config.yaml index 8940f82..4656496 100644 --- a/config.yaml +++ b/config.yaml @@ -1,53 +1,27 @@ dotfiles: - - name: .zshrc - path: ~/ - - name: .bash_profile - path: ~/ - - name: .bashrc - path: ~/ - - name: .vimrc - path: ~/ - - name: .gitconfig - path: ~/ - - name: .gitignore_global - path: ~/ - - name: .tmux.conf - path: ~/ - - name: .ssh/config - path: ~/.ssh/ - - name: .config/nvim/init.vim - path: ~/.config/nvim/ - - name: .hyper.js - path: ~/ - - name: .npmrc - path: ~/ - - name: .yarnrc - path: ~/ - - name: .editorconfig - path: ~/ - - name: .aliases - path: ~/ - - name: .functions - path: ~/ - - name: .inputrc - path: ~/ - - name: .hushlogin - path: ~/ - - name: .curlrc - path: ~/ - - name: .wgetrc - path: ~/ - - name: .gemrc - path: ~/ - - name: .config/alacritty/alacritty.yml - path: ~/.config/alacritty/ - - name: .config/karabiner/karabiner.json - path: ~/.config/karabiner/ - - name: .config/iterm2/com.googlecode.iterm2.plist - path: ~/.config/iterm2/ - - name: .aws/config - path: ~/.aws/ - - name: .aws/credentials - path: ~/.aws/ - - name: .docker/config.json - path: ~/.docker/ + - name: ${HOME}/.zshrc + - name: ${HOME}/.bash_profile + - name: ${HOME}/.bashrc + - name: ${HOME}/.vimrc + - name: ${HOME}/.gitconfig + - name: ${HOME}/.gitignore_global + - name: ${HOME}/.tmux.conf + - name: ${HOME}/.ssh/config + - name: ${HOME}/.config/nvim/init.vim + - name: ${HOME}/.hyper.js + - name: ${HOME}/.npmrc + - name: ${HOME}/.yarnrc + - name: ${HOME}/.editorconfig + - name: ${HOME}/.aliases + - name: ${HOME}/.functions + - name: ${HOME}/.inputrc + - name: ${HOME}/.hushlogin + - name: ${HOME}/.curlrc + - name: ${HOME}/.wgetrc + - name: ${HOME}/.gemrc + - name: ${HOME}/.config/alacritty/alacritty.yml + - name: ${HOME}/.config/karabiner/karabiner.json + - name: ${HOME}/.config/iterm2/com.googlecode.iterm2.plist + - name: ${HOME}/.aws/config + - name: ${HOME}/.aws/credentials + - name: ${HOME}/.docker/config.json diff --git a/src/cli.rs b/src/cli.rs index 41ccef9..e61a6d8 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -3,6 +3,13 @@ use clap::Parser; #[derive(Parser, Debug)] #[clap(author, version, about, long_about = None)] pub struct Args { - #[clap(short, long, value_parser)] + #[clap(short, long, value_parser, help = "Path to the configuration file")] pub config: String, + + #[clap( + long, + value_parser, + help = "Optional home directory path. Defaults to home (~/)" + )] + pub home: Option, } diff --git a/src/config.rs b/src/config.rs index 3f9142a..07a4f98 100644 --- a/src/config.rs +++ b/src/config.rs @@ -3,7 +3,6 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Deserialize, Serialize)] pub struct Dotfile { pub name: String, - pub path: String, } #[derive(Debug, Deserialize, Serialize)] diff --git a/src/file_operations.rs b/src/file_operations.rs index ff43eda..19acc5a 100644 --- a/src/file_operations.rs +++ b/src/file_operations.rs @@ -6,12 +6,26 @@ use std::path::{Path, PathBuf}; use symlink::symlink_file; use thiserror::Error; -pub fn find_dotfiles(dotfiles: &[Dotfile]) -> Vec { +const DEFAULT_HOME_PATH: &str = "~"; + +fn create_dotfile_path(path: &str, home_path: Option<&str>) -> String { + path.replace( + "${HOME}", + if home_path.is_some() { + home_path.unwrap() + } else { + DEFAULT_HOME_PATH + }, + ) +} + +pub fn find_dotfiles(dotfiles: &[Dotfile], home_path: Option<&str>) -> Vec { dotfiles .iter() .filter_map(|dotfile| { - let path = - PathBuf::from(shellexpand::tilde(&dotfile.path).to_string()).join(&dotfile.name); + let path = create_dotfile_path(&dotfile.name, home_path); + + let path = PathBuf::from(shellexpand::tilde(&path).to_string()); if path.exists() { Some(path) } else { diff --git a/src/main.rs b/src/main.rs index fc3ff5d..210d50b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,7 @@ fn main() -> Result<(), Box> { let repo_path = get_repo_path()?; println!("{}", "Searching for dotfiles...".yellow()); - let found_dotfiles = find_dotfiles(&config.dotfiles); + let found_dotfiles = find_dotfiles(&config.dotfiles, args.home.as_deref()); println!("{}", "Found the following dotfiles:".green()); for dotfile in &found_dotfiles {