# preferred way
uses "alt-space" combo to switch, just run once to set the combo
setxkbmap -option 'grp:alt_space_toggle' 'pt,us'

# alternative and old way
prints the current layout, searchs for pt and if so changes to us.
if it's not pt, change to it then.
grep redirects its output to /dev/null so we don't have anything printed when
running a xterm

setxkbmap -print | grep pt > /dev/null && setxkbmap us || setxkbmap pt