Hi Ben,

Thanks for the reply.  I see what you mean, but I'm not quite sure
this carries over to another server.

When I SSH to another host, without any of the aforementioned PS1
setting, I just see my window name set to "ssh".  So far as I can
tell, in order to set the window name to the hostname, I need to send
an escape sequence to the terminal, from that host in particular, so
it will recognize what it should rename the window to (\033kVALUE\033,
as you mentioned).  That is what I'm doing by setting the PS1
variable.

As for setting the window name to the command, I would tell screen
what a prompt looked like with the "shelltitle" config directive, and
it would extrapolate the command.  You made a good point that screen
was too dumb to realize if the command was actually the _command_ and
not some environment variable being set, terminal trash, or, in HPUX's
case, just part of a really long commandline.

>From what I can tell, this may be outside the scope of tmux and
perhaps needs to be something better suited for the local shell of the
host I'm SSHing into.  There, the shell, can set that escape sequence
to be whatever it deemed necessary and have the logic to strip out
things like environment variables, interpreters, or other garbage.

I'm looking at something similar to:
http://www.twistedmatrix.com/users/glyph/preexec.bash.txt

It uses "trap" to set the title before a command runs, and
$PROMPT_COMMAND to set it back to the hostname after the command
completes.

The only problem I may have with this is that, from what I've read,
none of the shells in HPUX have anything similar to PROMPT_COMMAND -
closest is setting PS1, and HPUX's "trap" command traps _after_ the
command completes; not before.  I don't have bash installed on my HPUX
systems, and unfortunately, it's a bit of a pain in the ass to
maintain software outside the standard patch bundles.  It's more of a
manual process of remembering that you installed something outside the
standard packaged software, downloading it, and it's dependencies, and
updating each in the right order from there.  Though, this appears to
be the obvious solution, and I may need to go this route.

I may be overlooking something basic, so if anyone else has any ideas,
I will welcome them.

Thanks much!

Mike


On Thu, Jan 13, 2011 at 10:37 AM, Ben Boeckel <maths...@gmail.com> wrote:
> mbm329 <mbm...@gmail.com> wrote:
>> Hello list,
>>
>> I'm trying to transition from GNU Screen to tmux.  I like to have my
>> windows named as the host they are logged into.  That is, until I run
>> a command.  Then I like to have it named for the command I'm running.
>>
>> In GNU Screen, I accomplished this via the PS1 environment variable.
>> (some shells in various OSes do not support PROMPT_COMMAND)
>>
>> In Linux:
>> export PS1="\[\033]0;${USER}@${HOSTNAME}\007\]"  ##display user@host
>> in titlebar or "%h" screen string escape
>> export PS1=${PS1}'\[\033k\033\\\]'  ##display running command for
>> window name in screen's caption line (empty the current name)
>> export PS1=${PS1}'\[\033k'${HOSTNAME}'\033\\\]'  ##show hostname for
>> window name on screen's caption line when idle
>> export PS1='<\u@\h:\w>\n'${PS1}'\$ '
>>
>> I place this code in my .bashrc or .profile of each host I ssh into.
>> It works great in screen.
>>
>> When I try this in tmux, it sets the window name (#W) to the hostname
>> of the system i'm logged into great, but it fails to set it to a
>> running command (example: top, sar, etc...)
>>
>> I believe this is due to the fact that I tell screen what a prompt
>> looks like via this config:
>> shelltitle "$ |idle"
>>
>> I'm not quite sure how to accomplish this with tmux.  I have tried
>> setw -g automatic-rename on, but from what I've read, after the first
>> rename (my PS1 being set), it disables this feature for the window.
>>
>> Can anyone provide any ideas or solutions that will acknowledge the
>> escape sequence I'm using for setting the window, yet override it when
>> a command is run?  Perhaps there is a config directive I'm
>> overlooking.  Perhaps there's something even easier and cleaner than
>> setting PS1 on every host; that would be nice.
>
> I use the following setting:
>
>    set-window-option -g window-status-format '#I#F:#T-#W'
>
> which looks something like:
>
>    1#:-python
>
> by default. When ssh'ing I've seen it become:
>
>    1#:user@host-bash
>
> I've also seen that tmux is much better at grabbing the process name
> than screen (ENVVAR=value cmd is 'ENVVAR=value' in screen and 'cmd' in
> tmux) but it doesn't get things that run under interpreters that well
> (offlineimap is 'python', for instance). Don't have any machines to ssh
> into at the moment however to verify the auto-hosting right now. I also
> have the following function in my zshrc:
>
>    tmux_title () {
>        if [ -n "$TMUX" ]; then
>            printf "\033]2;$1\033\\"
>        fi
>    }
>
>
>    # Initialize to nothing
>    if [[ -z "$VIMRUNTIME" ]]; then
>        tmux_title ""
>    fi
>
> To manually name shells and to clear it on new (local) shells that are
> not from vim (:sh).
>
> Hope this helps.
>
> --Ben
>
>
> ------------------------------------------------------------------------------
> Protect Your Site and Customers from Malware Attacks
> Learn about various malware tactics and how to avoid them. Understand
> malware threats, the impact they can have on your business, and how you
> can protect your company and customers by using code signing.
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> tmux-users mailing list
> tmux-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/tmux-users
>

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to