Thursday, August 14, 2014

How to ssh to host and set terminal title to hostname:path_on_the_host in a single command

 1. Create file ~/ssht.sh with content:

#!/bin/bash
SETTP='MY_PROMPT="$HOSTNAME:$PWD\$ "'
SETTP="$SETTP;"'MY_TITLE="\[\e]0;$HOSTNAME:$PWD\a\]"'
SETTP="$SETTP;"'PS1="$MY_TITLE$MY_PROMPT"'
ssh -t <YOUR_NICKNAME>@$1 "export PROMPT_COMMAND='eval '\\''$SETTP'\\'; bash --login"

2. Make it executable:

chmod ugo+x ~/ssht.sh

3. add alias to this script into your .profile:

alias ssht="~/ssht.sh"

4. Use:

ssht <HOST_NAME>

No comments:

Post a Comment