Skip to content

Instantly share code, notes, and snippets.

@mrteera
Created June 11, 2013 15:00
Show Gist options
  • Save mrteera/5757595 to your computer and use it in GitHub Desktop.
Save mrteera/5757595 to your computer and use it in GitHub Desktop.
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
export PIP_VIRTUALENV_BASE=$WORKON_HOME
look_for_cmd=0
print_cmd() {
if [ ${look_for_cmd} = 1 ] ;then
if [ "${BASH_COMMAND}" != 'print_host' ] ;then
cmdline=$(history 1 | xargs | cut -d\ -f3-)
if [[ "${cmdline}" =~ ^(sudo|ssh|vi|man|more|less)\ ]] ;then
first=$(echo "${cmdline}" | awk '{print $1}')
for i in ${cmdline} ;do
if ! [[ "${i}" =~ ^-.*$ ]] && ! [[ "${i}" =~ ^${first}$ ]] ;then
cmd="${first}[${i}]"
break
fi
done
elif [[ "${cmdline}" =~ ^[A-Z]*=.*$ ]] ;then
cmd=$(echo ${cmdline} | awk '{print $2}')
else
cmd=$(echo ${cmdline} | awk '{print $1}')
fi
echo -ne "\033k${cmd}\033\\" 1>&2
look_for_cmd=0
else
return
fi
fi
}
print_host() {
echo -ne "\033k${HOSTNAME}\033\\" 1>&2
look_for_cmd=1
}
PROMPT_COMMAND="print_host"
trap "print_cmd" DEBUG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment