If this is for retail, the below should work. No idea if it will work like you want for classic.
You basically want it to dash every time you hold down shift.
If your mouse is over something friendly, dead, or over nothing, go passive. Passive is the only thing I know of that makes the pet return to your side.
Otherwise if your mouse is over a living enemy, attack and continue attacking it. The “continue attacking” part won’t work with if your pet was previously put in passive which is why you need petassist.
You may be able to get away with just “Dash” instead of “Dash(Basic Ability)”
/stopmacro [nopet]
/petpassive [@mouseover,noexists][@mouseover,help][@mouseover,dead]
/cast [mod:shift] Dash(Basic Ability)
/petassist [@mouseover,harm,nodead]
/petattack [@mouseover,harm,nodead]
One thing with the retail version is that there is a small delay between “petattack” and your pet using its basic attack abilities even when those basic attack abilities are on autocast. It does reduce your pet’s dps slightly and if you are really concerned with squeezing every last deep into your dps you have 2 choices.
Get the LongMacro addon which allows up to 1k long text strings to be used in a macro. The WoW macro API’s actually support macros of that length but unfortunately the macro box where you type the text into is limited to 255 characters (boo!). With the Long Macro addon you can do this macro:
/stopmacro [nopet]
/petpassive [@mouseover,noexists][@mouseover,help][@mouseover,dead]
/cast [mod:shift] Dash(Basic Ability)
/petassist [@mouseover,harm,nodead]
/petattack [@mouseover,harm,nodead]
/cast [@mouseover,harm,nodead] Claw(Basic Attack)
/cast [@mouseover,harm,nodead] Bite(Basic Attack)
/cast [@mouseover,harm,nodead] Smack(Basic Attack)
Without it you would need to break the macro up into 2 chunks and have the macro you activate “click” the second macro button.
/stopmacro [nopet]
/petpassive [@mouseover,noexists][@mouseover,help][@mouseover,dead]
/cast [mod:shift] Dash(Basic Ability)
/click [@mouseover,harm,nodead] ButtonIDofOtherMacroButton
And then on a second action bar button you would have this macro
/petassist [@mouseover,harm,nodead]
/petattack [@mouseover,harm,nodead]
/cast [@mouseover,harm,nodead] Claw(Basic Attack)
/cast [@mouseover,harm,nodead] Bite(Basic Attack)
/cast [@mouseover,harm,nodead] Smack(Basic Attack)
To get the “ButtonIDofOtherMacroButton” use the /framestack chat command and then hover the mouse over button you plan on putting the second macro. You’ll see a popup screen in your upper right corner that will say something like “MultiBarBottomRightButton1” and that’s what you would type in above. I believe it is case sensitive. Enter /framestack again to turn off that popup.
Below is a list of good resources for macros:
https://wow.gamepedia.com/Macro_commands
https://us.battle.net/forums/en/wow/topic/16200990425
https://wowwiki.fandom.com/wiki/Making_a_macro
https://wow.gamepedia.com/MACRO_cast
https://wow.gamepedia.com/Macro_conditionals
https://wow.gamepedia.com/UnitId
I have learned a lot by reading the UI & Macro forum. The guys there are really good resources.