Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed config format #4

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 26 additions & 52 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 8 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
}
1 change: 0 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
20 changes: 17 additions & 3 deletions src/file_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,26 @@ use std::path::{Path, PathBuf};
use symlink::symlink_file;
use thiserror::Error;

pub fn find_dotfiles(dotfiles: &[Dotfile]) -> Vec<PathBuf> {
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<PathBuf> {
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 {
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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 {
Expand Down
Loading