-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnpa-ml.bash
70 lines (51 loc) · 1.33 KB
/
npa-ml.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
script=$(tmp_file)
cat <<EOF > $script
#!/bin/bash
# This creates a shorthand for "module"
function ml {
local args="" opt=load
if [ \$# -gt 0 ]; then
case \$1 in
load|add|rm|unload|swap|switch|purge|refresh|update)
opt=\$1 ; shift ;;
show|display|help|clear)
opt=\$1 ; shift ;;
av|avail)
opt=avail ; shift ;;
esac
else
opt=list
fi
module \$opt \$@
}
# Returns a list of prereqs so an easy load
# is enabled
# For instance:
# module load \`ml_prereq numpy\`
function ml_prereq {
module show \$@ 2>&1 | grep prereq | sed -e "s:prereq::g;s:[[:space:]]::g" | tr "\n" " "
printf "\n"
}
EOF
pack_cmd "mv $script $(pack_get --prefix)/source/ml.function"
script=$(tmp_file)
cat <<EOF > $script
#!/bin/bash
# This creates the autocompletion for "ml"
source \$NPA_SOURCE/ml.function
function _ml {
local cur="\$2"
COMPREPLY=( \$(compgen -W "\$(_module_not_yet_loaded)" -- "\$cur"))
}
complete -F _ml ml
EOF
pack_cmd "mv $script $(pack_get --prefix)/source/ml.bashrc"
script=$(tmp_file)
cat <<EOF > $script
#!/bin/zsh
# This creates the autocompletion for "ml"
source \$NPA_SOURCE/ml.function
# Currently autocomplete does not work
EOF
pack_cmd "mv $script $(pack_get --prefix)/source/ml.zshrc"
unset script