Women in Technology

Hear us Roar

  bash on Mac OS X
Subject:   if only ...
Date:   2004-02-25 08:09:07
From:   henksmets
... I could do this in bash

alias precmd 'printf "\033]0;%s @ $SHORTHOST\007" "${cwd}" | sed -e "s%$HOME%~%"'
sched +0:00 alias postcmd 'printf "\033]0;%s @ $SHORTHOST\007" "\!#"'

This gives me dynamic hostname information in the terminal information. When I ssh to a server that terminal window is easily recognisable.

Full Threads Oldest First

Showing messages 1 through 3 of 3.

  • if only ...
    2004-02-25 08:54:46  blalor [View]

    But you can!

    if [ "${TERM#xterm}" != "${TERM}" ] && [ "${EMACS}" != "t" ]; then
    # Set prompt to "[$USER@$HOSTNAME `pwd` ]> "
    prompt_command () {
    # Display my current machine and directory in the title bar!
    title="${LOGNAME}@$(hostname -s):[$(dirs)]"
    echo -n "ESC]1;$title^G"
    echo -n "ESC]2;$title^G"

    export PROMPT_COMMAND=prompt_command

    (the ESC and ^G are actually control characters I entered in with Emacs; \033 and \007 would probably work, too.)
    That gives you a prompt like [blalor@Animal ~]> and a window title like blalor@Animal:[~]
    • if only ...
      2004-02-28 04:29:31  hysterion [View]

      This does the precmd part. OTOH there is no bash equivalent for the postcmd part (used here to put the last command executed in the title bar).

      This can be done in tcsh and zsh, but in bash there is simply no way unless you patch it.
    • if only ...
      2004-02-27 04:04:25  henksmets [View]

      Great, thanks a lot, I looked a long time for this

      I'm also looking for a way to colorize my different ssh-connections, with the same color for each host. I found some tips but someway it doesn't work. Are bash solutions?