Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'A year later...' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A year later...
Authored by: hysterion on Feb 07, '03 09:07:19AM


Another recent titlebar hint reminded me of this one just in time for its first anniversary :-)

I'm unconvinced by the current "Addendum to original story", because as pointed out above, the proposed "ultimate title bar" still causes the same sort of bugs we've seen. In fact, to recap, postcmd has two (apparently well known) problems with shell expansions:
  1. Expansion of (undefined) variables: if foo is undefined, then (depending on how single and double quotes were nested in the alias definition) one of the following will cause the postcmd alias to be removed as 'faulty':
    • echo $foo
    • echo '$foo'
    • echo "$foo"
  2. Expansion of 'same-name' aliases: if we have 'same-name' aliases like those below, then the first line of their output gets chopped. (Moreover the third example -- which assumes that that GNU ls is installed -- also causes the problem seen by z0mbi3.)
    • alias df 'df -k'
    • alias ls 'ls -a'
    • alias ls 'ls --color'
Workaround: use printf instead of echo, following Marc Liyanage (googlewhack); in addition, (following man tcsh), prevent variable expansion by using a :q modifier; thus:
sched +0:00 alias postcmd 'printf "\\033]0; %s \\007" "\\!#:q"'
With this, one problem remains: same-name aliases never make it into the title bar (but at least now their output isn't chopped). This seems due to the way tcsh avoids a recursive expansion loop -- see item 20 from the bottom of this file. So far as I can see, the only way out of that is to always use backslash escapes when defining such aliases, thus:
    • alias df '\\df -k'
    • alias ls '\\ls -a'
    • alias ls '\\ls --color' (etc.)
Alternatively: if we don't insist on seeing aliases mnemonically expanded in the title bar, then (following George) replace \\!#:q by `history -h 1` in the line above. (We can still use printf, with the benefit that these lines can now be pasted into any editor, with no need to talk about vi escape sequences.)

P.S.: In all of the above, read any number of consecutive backslashes as just one backslash. (I tried to put enough of them that at least some would survive the geeklog treatment...)

[ Reply to This | # ]
A year later...
Authored by: dpwk on Nov 29, '03 03:12:09AM
Oof! I spent too much time looking at this and all related hints I could find, and here is the synthesis I came up with- thanks to all the many people whose code appears in chunks here, you've given me a great education in all of this.

In my aliases.mine:

sched +0:00 alias postcmd 'printf "\033]0; %s \007" "`date "+%H:%M"` `echo -n "${cwd}"| sed -e "s%$HOME%~%"` => `history -h 1`"'

alias precmd 'printf "\033]0; %s \007" "`date "+%H:%M"`" ${cwd}"| sed -e "s%$HOME%~%"'

- prints time, cwd, current job
- works with aliased commands
- substitutes "~" for your home path
- doesn't add blank lines or obscure certain single line responses (as some of the other similar solutions did in my environment)
- doesn't use pesky escape sequences

also, more futzing on other hints elsewhere gave me this oh so fun prompt:

if ( $?prompt && $?tcsh ) then
  set BG_COL = 31
  alias inc_bg 'if ($BG_COL >= 37) @ BG_COL=30; @ BG_COL++'
  alias precmd 'set prompt="%{\033[${BG_COL};01m%}%B%m%b:%~ %h%# "; inc_bg'
  alias uncool 'unalias precmd; set prompt="%B%m%b:%~ %h%# "'

(put this in your .login, start a new shell, and hit return a few times.. you'll need a terminal that supports colors for this.)

now I'm wondering if I set up some sort of precmd collision here.. oh well, it all works, at least for now..

---
gigabling megashiznit

[ Reply to This | # ]

A year later...
Authored by: dpwk on Nov 29, '03 03:18:14AM
Oof! I spent too much time looking at this and all related hints I could find, and here is the synthesis I came up with- thanks to all the many people whose code appears in chunks here, you've given me a great education in all of this.

In all code below, 2 backslashes actually means one backslash.

In my aliases.mine:

sched +0:00 alias postcmd 'printf "\033]0; %s \007" "`date "+%H:%M"` `echo -n "${cwd}"| sed -e "s%$HOME%~%"` => `history -h 1`"'

alias precmd 'printf "\033]0; %s \007" "`date "+%H:%M"`" ${cwd}"| sed -e "s%$HOME%~%"'

- prints time, cwd, current job
- works with aliased commands
- substitutes "~" for your home path
- doesn't add blank lines or obscure certain single line responses (as some of the other similar solutions did in my environment)
- doesn't use pesky escape sequences

also, more futzing on other hints elsewhere gave me this oh so fun prompt:

if ( $?prompt && $?tcsh ) then
  set BG_COL = 31
  alias inc_bg 'if ($BG_COL >= 37) @ BG_COL=30; @ BG_COL++'
  alias precmd 'set prompt="%{\033[${BG_COL};01m%}%B%m%b:%~ %h%# "; inc_bg'
  alias uncool 'unalias precmd; set prompt="%B%m%b:%~ %h%# "'

(put this in your .login, start a new shell, and hit return a few times.. you'll need a terminal that supports colors for this.)

now I'm wondering if I set up some sort of precmd collision here.. oh well, it all works, at least for now..

---
gigabling megashiznit

[ Reply to This | # ]