I feel like I should have written this script a long time ago…
Hopefully, it will be useful to others as well.
Move tab right
Move tab left
And I also updated my script to attach a tab to another window. I think it works much better now.