synclib
A small Go tool for creating symbolic links
Created out of infuriating difficulty of creating symbolic links on windows
Instruction Formats
The tool supports two formats for defining symbolic links:
1. CSV Format (Legacy)
Simple comma-separated values with the format: <source>,<destination>[,force][,hard][,delete]
For example:
source_path,target_path
source_path,target_path,true
source_path,target_path,true,true
source_path,target_path,true,true,true
Or with named flags:
source_path,target_path,force=true,hard=true,delete=true
source_path,target_path,f=true,h=true,d=true
2. YAML Format (Recommended)
A more readable format using YAML:
links:
- source: ~/Documents/config.ini
target: ~/.config/app/config.ini
force: true
- source: ~/Pictures
target: ~/Documents/Pictures
hard: true
force: true
- source: ~/Scripts/script.sh
target: ~/bin/script.sh
delete: true
Alternatively, you can use an array directly:
- source: ~/Documents/config.ini
target: ~/.config/app/config.ini
force: true
- source: ~/Pictures
target: ~/Documents/Pictures
hard: true
Input Methods
The tool supports input of these instructions through:
- Stdin
echo "this,that" | sync
- Run arguments
sync this,that foo,bar "foo 2","C:/bar"
- Files
sync -f <file>
(CSV format)sync -f <file.yaml>
orsync -f <file.yml>
(YAML format)- Where the file contains instructions, one per line for CSV or structured YAML
- Directories
sync -r <directory>
- This mode will look for "sync", "sync.yaml", or "sync.yml" files recursively in directories and run their instructions
Options
force: true
- Overwrite an existing symbolic link at the target locationhard: true
- Create a hard link instead of a symbolic linkdelete: true
- Delete a non-symlink file at the target location (impliesforce: true
)
Use case
I have a lot of folders (documents, projects, configurations) backed up via Seafile and to have the software using those folders find them at their usual location I'm creating soft symbolic links from the seafile drive to their original location
It would be problematic to have to redo all (or some part) of these symlinks when reinstalling the OS or having something somewhere explode (say software uninstalled) so I have all the instructions in sync files in individual folders in the seafile drive
Which means I can easily back up my configuration and sync -r ~/Seafile
to symlink it where it belongs