# 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] archive = archives[-1] print('Global namespace populated with "archive", "archives" and all files') for i, fname in enumerate(argv): print(f' {i:<3.0f}: {fname}') 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 $@ } 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 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 }