You are not logged in.

#1 2012-01-10 14:34:16

nexus7
Member
From: brain dump
Registered: 2006-12-06
Posts: 285

[SOLVED] urxvt/titlebar: how to show what app is running etc.?

Hi all,

new year, more work. wink
Next is, that I'd like to completely switch from xfce-terminal to urxvt. urxvt works fine so far, but what bothers me, that it seems not to print out other information to the titlebar than it's very window class by default, say, just

urxvt

Well, the titlebar is ppTitle from XMonad, but that's probably not important here, I guess.

In comparision other programs show for example:

(a)   Post new topic / Arch Linux Forums - Mozilla Firefox

(b)   Terminal - ~ | 147x52 | pts/7

(c)   Terminal - .alsirc (~) - VIM

(where "Terminal" is xfce-terminal) and so on, where you can see far more infos like pwd, editor, or web page.

I looked on the web for urxvt specific options for this e.g. in .Xresources. But I don't know exactly how to name this, and so haven't found any. Read also this stuff, however to me the problem seems not to have something directly to do with X resources.

Maybe it's related to "terminal emulator factories" as seen in here, but I don't get it~ tongue
So any help is appreciated.


And finally, if hopefully there's some kind of config file for this, I want to edit it, e.g. for changing the separator "-".

Last edited by nexus7 (2012-01-16 14:48:46)


we are Arch.
you will be assimilated!
resistance is futile!

Offline

#2 2012-01-10 14:43:09

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,554
Website

Re: [SOLVED] urxvt/titlebar: how to show what app is running etc.?

You can set it by echoing what you want wrapped in the appropriate escape characters.  For example my bashrc includes the following:

PROMPT_COMMAND='echo -en "\033]0;$PWD\007"
'wname() { echo -en "\033]0;$@\007"; }

The prompt command renames the window (changes the title) to the current working directory whenever a prompt is displayed.  My wname function changes the title to whatever it is passed as a parameter.  I then have some aliases like

alias mutt='wname mutt; mutt'

so the title of the terminal with mutt open is "mutt."

This will work on most terminal emulators - definitely on the xterm/rxvt families.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2012-01-10 15:07:46

nexus7
Member
From: brain dump
Registered: 2006-12-06
Posts: 285

Re: [SOLVED] urxvt/titlebar: how to show what app is running etc.?

Trilby, so that means, one must do these aliases for each app manually?? Shouldn't this not work right out of the box for urxvt (like for terminal, see above)?
I use zsh btw.


we are Arch.
you will be assimilated!
resistance is futile!

Offline

#4 2012-01-10 15:22:27

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,554
Website

Re: [SOLVED] urxvt/titlebar: how to show what app is running etc.?

As far as I know it does need 'manually'.  I don't really consider that manually though as once set up in the appropriate file you can forget about it and it will 'just work' the way you set it up.

Some terminal apps - generally the gui apps like terminal - will do this for you.  There's nothing more automatic about it in those terminal emulators - someone else just already set it up for you.

You don't necessarily need to do a different alias for each app - I just do a few that I like to have particular control over.

You can have a general rule in your prompt command - or I believe it is "precmd" in zsh.  You can set the title to something like terminal does with the terminal name, PWD, and last command entered.  I've seen things with

history 1 | awk '{print $2}'

to set the title to the currently running command.

The "\033]0;" and "\007" are what allow you to put something in the title.  What you put there is up to you.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#5 2012-01-10 15:37:54

nexus7
Member
From: brain dump
Registered: 2006-12-06
Posts: 285

Re: [SOLVED] urxvt/titlebar: how to show what app is running etc.?

Trilby wrote:

As far as I know it does need 'manually'.  I don't really consider that manually though as once set up in the appropriate file you can forget about it and it will 'just work' the way you set it up.

Some terminal apps - generally the gui apps like terminal - will do this for you.  There's nothing more automatic about it in those terminal emulators - someone else just already set it up for you.

