This code is a collection of command prompts for tclline (Pure-tcl readline2). The prompts path and pathColor are extracted from its source code; fish (inspired by the fish shell ) is by dbohdan.
namespace eval ::TclReadLine::prompts { variable shortenPath { original {} short {} } } proc ::TclReadLine::prompts::user-at-host {} { return $::tcl_platform(user)@[info hostname] } proc ::TclReadLine::prompts::shorten-path path { # Cache the short path, since this runs on every key press. variable shortenPath if {[dict get $shortenPath original] eq $path} { return [dict get $shortenPath short] } set splitPath [file split $path] set result {} foreach fragment [lrange $splitPath 0 end-1] { regexp {^\.{0,2}.} $fragment fragment lappend result $fragment } set short [file join {*}$result [lindex $splitPath end]] dict set shortenPath original $path dict set shortenPath short $short return $short } # Looks like this: # tclsh-8.6.3 [Downloads] % set ::TclReadLine::prompts::path {tclsh[info patchlevel] \[[pwd]\]% } # Looks like the above but with color. set ::TclReadLine::prompts::pathColor {\033\[36mtclsh-[info patchlevel]\033\[0m \[\033\[34m[file tail [pwd]\033\[0m]\]\033\[31m % \033\[0m} # A fish shell-style prompt with a clock. # Looks like this: # 14:49:52 user@host /h/d/Downloads> set ::TclReadLine::prompts::fish {[clock format [clock seconds] -format {%H:%M:%S}] [::TclReadLine::prompts::user-at-host] [::TclReadLine::prompts::shorten-path [pwd]]> }
The code above only makes new prompts available. Use a command like the following to change your prompt.
set ::TclReadLine::PROMPT $::TclReadLine::prompts::fish