aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--initjimsh.tcl28
-rw-r--r--jim_tcl.txt2
-rw-r--r--jimsh.c2
-rw-r--r--stdlib.tcl17
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
diff --git a/jimsh.c b/jimsh.c
index 9c11083..fe89649 100644
--- a/jimsh.c
+++ b/jimsh.c
@@ -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);
diff --git a/stdlib.tcl b/stdlib.tcl
index d0256d0..3a2bbd8 100644
--- a/stdlib.tcl
+++ b/stdlib.tcl
@@ -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'