Hm, I see.


Trilby wrote:

You don't necessarily need to do a different alias for each app - I just do a few that I like to have particular control over.

Sure. wink


Trilby wrote:

You can have a general rule in your prompt command - or I believe it is "precmd" in zsh.  You can set the title to something like terminal does with the terminal name, PWD, and last command entered.  I've seen things with

history 1 | awk '{print $2}'

to set the title to the currently running command.

The "\033]0;" and "\007" are what allow you to put something in the title.  What you put there is up to you.

So its a shell thing. OK, I'm off now and will try this later. smile


we are Arch.
you will be assimilated!
resistance is futile!

Offline

#6 2012-01-10 21:32:04

VCoolio
Member
From: Netherlands
Registered: 2010-01-05
Posts: 120

Re: [SOLVED] urxvt/titlebar: how to show what app is running etc.?

To have current location in title bar, use chpwd hook in zsh like explained here, basically, inside .zshrc:

function chpwd() {
    print -Pn "\e]2;%~\a"
}

That only changes window title after changing folder, so if you like it to also show default folder when starting urxvt, use precmd hook:

function precmd() {
    print -Pn "\e]2;%~\a"
}

Offline

#7 2012-01-11 07:05:15

moetunes
Member
From: A comfortable couch
Registered: 2010-10-09
Posts: 1,033

Re: [SOLVED] urxvt/titlebar: how to show what app is running etc.?

I found this which is about having the running command show in the titlebar in bash but has a zsh example near the top.
Edit : This works much better for bash.

Last edited by moetunes (2012-01-11 07:46:50)


You're just jealous because the voices only talk to me.

Offline

#8 2012-01-11 12:34:12

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,006
Website

Re: [SOLVED] urxvt/titlebar: how to show what app is running etc.?

you can also try out oh-my-zsh.
it does a bunch of things, but one of the things it does, is installing precmd/preexec hooks that set the title.


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#9 2012-01-13 14:55:44

nexus7
Member
From: brain dump
Registered: 2006-12-06
Posts: 285

Re: [SOLVED] urxvt/titlebar: how to show what app is running etc.?

Playing with precmd/preexec now. The first works (most of the time; mc seems to be buggy here btw), the latter doesn't.

I want to check out oh-my-zsh-git, but it conflicts grml-zsh-config, and I'd like to keep my ~/.zshrc.local ... tongue


Edit:
...ok, ok, I'll just backup my config, install omz anyway, re-login and see what happens. wink

Last edited by nexus7 (2012-01-13 16:44:53)


we are Arch.
you will be assimilated!
resistance is futile!

Offline

#10 2012-01-14 19:31:57

nexus7
Member
From: brain dump
Registered: 2006-12-06
Posts: 285

Re: [SOLVED] urxvt/titlebar: how to show what app is running etc.?

Meanwhile there's some progress, but also some drawback.

Progress is regarding the terminal title's display with that code snippet (found here), pasted into ~/.zshrc:

## This sets the window title to the last run command. ##
[[ -t 1 ]] || return
case $TERM in
       *xterm*|*rxvt*|(dt|k|E|a)term)
#    xterm|rxvt-unicode-256color)
    preexec () {
    print -Pn "\e]2;[%l] [%n@%m] <$1>\a"        # (1)
#    print -Pn "\e]2;$1\a"                      # (2)
#    print -Pn "\e\"$1\e\134"                   # (3) copied from screen*), does not work
    }
    ;;
    screen*)
        preexec () {
        # this doesn't do anything... *wah*
        #print -Pn "\e\"[screen] [%l] [%n@%m] <$1>\e\134"
        print -Pn "\e\"$1\e\134"                # (4) works also nicely with tmux
    }
  ;; 
esac

where

(1)   print -Pn "\e]2;[%l] [%n@%m] <$1>\a"       -->     looks like     [pts/6] [nexus@myhost] <joe .zshrc>
(2)   print -Pn "\e]2;$1\a"                      -->     looks like     joe .zshrc
(4)   print -Pn "\e\"$1\e\134"                   -->     looks like     tmux:1 zsh

