mirror of
https://github.com/envmodules/modules.git
synced 2026-06-14 00:42:43 +08:00
Add 'usergroups' state
Create `usergroups` state to collect all the groups the user running modulecmd.tcl process is member of. Add an initStateUsergroups procedure to initialize this state, which calls `id -G -n` to fetch these group names. This external command is available on every Unices and its `-G -n` arguments operate the same way. An error will be obtained on Windows platform as `id` command is not known there. initStateUsergroups procedure is recorded in modulecmd.tcl as __initStateUsergroups and renamed if initStateUsergroups procedure is not found from Modules Tcl extension library. A more efficient version of initStateUsergroups 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}\
|
||||
usergroups {<undef> initStateUsergroups}\
|
||||
username {<undef> initStateUsername}\
|
||||
]
|
||||
|
||||
@@ -352,6 +353,18 @@ proc initStateTermColumns {} {
|
||||
return [expr {![info exists cols] || $cols eq {0} ? 80 : $cols}]
|
||||
}
|
||||
|
||||
# Get all groups of user running modulecmd.tcl process
|
||||
proc __initStateUsergroups {} {
|
||||
# ensure groups including space in their name (found on Cygwin/MSYS
|
||||
# platforms) are correctly set as list element
|
||||
if {[catch {
|
||||
return [split [string range [runCommand id -G -n -z] 0 end-1] \0]
|
||||
} errMsg]} {
|
||||
# fallback if '-z' option is not supported
|
||||
return [runCommand id -G -n]
|
||||
}
|
||||
}
|
||||
|
||||
# Get name of user running modulecmd.tcl process
|
||||
proc __initStateUsername {} {
|
||||
return [runCommand id -u -n]
|
||||
@@ -11710,6 +11723,7 @@ if {[catch {
|
||||
if {[info commands readFile] eq {}} {
|
||||
rename ::__readFile ::readFile
|
||||
rename ::__getFilesInDirectory ::getFilesInDirectory
|
||||
rename ::__initStateUsergroups ::initStateUsergroups
|
||||
rename ::__initStateUsername ::initStateUsername
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user