set gitguidir [file dirname [info script]]
regsub -all ";" $gitguidir "\\;" gitguidir
set env(PATH) "$gitguidir;$env(PATH)"
- set _search_path [split $env(PATH) {;}]
- # Skip empty `PATH` elements
- set _search_path [lsearch -all -inline -not -exact \
- $_search_path ""]
+
+ set _path_seen [dict create]
+ foreach p [split $env(PATH) {;}] {
+ # Keep only absolute paths, getting rid of ., empty, etc.
+ if {[file pathtype $p] ne {absolute}} {
+ continue
+ }
+ # Keep only the first occurence of any duplicates.
+ set norm_p [file normalize $p]
+ if {[dict exists $_path_seen $norm_p]} {
+ continue
+ }
+ dict set _path_seen $norm_p 1
+ lappend _search_path $norm_p
+ }
+ unset _path_seen
set _search_exe .exe
} else {
set _search_path [split $env(PATH) :]