I've now been testing both with urxvt and xterm, and there are differences:
With urxvt, the last command remains displayed even after closing a program (like an editor, htop ...); xterm in comparison refreshes and returns to "~" then -- but at any time, as it ignores $pwd!

One might think, because both terminals make use of .Xresources, they'd show the same default window title. But where urxvt simply shows its window class, xterm behaves (more) like xfce-terminal (see first post):

~ | 289x44 | pts/7

I've got a tiling wm, so how to make urxvt's title also show the terminal's actual geometry? Well, it seems not to have such an own starting option though.



oh-my-zsh users: would you please show me how to activate its special precmd/preexec functions? I'd rather configure this where it should be instead of pasting old dirty code directly into ~/.zshrc.
I'm also lacking some basic functions yet. After its installlation (and de-installation of grml-zsh-config) I'm about copying parts of my former .zshrc.local into different files. But putting those files into .zsh/custom/ only (as mentioned here; also skimmed the refcard) seems not to be enough. So actually I'm left without aliases or history... tongue


Edit:
Ah, forgot to mention, that this whole title stuff seems not to work, when urxvt got tabs...

Edit #2:
Also, my [Home]- and [End]-keys don't work anymore in zsh; all I got is a "~"

Edit #3:
Found sth for the title stuff here, a page I visited ages ago... Will work that out tomorrow.

Last edited by nexus7 (2012-01-15 00:55:18)


we are Arch.
you will be assimilated!
resistance is futile!

Offline

#11 2012-01-16 14:47:49

nexus7
Member
From: brain dump
Registered: 2006-12-06
Posts: 285

Re: [SOLVED] urxvt/titlebar: how to show what app is running etc.?

Got it! smile


ntl had to get rid again of omz first, there was just too much trouble with it for me: Too many not working keys, and even couldn't get it to run though I exported $ZSH to $HOME/.oh-my-zsh, because of a "syntax error in line 14" of it's oh-my-zsh.sh, while there is apparently none. tongue

Therefor I reinstalled grml-zsh-config, being happy now to have my auto-completion, history, and prompt-live-coloring etc. back.


So I don't know what's about omz's abilities about setting a terminal window's title and had to do it by hand. -- No problem, as there seem to be at least two popular ways (besides the above shown attempts) to do this via

(1) using the PR_TITLEBAR-variable
It is explained in the already mentioned in Phil's prompt (at the bottom, with pics); I don't know if credits would go to him, found plenty of the same or simlar code snippets on the web.
Doing it like this looks quite elegant, but I want also have to last command in the title to be displayed, and this is probably not possible here, however. So I chose

(2) the print -Pn "\e]2; ... \a"-way,
where $1 simply can be used for the command, also along with ${COLUMNS}x${LINES} for the terminal's geometry:

# .zshrc.local
...
[[ -t 1 ]] || return
case $TERM in
    *xterm*|*rxvt*|(dt|k|E|a)term)
    preexec () {
    #print -Pn "\e]2;[%l] [%n@%m] <$1>\a"                # original code (see above)
    print -Pn "\e]2;%l [${COLUMNS}x${LINES}] :: $1\a"    # edited; %n@%m omitted, as I know who and where I am
    }
    ;;
    screen*)
        preexec () {
        print -Pn "\e\"$1\e\134"
    }
  ;; 
esac
...

So now, the output is e.g.

pts/3 [144x48] :: joe .zshrc

Well, this remains the same, even if the running program is closed and/or the tiling layout or the window's layout has changed -- in other words: The display of the geometry does not change on the fly accordingly, you'll just have to intput a new command for that. But I'm fine with this.


Thank you guys! smile


we are Arch.
you will be assimilated!
resistance is futile!

Offline

Board footer

Powered by FluxBB