Skip to content

Commit

Permalink
Issue #750: make "export -f funcName" and "complete ..." appear last …
Browse files Browse the repository at this point in the history
…in output to bash/zsh/sh shells
  • Loading branch information
Robert McLay committed Feb 21, 2025
1 parent 818af38 commit fc05009
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion rt/complete/err.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
step 1
lua ProjectDIR/src/lmod.in.lua shell --regression_testing --version
===========================
Modules based on Lua: Version 8.7.32 2023-08-28 12:42 -05:00
Modules based on Lua: Version 8.7.56 2025-02-04 18:12 -07:00
by Robert McLay mclay@tacc.utexas.edu
===========================
step 2
Expand Down
2 changes: 1 addition & 1 deletion rt/complete/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ _LMFILES_=ProjectDIR/rt/complete/mf/foo/1.0.lua;
export _LMFILES_;
_ModuleTable_='_ModuleTable_={MTversion=3,depthT={},family={},mT={foo={fn="ProjectDIR/rt/complete/mf/foo/1.0.lua",fullName="foo/1.0",loadOrder=1,propT={},stackDepth=0,status="active",userName="foo/1.0",wV="000000001.*zfinal",},},mpathA={"ProjectDIR/rt/complete/mf",},systemBaseMPATH="ProjectDIR/rt/complete/mf",}';
export _ModuleTable_;
[[ -n "${BASH_VERSION:-}" ]] && complete -o default -F foo_completion foo;
foo () { echo foo;
};
foo_completion () { COMPREPLY=(bar baz);
};
[[ -n "${BASH_VERSION:-}" ]] && complete -o default -F foo_completion foo;
2 changes: 1 addition & 1 deletion rt/set_alias/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ _some_spack_func () {
echo found;
fi;
};
[[ -n "${BASH_VERSION:-}" ]] && export -f _some_spack_func;
[[ -n "${BASH_VERSION:-}" ]] && export -f _some_spack_func 2> /dev/null || true;
===========================
step 9
lua ProjectDIR/src/lmod.in.lua shell --regression_testing unload spack
Expand Down
12 changes: 6 additions & 6 deletions rt/sh_to_mf/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ banner () {
local NONE='\\033[0m';
echo "${RED}${str}${NONE}";
};
[[ -n "${BASH_VERSION:-}" ]] && complete -F _xyz123 xyz123;
alias fooAlias=foobin\ -q\ -l;
fooFunc () {
echo "arg1: $1";
Expand All @@ -167,6 +166,7 @@ save_args () {
done;
echo " ";
};
[[ -n "${BASH_VERSION:-}" ]] && complete -F _xyz123 xyz123;
===========================
step 11
lua ProjectDIR/src/lmod.in.lua shell --regression_testing show wrapperSh/1.0
Expand All @@ -189,7 +189,6 @@ banner () {
local NONE='\\033[0m';
echo "${RED}${str}${NONE}";
};
[[ -n "${BASH_VERSION:-}" ]] && complete -F _xyz123 xyz123;
alias fooAlias=foobin\ -q\ -l;
fooFunc () {
echo "arg1: $1";
Expand All @@ -209,6 +208,7 @@ save_args () {
done;
echo " ";
};
[[ -n "${BASH_VERSION:-}" ]] && complete -F _xyz123 xyz123;
===========================
step 13
lua ProjectDIR/src/lmod.in.lua shell --regression_testing list
Expand Down Expand Up @@ -236,12 +236,12 @@ unset _LMFILES_;
_ModuleTable_='_ModuleTable_={MTversion=3,depthT={},family={},mT={},mpathA={"ProjectDIR/rt/sh_to_mf/mf",},systemBaseMPATH="ProjectDIR/rt/sh_to_mf/mf",}';
export _ModuleTable_;
unset -f banner 2> /dev/null || true;
[[ -n "${BASH_VERSION:-}" ]] && complete -r xyz123;
unalias fooAlias 2> /dev/null || true;
unset -f fooFunc 2> /dev/null || true;
unset -f junk 2> /dev/null || true;
unset -f my_help 2> /dev/null || true;
unset -f save_args 2> /dev/null || true;
[[ -n "${BASH_VERSION:-}" ]] && complete -r xyz123;
===========================
step 16
lua ProjectDIR/src/lmod.in.lua shell --regression_testing load brokenSh/1.0
Expand Down Expand Up @@ -273,7 +273,6 @@ banner () {
local NONE='\\033[0m';
echo "${RED}${str}${NONE}";
};
[[ -n "${BASH_VERSION:-}" ]] && complete -F _xyz123 xyz123;
alias fooAlias=foobin\ -q\ -l;
fooFunc () {
echo "arg1: $1";
Expand All @@ -293,6 +292,7 @@ save_args () {
done;
echo " ";
};
[[ -n "${BASH_VERSION:-}" ]] && complete -F _xyz123 xyz123;
===========================
step 18
lua ProjectDIR/src/lmod.in.lua shell --regression_testing save
Expand Down Expand Up @@ -325,7 +325,6 @@ banner () {
local NONE='\\033[0m';
echo "${RED}${str}${NONE}";
};
[[ -n "${BASH_VERSION:-}" ]] && complete -F _xyz123 xyz123;
alias fooAlias=foobin\ -q\ -l;
fooFunc () {
echo "arg1: $1";
Expand All @@ -345,6 +344,7 @@ save_args () {
done;
echo " ";
};
[[ -n "${BASH_VERSION:-}" ]] && complete -F _xyz123 xyz123;
===========================
step 20
lua ProjectDIR/src/lmod.in.lua shell --regression_testing --mt
Expand All @@ -369,7 +369,6 @@ banner () {
local NONE='\\033[0m';
echo "${RED}${str}${NONE}";
};
[[ -n "${BASH_VERSION:-}" ]] && complete -F _xyz123 xyz123;
alias fooAlias=foobin\ -q\ -l;
fooFunc () {
echo "arg1: $1";
Expand All @@ -389,6 +388,7 @@ save_args () {
done;
echo " ";
};
[[ -n "${BASH_VERSION:-}" ]] && complete -F _xyz123 xyz123;
===========================
step 22
lua ProjectDIR/src/lmod.in.lua shell --regression_testing list
Expand Down
20 changes: 16 additions & 4 deletions shells/BaseShell.lua
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ function M.expand(self, tbl)

local init = false

local delayT = {}


for k,v in pairsByKeys(tbl) do
if (not init) then
self:initialize()
Expand Down Expand Up @@ -178,10 +181,8 @@ function M.expand(self, tbl)
self:alias(k,vstr)
elseif (vType == "shell_function") then
self:shellFunc(k,vstr)
elseif (vType == "complete") then
self:complete(k,vstr)
elseif (vType == "export_shell_function") then
self:export_shell_function(k,vstr)
elseif (vType == "complete" or vType == "export_shell_function") then
delayT[k] = { vType = vType, vstr = vstr }
elseif (not vstr) then
self:unset(k, vType)
elseif (k == "_ModuleTable_") then
Expand All @@ -192,6 +193,17 @@ function M.expand(self, tbl)
end
end
end
if (next(delayT) ~= nil) then
for k, v in pairsByKeys(delayT) do
local vType = v.vType
if (vType == "complete") then
self:complete(k,v.vstr)
elseif (vType == "export_shell_function") then
self:export_shell_function(k,v.vstr)
end
end
end

if (init) then
self:finalize()
end
Expand Down
2 changes: 1 addition & 1 deletion shells/Bash.lua
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function Bash.export_shell_function(self, n, value)
if (value) then
lineA[#lineA + 1] = "[[ -n \"${BASH_VERSION:-}\" ]] && export -f "
lineA[#lineA + 1] = name
lineA[#lineA + 1] = ";\n"
lineA[#lineA + 1] = " 2> /dev/null || true;\n"
else
lineA[#lineA + 1] = "[[ -n \"${BASH_VERSION:-}\" ]] && unset -f "
lineA[#lineA + 1] = name
Expand Down
2 changes: 1 addition & 1 deletion src/lmod.in.lua
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ function main()

local vPATH = varT["PATH"]
if (vPATH) then
vPATH:prt();
vPATH:prt()
end

hook.apply("finalize", cmdName)
Expand Down

0 comments on commit fc05009

Please sign in to comment.