From 5a8527d4b55545aeb703eaae36e6fc73d8467e2a Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Tue, 2 Jun 2020 06:51:20 +0200 Subject: [PATCH] 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). --- modulecmd.tcl.in | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modulecmd.tcl.in b/modulecmd.tcl.in index aed1226f..75a69227 100644 --- a/modulecmd.tcl.in +++ b/modulecmd.tcl.in @@ -60,6 +60,7 @@ array set g_state_defs [list\ tcl_ext_lib_loaded {0}\ tcl_version [list [info patchlevel]]\ term_columns { initStateTermColumns}\ + username { 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