From 93d4c60025c730f68fd318f37475144f6ddea714 Mon Sep 17 00:00:00 2001 From: Jeff Lawson Date: Fri, 8 Feb 2019 13:57:39 -0600 Subject: [PATCH] Normalize home directory in prompts to avoid display oddities (#12) * Normalize home directory in prompts. * use simple concatenation instead of "file join" to avoid problems with leading slashes Fixes #6 --- tclreadlineSetup.tcl.in | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tclreadlineSetup.tcl.in b/tclreadlineSetup.tcl.in index 3c99413..bb89c7f 100644 --- a/tclreadlineSetup.tcl.in +++ b/tclreadlineSetup.tcl.in @@ -155,8 +155,14 @@ namespace eval tclreadline { set pwd "unable to get pwd" } - if [info exists env(HOME)] { - regsub $env(HOME) $pwd "~" pwd + if {[info exists env(HOME)]} { + variable normalized_home + if {![info exists normalized_home]} { + set normalized_home [file normalize $env(HOME)] + } + if {[string equal -length [string length $normalized_home] $pwd $normalized_home]} { + set pwd "~[string range $pwd [string length $normalized_home] end]" + } } return "$prompt_string \[$pwd\] " }