Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

::tclreadline::prompt1

14 views
Skip to first unread message

Cecil Westerhof

unread,
Dec 16, 2017, 4:59:05 PM12/16/17
to
I have it defined as:
proc ::tclreadline::prompt1 {} {
return [format "%s \[%s %s@%s:%s\]\n$ " \
tclsh${::tcl_version} \
[clock format [clock seconds] -format "%a, %b %T"] \
$::tcl_platform(user) \
[lindex [split [info hostname] "."] 0] \
[pwd]]
}

It does mostly what I want. I would like to give the prompt a colour,
but that is not very important.
What is a bit more important is the current working directory. Instead
of:
/home/cecil

I would prefer:
~

And instead of:
/home/cecil/Documents

I would prefer:
~/Documents

Is this possible, or should I use a substitution on the output of pwd?

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Cecil Westerhof

unread,
Dec 16, 2017, 5:14:05 PM12/16/17
to
Cecil Westerhof <Ce...@decebal.nl> writes:

> I have it defined as:
> proc ::tclreadline::prompt1 {} {
> return [format "%s \[%s %s@%s:%s\]\n$ " \
> tclsh${::tcl_version} \
> [clock format [clock seconds] -format "%a, %b %T"] \
> $::tcl_platform(user) \
> [lindex [split [info hostname] "."] 0] \
> [pwd]]
> }
>
> It does mostly what I want. I would like to give the prompt a colour,
> but that is not very important.
> What is a bit more important is the current working directory. Instead
> of:
> /home/cecil
>
> I would prefer:
> ~
>
> And instead of:
> /home/cecil/Documents
>
> I would prefer:
> ~/Documents
>
> Is this possible, or should I use a substitution on the output of pwd?

I rewrote it as:
proc ::tclreadline::prompt1 {} {
set user $::tcl_platform(user)
set currentDir [regsub "^/home/${user}" [pwd] ~]
set dateTime [clock format [clock seconds] -format "%a, %e %b %T"]
set host [lindex [split [info hostname] "."] 0]
return [format "%s \[%s %s@%s:%s\]\n$ " \
tclsh${::tcl_version} \
${dateTime} \
${user} \
${host} \
${currentDir}]
}

If there is a better way: I am open for improvements.
0 new messages