Created
October 26, 2019 20:03
-
-
Save durch/51fd3e38ed4440ff3f1a97887653ba6e to your computer and use it in GitHub Desktop.
Sync multiple folders wit abs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!abs | |
is = f(x) { | |
return x != "" | |
} | |
onedrive = flag("o") || flag("onedrive") | |
dryrun = flag("d") | |
source_dir = pwd() | |
wsl_pattern = "<wsl home dir like /home/user>" | |
win_pattern = "<win home dir like /c/Users/user>" | |
onedrive_pattern = "<onedrie dir like /c/Users/user/OneDrive>" | |
wsl = `echo $source_dir | grep $wsl_pattern` | |
win = `echo $source_dir | grep $win_pattern` | |
if is(wsl) { | |
source_pattern = wsl_pattern | |
target_pattern = win_pattern | |
} else if is(win) { | |
source_pattern = win_pattern | |
target_pattern = wsl_pattern | |
} else { | |
exit(1, "Invalid pattern for source dir -> $source_dir") | |
} | |
target_dir = `echo $source_dir | sed "s.$source_pattern.$target_pattern.g"` | |
onedrive_dir = `echo $source_dir | sed "s.$source_pattern.$onedrive_pattern.g"` | |
echo("source dir -> $source_dir") | |
echo("target_dir -> $target_dir") | |
if dryrun { | |
echo("unison $source_dir $target_dir -ignore 'Name = venv' -ignore 'Name = target' -ignore 'Name = .idea' -ignore 'Name = .vscode' -batch") | |
} else { | |
exec("mkdir -p $target_dir") | |
exec("unison $source_dir $target_dir -ignore 'Name = venv' -ignore 'Name = target' -ignore 'Name = .idea' -ignore 'Name = .vscode' -batch") | |
if onedrive { | |
exec("unison $source_dir $onedrive_dir -ignore 'Name = venv' -ignore 'Name = target' -ignore 'Name = .idea' -ignore 'Name = .vscode' -batch") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment