设置Ubuntu环境变量控制Putty窗口标题动态显示


设置Ubuntu环境变量控制Putty窗口标题动态显示
 
   嗷,卖葛! 这次完了~    关错服务器了,,,
 
      :(   经常会犯这样的错误,因为桌面上开着N多个Putty远程连接,它们都长成一个样子,一不小心就会弄错! 有什么好办法能让我更好地区分它们呢?
 
  下面给出好的解决方案
 
  (以下场景执行Putty工具,使用root用户远程登录,SSH主机是 Ubuntu Server )  
 
● 使用不带任何参数的 cd 命令,进入到 ~ 目录下面
 
●  由于 Ubuntu Server 13 的 ~/ 下没有.bash_profile , 我们先用 touch .bash_profile 创建一个全新的
 
●  用 vi 编辑之,输入以下内容
 
---------------------------------------
 
# .bash_profile
 
# Get the aliases and functions
 
if [ -f ~/.bashrc ]; then
 
       . ~/.bashrc
 
fi
 
 
 
# User specific environment and startupprograms
 
# PATH=$PATH:$HOME/bin
 
# export PATH
 
 
 
# add following statement to the END offile  ~/.bash_profile
 
# auto add env parameter $PROMPT_COMMANDwhen use non-Linux tty login by ssh.
 
 
 
if [ "$SSH_CONNECTION" != '' ]; then
 
     export HOSTIP=`echo $SSH_CONNECTION |awk '{print $3}' |awk -F: '{if ($1== "") print $4; else print $1}'`
 
     export PROMPT_COMMAND='echo -ne"\033]0;${USER}@'$HOSTIP':[${HOSTNAME%%.*}]:${PWD/#$HOME/~}  \007"'
 
     env |grep PROMPT_COMMAND
 
 
 
      # Set the DISPLAY env var for Xmanagerforward
 
     # export DISPLAY=`echo $SSH_CONNECTION |awk '{print $1}' |awk -F: '{if($1 == "") print $4; else print $1}'`:0.0
 
fi
 
---------------------------------------
 
● 上面的脚本第一二句会执行一些环境参数设置的脚本 ~/.bashrc,经研究,由于 Ubuntu 下的默认设置脚本某些参数会与我们想要的效果冲突,所以要编辑并屏蔽掉部分内容。
 
     用 vi 编辑 ~/.bashrc 将下面的两段代码给注释屏蔽掉(将第一行最前加注释符号 # )
 
---------------------------------------
 
第一段:
 
# set a fancy prompt (non-color, unless weknow we "want" color)
 
case "$TERM" in
 
   xterm-color) color_prompt=yes;;
 
esac
 
---- 注释后 -------
 
# case "$TERM" in
 
#   xterm-color) color_prompt=yes;;
 
# esac
 
第二段:
 
# If this is an xterm set the title touser@host:dir
 
case "$TERM" in
 
xterm*|rxvt*)
 
   PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
 
   ;;
 
*)
 
   ;;
 
esac
 
---------------------------------------
 
   下面给出配置完毕后登录时自动显示相关信息的效果图
 
 
              enjoy !!     :)  
 

相关内容

    暂无相关文章