I have a laptop which is connected to a cloud workstation. All my compilation happens on the cloud workstation, but I modify files on my laptop. I want to sync files between the two, but I want only source files to be synced, not build, configuration, etc. I want to make it so that if a folder is named src, it and its contents get recursively synced.

For example, ~/workspace/src/file1.cpp and ~/workspace/src/myfolder/file2.cpp get synced but ~/workspace/build/file3.cpp does not. I keep making and deleting projects and I do not want to have to re-configure file paths for syncing every time I create a new project with a new src directory.

Right now I'm using Unison file syncing tool for Mac and I don't know how to do this. Can someone show me?


Unfortunately it appears that Unison (alone) cannot easily do this. From the usage of ignorenot xxx in the Unison manual:

In particular, putting ignore = Path * in your profile and then using ignorenot to select particular paths to be synchronized will not work. Instead, you should use the path preference to choose particular paths to synchronize.

Since that was exactly what I had in mind as a solution, means that there is no good solution. Here a few useful ideas though:

  1. Manually add a new path for each project: This is just what the above quote suggests. For each new project you start and each new src directory you want to sync, add a line

    Path = path/to/src

    to your Unison profile.

  2. Manually ignore the build and configuration files: Maybe all your build and configuration files have just a few different patterns you can match against? You could tell Unison to ignore those patterns in particular by adding something to your Unison profile like

    ignore = Name *.o              #ignore object files
    ignore = Name build            #ignore paths that end with "build"
    ignore = Name {.*,*}.sw[ponx]  #ignore pesky vim swap files
    ignore = ...
  3. Write a script to help: You could certainly write a script that searches for all the directories named src and calls Unison on them individually. But that seems kinda silly. You could write a script that helps with point (1) above though. Write a script that finds all the paths named src and for each such path, add the line

    Path = /path/to/src

    to some file AllThePaths, and then just have the line

    include AllThePaths

    in your Unison profile.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.