Break tools out into modules

This commit is contained in:
2023-03-09 11:15:53 +01:00
parent 522854ab3d
commit 04273c2422
5 changed files with 149 additions and 114 deletions

View File

@@ -35,105 +35,10 @@ complete -o bashdefault -o default -o nospace -F __git_wrap__git_main dotfiles
# Define a OS X-like open command
open() { command xdg-open "$@" > /dev/null 2>&1 & }
# Inspect .npz files
npz_py_str="$(cat << EOM
from sys import argv
import numpy as np
try:
import matplotlib.pyplot as plt
print('Imported matplotlib.pyplot as plt')
except ImportError:
pass
class Wrap:
def __init__(self, fname):
n = np.load(fname, allow_pickle=True)
files = n.files
globs = globals()
print('Contains files', files)
for f in files:
setattr(self, f, n[f])
globs[f] = n[f]
argv = argv[argv.index('--')+1:]
archives = [Wrap(arg) for arg in argv[::-1]]
archive = archives[0]
print('Global namespace populated with "archive", "archives" and all files')
EOM
)"
npz_preview() {
if [ $# -lt 1 ]; then
echo "Please specify file to open as argument"
return
fi
python -ic "$npz_py_str" -- "$@"
}
npz_previewi() {
if [ $# -lt 1 ]; then
echo "Please specify file to open as argument"
return
fi
ipython -i -c "$npz_py_str" -- "$@"
}
rsync_wrap() {
cmd="rsync -a -R -r --copy-links --exclude .git --exclude __pycache__ --progress"
if [ $# == 0 ]; then
echo "Usage rsync_wrap [...]
Useful for synchronizing repositories
Calls $cmd [...]"
return
fi
$cmd $@
}
rsync_wrap_huge() {
cmd="rsync -a -R -r --copy-links --size-only --exclude .git --exclude __pycache__ --progress"
if [ $# == 0 ]; then
echo "Usage rsync_wrap_huge [...]
Useful for synchronizing repositories. Does not do checksum
Calls $cmd [...]"
return
fi
$cmd $@
}
watch_modify() {
if [ $# -lt 2 ]; then
echo "Usage watch_modify FILE CMD ARGS...
Run CMD ARGS... when file FILE is updated
"
return
fi
file="$1"
base="$(basename "$file")"
dir="$(dirname "$file")"
inotifywait -r -m -e modify "$dir" | while read file_path file_event file_name; do
[ "$base" == "$file_name" ] && echo ${@:2} && ${@:2}
done
}
# Source git prompt
source_existing ~/scripts/git-prompt.sh
source_existing ~/.bash_prompt.kuba
if command -v xclip &> /dev/null; then
alias selc="xclip -sel primary -i"
alias selv="xclip -sel primary -o"
alias clipc="xclip -sel clip -i"
alias clipv="xclip -sel clip -o"
fi
# Activate python virtualenv
source_existing ~/.python-venv.kuba/bin/activate
@@ -153,5 +58,9 @@ if [ -z "$DONT_LOAD_LMOD" ]; then
module use "$HOME/.modules.kuba/"
module use "$HOME/git/auto-venv-setup/lmod-modules/"
module load tools
else
# lmod does not exist
source $HOME/.modules.kuba/.tools.sh
fi
fi