2013-04-09 112 views
0

我有一个功能,我在网上找到要添加到我的.bashrc其滋生与主机名新的SSH会话:通过SSH创建一个新的屏幕窗口?

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

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

,但它也将做到这一点的别名,就像这样:

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

所以我的问题是如何从别名/功能停止工作,并只用于交互工作:

ssh somehost 

在此先感谢。

回答

0

我发现了一个(哈克)的方式:

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

此检查参数传递给SSH的num是大于一个,所以不产卵,当我做一个新的屏幕seession:

ssh hostname 

我绝对开放更好的方式来做到这一点!