While lmod support fish from version 7.4 onwards, I have to use servers with an older version. How can I make it work with fish? (Even if in limited capacity.)
Asked
Active
Viewed 95 times
1 Answers
0
This solution let me run commands like module load R
. It may fail in the general case.
Define a convenience function as follows:
function module
eval $LMOD_CMD bash $argv | lmod_bash_to_fish.py | source -
end
where lmod_bash_to_fish.py
has the contents:
#!/usr/bin/env python3
import re
import sys
f = sys.stdin
while True:
line = f.readline()
if not line:
break
match = re.match(r'^(\w+)="(.+)";\n$', line)
if not match:
raise RuntimeError("Unexpected line: {}".format(line))
var, val = match.groups()
line = f.readline()
if line != "export {};\n".format(var):
raise RuntimeError("Variable not immediately exported: {}".format(line))
if var == 'PATH':
val = " ".join('"{}"'.format(elem) for elem in val.split(':'))
print("set -gx fish_user_paths {}".format(val))
continue
print("set -gx {} \"{}\"".format(var, val))

Yatharth Agarwal
- 4,385
- 2
- 24
- 53