Shamans, how does totem twisting work?

Or better yet, make a macro that does this.