Easy way to duplicate a KiCAD project

Sometimes you need to duplicate a KiCAD project, e.g. if you are splitting a KiCAD project into smaller ones, you want to try out a design change outside of your versioning system, or maybe you just want to start off with a non-empty KiCAD project. Like a lot of other tasks in KiCAD, you can accomplish this with a little command line elbow grease. Here is how I do it.

In this example we're duplicating the existing project Controller_v2 to a new project called MyAwsomeProject.

1. Install the mmv tool from the Ubuntu package repo, it's perfect for this case
$ sudo apt install mmv
2. Copy your KiCAD project folder to a new name
$ cp --recursive Controller_v2/ MyAwsomeProject
Hint: Use a project name which does not exist in an English dictionary, so we safely can use raw text replacement in step 5 below.

3. Step into the new project's folder and rename all directories and files from 'Controller_v2' to 'MyAwsomeProject'
$ cd MyAwsomeProject
$ mmv -r ';*Controller_v2*' 'MyAwsomeProject#3'
4. Optional: Run this to view all places the text 'Controller_v2' will be replaced
$ grep --recursive --binary-files=without-match --with-filename --line-number --before-context=3 --after-context=1 --color 'Controller_v2'

5. Use ex to replace text in all relevant files inside the project
(See http://mywiki.wooledge.org/BashFAQ/021)
      $ shopt -s globstar
      $ ex -sc 'argdo %s/Controller_v2/MyAwsomeProject/ge|x' ./**
Done! You can now open the new project i KiCAD, free from all references to the original project :-)

Tested February 2020 with KiCAD (5.1.5), bash (4.4.20) and Linux Mint 19.3, but this should work on all Debian-based distros.

No comments:

Post a Comment