core: improvements to garbage collection
[jimtcl.git] / initjimsh.tcl
blob1aab707abfd398aadb6a1d36886ec68870665f48
1 # This pseudo-package is loaded from jimsh to add additional
2 # paths to $auto_path and to source ~/.jimrc
4 proc _jimsh_init {} {
5 rename _jimsh_init {}
6 global jim::exe jim::argv0 tcl_interactive auto_path tcl_platform
8 # Stash the result of [info nameofexecutable] now, before a possible [cd]
9 if {[exists jim::argv0]} {
10 if {[string match "*/*" $jim::argv0]} {
11 set jim::exe [file join [pwd] $jim::argv0]
12 } else {
13 foreach path [split [env PATH ""] $tcl_platform(pathSeparator)] {
14 set exec [file join [pwd] [string map {\\ /} $path] $jim::argv0]
15 if {[file executable $exec]} {
16 set jim::exe $exec
17 break
23 # Add to the standard auto_path
24 lappend p {*}[split [env JIMLIB {}] $tcl_platform(pathSeparator)]
25 if {[exists jim::exe]} {
26 lappend p [file dirname $jim::exe]
28 lappend p {*}$auto_path
29 set auto_path $p
31 if {$tcl_interactive && [env HOME {}] ne ""} {
32 foreach src {.jimrc jimrc.tcl} {
33 if {[file exists [env HOME]/$src]} {
34 uplevel #0 source [env HOME]/$src
35 break
39 return ""
42 if {$tcl_platform(platform) eq "windows"} {
43 set jim::argv0 [string map {\\ /} $jim::argv0]
46 # Set a global variable here so that custom commands can be added post hoc
47 set tcl::autocomplete_commands {info tcl::prefix socket namespace array clock file package string dict signal history}
49 # Simple interactive command line completion callback
50 # Explicitly knows about some commands that support "-commands"
51 proc tcl::autocomplete {prefix} {
52 if {[set space [string first " " $prefix]] != -1} {
53 set cmd [string range $prefix 0 $space-1]
54 if {$cmd in $::tcl::autocomplete_commands || [info channel $cmd] ne ""} {
55 set arg [string range $prefix $space+1 end]
56 # Add any results from -commands
57 return [lmap p [$cmd -commands] {
58 if {![string match "${arg}*" $p]} continue
59 function "$cmd $p"
63 # Find matching files.
64 if {[string match "source *" $prefix]} {
65 set path [string range $prefix 7 end]
66 return [lmap p [glob -nocomplain "${path}*"] {
67 function "source $p"
70 # Find matching commands, omitting results containing spaces
71 return [lmap p [lsort [info commands $prefix*]] {
72 if {[string match "* *" $p]} {
73 continue
75 function $p
79 _jimsh_init