diff options
-rw-r--r-- | initjimsh.tcl | 28 | ||||
-rw-r--r-- | jim_tcl.txt | 2 | ||||
-rw-r--r-- | jimsh.c | 2 | ||||
-rw-r--r-- | stdlib.tcl | 17 |
4 files changed, 28 insertions, 21 deletions
diff --git a/initjimsh.tcl b/initjimsh.tcl index 9ce9053..7423dfb 100644 --- a/initjimsh.tcl +++ b/initjimsh.tcl @@ -3,14 +3,29 @@ proc _jimsh_init {} { rename _jimsh_init {} + global jim::exe jim::argv0 tcl_interactive auto_path tcl_platform + + # Stash the result of [info nameofexecutable] now, before a possible [cd] + if {[string match "*/*" $jim::argv0]} { + set jim::exe [file join [pwd] $jim::argv0] + } else { + set jim::exe "" + foreach path [split [env PATH ""] $tcl_platform(pathSeparator)] { + set exec [file join [pwd] [string map {\\ /} $path] $jim::argv0] + if {[file executable $exec]} { + set jim::exe $exec + break + } + } + } # Add to the standard auto_path - lappend p {*}[split [env JIMLIB {}] $::tcl_platform(pathSeparator)] - lappend p [file dirname [info nameofexecutable]] - lappend p {*}$::auto_path - set ::auto_path $p + lappend p {*}[split [env JIMLIB {}] $tcl_platform(pathSeparator)] + lappend p [file dirname $jim::exe] + lappend p {*}$auto_path + set auto_path $p - if {$::tcl_interactive && [env HOME {}] ne ""} { + if {$tcl_interactive && [env HOME {}] ne ""} { foreach src {.jimrc jimrc.tcl} { if {[file exists [env HOME]/$src]} { uplevel #0 source [env HOME]/$src @@ -18,10 +33,11 @@ proc _jimsh_init {} { } } } + return "" } if {$tcl_platform(platform) eq "windows"} { - set jim_argv0 [string map {\\ /} $jim_argv0] + set jim::argv0 [string map {\\ /} $jim::argv0] } _jimsh_init diff --git a/jim_tcl.txt b/jim_tcl.txt index d6172b9..53d053a 100644 --- a/jim_tcl.txt +++ b/jim_tcl.txt @@ -4955,7 +4955,7 @@ The following global variables are set by jimsh. If jimsh is invoked to run a script, this variable contains the number of arguments supplied to the script. -+*jim_argv0*+:: ++*jim::argv0*+:: The value of argv[0] when jimsh was invoked. CHANGES IN PREVIOUS RELEASES @@ -84,7 +84,7 @@ int main(int argc, char *const argv[]) JimPrintErrorMessage(interp); } - Jim_SetVariableStrWithStr(interp, "jim_argv0", argv[0]); + Jim_SetVariableStrWithStr(interp, "jim::argv0", argv[0]); Jim_SetVariableStrWithStr(interp, JIM_INTERACTIVE, argc == 1 ? "1" : "0"); retcode = Jim_initjimshInit(interp); @@ -79,21 +79,12 @@ proc errorInfo {msg {stacktrace ""}} { string trim $result } -# Finds the current executable by searching along the path -# Returns the empty string if not found. +# Needs to be set up by the container app (e.g. jimsh) +# Returns the empty string if unknown proc {info nameofexecutable} {} { - if {[info exists ::jim_argv0]} { - if {[string match "*/*" $::jim_argv0]} { - return [file join [pwd] $::jim_argv0] - } - foreach path [split [env PATH ""] $::tcl_platform(pathSeparator)] { - set exec [file join [pwd] [string map {\\ /} $path] $::jim_argv0] - if {[file executable $exec]} { - return $exec - } - } + if {[exists ::jim::exe]} { + return $::jim::exe } - return "" } # Script-based implementation of 'dict with' |