Unfortunately Purge wall for dual prints is a necessary evil. and Unless you are willing to add Extensive variable replacement in the custom gcode it cannot be dun in custom gcode. The gcode would need to now controller state, Slicer last coordinates, Slicer next coordinates, extruder drive position...