diff --git a/README.md b/README.md index 58d034e..606151c 100644 --- a/README.md +++ b/README.md @@ -25,45 +25,69 @@ Locations are searched in the following priority: - `$XDG_CONFIG_HOME/homesync.yml` - `$XDG_CONFIG_HOME/homesync/homesync.yml` -That said, it is recommended to modify this config solely from the exposed -homesync CLI. Homesync will take responsibility ensuring the generated -configuration is according to package manager, platform, etc. +The config file should look like the following: + +```yaml +--- +user: + name: jrpotter + email: jrpotter@github.io +local: $HOME/.homesync +remote: + name: origin + branch: master + url: "https://github.com/jrpotter/home-config.git" +packages: + homesync: + configs: + - $HOME/.homesync.yml + - $HOME/.config/homesync/homesync.yml + - $XDG_CONFIG_HOME/homesync.yml + - $XDG_CONFIG_HOME/homesync/homesync.yml + ... +``` + +Copy over [examples/template.yaml](https://github.com/jrpotter/homesync/blob/main/examples/template.yaml) +to where you'd like as a starting point. ## Usage -Verify your installation by running `homesync` from the command line. If -installed, you will likely want to initialize a new config instance. Do so by -typing: +Verify your installation by running `homesync` from the command line. To have +your local repository match the remote, run ```bash -$ homesync init +$ homesync pull ``` -You can then walk through what github repository you want to sync your various -files with. You can have homesync automatically monitor all configuration files -and post updates on changes by running +If you make a change to a configuration tracked by homesync, you can tell +homesync to prep pushing those changes via the `stage` subcommand or rely on +the daemon service to do it for you: ```bash -$ homesync daemon +$ homesync stage +$ homesync daemon & ``` -As changes are made to your `homesync` config or any configuration files -referred to within the `homesync` config, the daemon service will sync the -changes to the local git repository. To push these changes upward, run +Homesync will find all tracked files that have changed and stage them in the +local repository. You can then push those changes using ```bash -$ homesync push --all +$ homesync push ``` -which will expose a git interface for you to complete the push. Lastly, to sync -the remote configurations to your local files, run +If looking to copy a configuration tracked by homesync to your desktop, you +can run ```bash -$ homesync pull --all +$ homesync apply ``` -This will load up a diff wrapper for you to ensure you make the changes you'd -like. +To copy all configurations (and optionally overwrite files that already exist), +you can run + +```bash +$ homesync apply --all [--overwrite] +``` ## Known Issues diff --git a/examples/template.yaml b/examples/template.yaml new file mode 100644 index 0000000..2b4b340 --- /dev/null +++ b/examples/template.yaml @@ -0,0 +1,16 @@ +--- +user: + name: name + email: email@email.com +local: $HOME/.homesync +remote: + name: origin + branch: master + url: "https://github.com/owner/repo.git" +packages: + homesync: + configs: + - $HOME/.homesync.yml + - $HOME/.config/homesync/homesync.yml + - $XDG_CONFIG_HOME/homesync.yml + - $XDG_CONFIG_HOME/homesync/homesync.yml diff --git a/src/daemon.rs b/src/daemon.rs index 628a1bb..9234ec3 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -157,7 +157,7 @@ pub fn launch(mut pc: PathConfig, repo: Repository, freq_secs: u64) -> Result<() let mut state = WatchState::new(poll_tx, &mut watcher)?; state.update(&pc); loop { - git::apply(&pc, &repo)?; + git::stage(&pc, &repo)?; // Received paths should always be fully resolved. match watch_rx.recv() { Ok(DebouncedEvent::NoticeWrite(p)) => { diff --git a/src/git.rs b/src/git.rs index 09d269d..4151cdc 100644 --- a/src/git.rs +++ b/src/git.rs @@ -132,7 +132,7 @@ pub fn init(pc: &PathConfig) -> Result { } // ======================================== -// Application +// Staging // ======================================== fn find_repo_files(path: &Path) -> Result> { @@ -166,7 +166,7 @@ fn find_package_files(pc: &PathConfig) -> Vec { seen } -pub fn apply(pc: &PathConfig, repo: &Repository) -> Result<()> { +pub fn stage(pc: &PathConfig, repo: &Repository) -> Result<()> { let workdir = repo.workdir().ok_or(Error::NotWorkingRepo)?; let repo_files = find_repo_files(&workdir)?; let package_files = find_package_files(&pc); diff --git a/src/lib.rs b/src/lib.rs index bde6c16..4e4bb26 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,12 +8,6 @@ use std::error::Error; type Result = std::result::Result<(), Box>; -pub fn run_apply(config: PathConfig) -> Result { - let repo = git::init(&config)?; - git::apply(&config, &repo)?; - Ok(()) -} - pub fn run_daemon(config: PathConfig, freq_secs: u64) -> Result { let repo = git::init(&config)?; daemon::launch(config, repo, freq_secs)?; @@ -30,3 +24,9 @@ pub fn run_push(config: PathConfig) -> Result { git::push(&config, &mut repo)?; Ok(()) } + +pub fn run_stage(config: PathConfig) -> Result { + let repo = git::init(&config)?; + git::stage(&config, &repo)?; + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 32610bb..5601551 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,9 +38,6 @@ fn main() { .help("Specify a configuration file to use in place of defaults") .takes_value(true), ) - .subcommand( - App::new("apply").about("Find all changes and apply them to the local repository"), - ) .subcommand( App::new("daemon") .about("Start up a new homesync daemon") @@ -62,6 +59,9 @@ fn main() { ) .subcommand(App::new("list").about("See which packages homesync manages")) .subcommand(App::new("push").about("Push changes from local to remote")) + .subcommand( + App::new("stage").about("Find all changes and stage them onto the local repository"), + ) .get_matches(); if let Err(e) = dispatch(matches) { @@ -73,7 +73,6 @@ fn dispatch(matches: clap::ArgMatches) -> Result<(), Box> { let candidates = find_candidates(&matches)?; let config = homesync::config::load(&candidates)?; match matches.subcommand() { - Some(("apply", _)) => Ok(homesync::run_apply(config)?), Some(("daemon", matches)) => { let freq_secs: u64 = match matches.value_of("frequency") { Some(f) => f.parse().unwrap_or(0), @@ -88,6 +87,7 @@ fn dispatch(matches: clap::ArgMatches) -> Result<(), Box> { } Some(("list", _)) => Ok(homesync::run_list(config)?), Some(("push", _)) => Ok(homesync::run_push(config)?), + Some(("stage", _)) => Ok(homesync::run_stage(config)?), _ => unreachable!(), } }