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


Click here to return to the 'Correct alias with no bugs?' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Correct alias with no bugs?
Authored by: geohar on Feb 08, '02 09:20:32AM

the best illustration of what's wrong with the script

install the title-change postcmd
type: echo $foo
where foo is non-existant
postcmd will try to interpret foo, will fail and you will get

foo: Undefined variable.
Faulty alias 'postcmd' removed.
foo: Undefined variable.

The problem is that you'd like !# to return the textual representation of the last line, _without_ doing substitutions on it....

I therefore believe that the following is the correct command

alias postcmd 'echo -n "^[]0;"`history -h 1`"^G"'

George



[ Reply to This | # ]
Correct alias with no bugs?
Authored by: geohar on Feb 08, '02 03:03:04PM

_or_ if you really want !# so that aliasses are expanded,

then

alias postcmd echo "'^[]0;\!#^G'"

where the !# above is escaped with a backslash (don't know if geeklog will kill it though ;)

will work, and won't fail on undefined variables, because the whole thing it echoes is in single-quotes...

George



[ Reply to This | # ]
Correct alias with no bugs?
Authored by: hysterion on Feb 08, '02 07:43:23PM
> if you really want !# so that aliasses are expanded, > > then > > alias postcmd echo "'^[]0;!#^G'" > > where the !# above is escaped with a backslash > (don't know if geeklog will kill it though ;) Ah, good! I had also noticed this "Faulty alias removed" problem, when you feed it an undefined variable. And indeed this seems to fix it. Provided, that is, I still include the sched part, thus:
sched +0:00 alias postcmd echo -n "'^[]0;!#^G'"
(with backslash before the "!"). Otherwise, opening a new terminal gives me: Welcome to Darwin! echo: No match. Faulty alias 'postcmd' removed. [localhost:~] fz% That still leaves the ls problem open, though...

[ Reply to This | # ]
Correct alias with no bugs?
Authored by: hysterion on Feb 07, '03 08:34:41AM

Actually this one still gives an error when the undefined variable is in quotes:

[localhost:~] fz% echo '$foo'
foo: Undefined variable.
Faulty alias 'postcmd' removed.
$foo



[ Reply to This | # ]
Correct alias with no bugs?
Authored by: geohar on Feb 08, '02 03:03:17PM

_or_ if you really want !# so that aliasses are expanded,

then

alias postcmd echo "'^[]0;\!#^G'"

where the !# above is escaped with a backslash (don't know if geeklog will kill it though ;)

will work, and won't fail on undefined variables, because the whole thing it echoes is in single-quotes...

George



[ Reply to This | # ]
Correct alias with no bugs?
Authored by: Anonymous on Feb 10, '02 08:56:01PM

Works for me, no problem. At least ls is still displayed as ls, rather than the first line of the output (which is exactly what you DON'T want). I still wish it could display what directory, but hey there's always pwd and the prompt. ;)



[ Reply to This | # ]