#!/usr/bin/env nu # SPDX-License-Identifier: AGPL-3.0-only # Copyright (c) 2026 MatrixFurry use std/log const config_path: path = ".rawrsync.toml" # Easily sync or deploy projects using `rsync`. Intended to somewhat replicate CLion's Deployment feature for use with other IDEs. # # Configure with `.rawrsync.toml` in your project root. For example: # ```toml # [org-server-23] # user = "username" # address = "org-server-23.tailnet-name.ts.net" # path = "/home/username/deployment/project/" # Destination path on the server # # [vr-desktop] # user = "username" # address = "vr-desktop.tailnet-name.ts.net" # path = "/home/username/vr/project" # ``` export def main [ select?: string # Select a configuration by name --continuous (-c) # Sync on file change --verbose (-v) # Verbose rsync logging (use NU_LOG_LEVEL=debug to set rawrsync logging level) ] { if not ($config_path | path exists) { log critical $"Could not find configuration file in current directory \(($config_path)\)" exit 1 } let src: path = pwd | path expand let config = open $config_path | transpose name data let dest: record = if ($config | length) == 1 { $config | get 0.data } else if ($select | is-not-empty) { let selected_entry = $config | where name == $select if ($selected_entry | length) < 1 { log critical $"Could not find selected configuration \"($select)\"" exit 1 } $selected_entry | get 0.data } else { $config | input list -d name "Sync to..." | get data } if $continuous { # TODO: only run rsync on changed files watch --verbose $src {|| sync --verbose=$verbose $src $dest} } else { sync --verbose=$verbose $src $dest } } def sync [ src: path dest: record --verbose (-v) ] { let args = [ -zar # Compress, archive (preserve permissions etc.), recursive (if $verbose {"-v"} else {""}) --exclude=.svn --exclude=.cvs --exclude=.DS_Store --exclude=.git --exclude=.hg --exclude=*.hprof --exclude=*.pyc --exclude=.jj --exclude=.idea --exclude=.zed --exclude=.rawrsync.toml --delete ($src ++ "/") # make sure the source directory path ends with a / $"($dest.user)@($dest.address)://($dest.path)" ] | where ($it | is-not-empty) log info $"Syncing to ($dest.address)" log debug $"Sync ($src) to ($dest.path) using rsync" log debug $"rsync ($args | str join ' ')" rsync ...$args }