mirror of
https://github.com/envmodules/modules.git
synced 2026-06-14 00:42:43 +08:00
Add 'username' state
Create `username` state to collect the name of the user running modulecmd.tcl process. Add an initStateUsername procedure to initialize this state, which calls `id -u -n` to fetch username. This external command is available on every Unices and its `-u -n` arguments operate the same way. An error will be obtained on Windows platform as `id` command is not known there. initStateUsername procedure is recorded in modulecmd.tcl as __initStateUsername and renamed if initStateUsername procedure is not found from Modules Tcl extension library. A more efficient version of initStateUsername will be provided in the library later on (not to depend on an external command call).
This commit is contained in:
@@ -60,6 +60,7 @@ array set g_state_defs [list\
|
||||
tcl_ext_lib_loaded {0}\
|
||||
tcl_version [list [info patchlevel]]\
|
||||
term_columns {<undef> initStateTermColumns}\
|
||||
username {<undef> initStateUsername}\
|
||||
]
|
||||
|
||||
# Configuration option properties (superseding environment variable, default
|
||||
@@ -351,6 +352,11 @@ proc initStateTermColumns {} {
|
||||
return [expr {![info exists cols] || $cols eq {0} ? 80 : $cols}]
|
||||
}
|
||||
|
||||
# Get name of user running modulecmd.tcl process
|
||||
proc __initStateUsername {} {
|
||||
return [runCommand id -u -n]
|
||||
}
|
||||
|
||||
# Initialize Select Graphic Rendition table
|
||||
proc initConfColors {envvar value validvallist intvallist} {
|
||||
# overriden value coming from environment
|
||||
@@ -11697,6 +11703,7 @@ if {[catch {
|
||||
if {[info commands readFile] eq {}} {
|
||||
rename ::__readFile ::readFile
|
||||
rename ::__getFilesInDirectory ::getFilesInDirectory
|
||||
rename ::__initStateUsername ::initStateUsername
|
||||
}
|
||||
|
||||
# source site configuration script if any
|
||||
|
||||
Reference in New Issue
Block a user