SSH command_not_found_handle

I am too lazy and I just want to paste a servername or IP into my terminal for connecting via SSH:

$ server
Connecting via SSH to root@server
$ 192.168.1.10
Connecting via SSH to root@192.168.1.10
$ vaporup@192.168.1.10
Connecting via SSH to vaporup@192.168.1.10

Bash

command_not_found_handle() {

  if [[ "$1" == *"@"* ]]; then
    echo "Connecting via SSH to $1"
    ssh "$1"
  else
    echo "Connecting via SSH to root@$1"
    ssh "root@$1"
  fi
}

Zsh

For ZSH you just have to add an *r* to the function name

command_not_found_handle -> command_not_found_handler
command_not_found_handler() {

  if [[ "$1" == *"@"* ]]; then
    echo "Connecting via SSH to $1"
    ssh "$1"
  else
    echo "Connecting via SSH to root@$1"
    ssh "root@$1"
  fi
}

Short variant

Bash

command_not_found_handle() { [[ "$1" == *"@"* ]] && ssh "$1" || ssh "root@$1"; }

Zsh

command_not_found_handler() { [[ "$1" == *"@"* ]] && ssh "$1" || ssh "root@$1"; }