0

I have a function I found online to add to my .bashrc which spawns a new SSH session with the hostname:

# Opens SSH on a new screen window with the appropriate name.
screen_ssh() {
    numargs=$#
    screen -t ${!numargs} ssh $@
if [ $TERM == "screen" -o $TERM == "screen.linux" ] && [ ! -z "$PS1" ];  then
    alias ssh=screen_ssh
fi

if [[ $- == *i* ]]
then
  [ "$STY" ] && ssh() { screen -t "${1##*@}" ssh "$@"; } # Spawn new window in Screen  for SSH
fi

but it will also do this for aliases, like so:

lsrem(){ ssh $1 "ls -l" ; }

so my question is how to stop it from working with aliases/functions and only work interactively for:

ssh somehost

Thanks in advance.

dueyfinster
  • 317
  • 2
  • 5
  • 14

1 Answers1

0

I found a (hacky) way:

# Opens SSH on a new screen window with the appropriate name.
screen_ssh() {
    numargs=$#
        if [ "$numargs" -eq "1" ];
        then   
                screen -t ${!numargs} ssh $@
        else   
                ssh $@
        fi
}
if [ $TERM == "screen" -o $TERM == "screen.linux" ]; then
    alias ssh=screen_ssh
fi

This checks num of args to SSH is greater then one, so doesn't spawn a new screen seession when I do:

ssh hostname

I'm definitely open to better ways to do this!

dueyfinster
  • 317
  • 2
  • 5
  • 14