5/12V voltage TTL selector
Try this. OA1 provides interlock between the 5V and 12V supplies (at low slew rate) while D1/R3 and D2/R4 provide break-before-make switching when edges are sharp. 

M1 is a P-channel MOSFET conventionally connected. M2 is an N-channel MOSFET connected in 'reverse' so that the body diode does not normally conduct. During switching the body diode will briefly conduct during the dead time when both MOSFETS are off, and output voltage will drop to ~4.3V with a load. 

R2 is a pullup to allow M1 to switch off completely. If M1 has insufficient Vgs rating for transients on the 12V supply you can simply connect a zener from gate to source without any additional parts. M2 should be a logic-level MOSFET- it must be fully on with 7V Vgs. 







simulate this circuit &ndash; Schematic created using CircuitLab

If the 5V supply appears before or without the 12V supply it will backfeed the 12V supply with 2 diode drops (so the 12V supply will go to ~3.6V)