Compare commits

...

2 Commits

Author SHA1 Message Date
04273c2422 Break tools out into modules 2023-03-09 11:15:53 +01:00
522854ab3d vimrc: CtrlP, slime, tagbar 2023-03-08 15:26:53 +01:00
7 changed files with 166 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

View File

@@ -7,6 +7,7 @@
title_inactive_bg_color = "#4C566A"
always_split_with_profile = True
[keybindings]
help = ""
[profiles]
[[default]]
background_color = "#12204d"

View File

@@ -0,0 +1,33 @@
qnode() {
[ $# -lt 1 ] && echo "Usage qnode JOBID" && return 0
squeue --noheader --jobs $1 -o %R
}
qssh() {
[ $# -lt 1 ] && echo "Usage qssh JOBID" && return 0
ssh $(qnode $1)
}
taillog() { [ $# -lt 1 ] && echo "Usage taillog LOGFILE [JOBIDs ..]" && return 0
if [ $# -lt 2 ] ; then
tail "$1"
else
tail "$1" "$1.$2"{.e,.o}
fi
}
catlog() { [ $# -lt 1 ] && echo "Usage catlog LOGFILE [JOBIDs ..]" && return 0
if [ $# -lt 2 ] ; then
cat "$1" | less
else
cat "$1" "$1.$2"{.e,.o} | less
fi
}
watchlog() { [ $# -lt 2 ] && echo "Usage watchlog INTERVAL LOGFILE [JOBIDs ..]" && return 0;
if [ $# -lt 3 ] ; then
watch -n $1 tail "$2"
else
watch -n $1 tail "$2" "$2.$3"{.e,.o}
fi
}

96
.modules.kuba/.tools.sh Normal file
View File

@@ -0,0 +1,96 @@
# 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
}

View File

@@ -9,22 +9,8 @@ set_alias("qa", 'squeue -o "%8A %10u %.6Q %24j %2t %3r %16S %.10M %.10L %.4D %16
set_alias("qid", 'squeue -h -u $USER -o "%A"')
set_alias("scancelall", 'squeue -h -u $USER -o "%A" | xargs scancel')
execute{cmd='qnode() { [ $# -lt 1 ] && echo "Usage qnode JOBID" && return 0; '..
'squeue --noheader --jobs $1 -o %R; '..
'}', modeA={"load"}}
execute{cmd='qssh() { [ $# -lt 1 ] && echo "Usage qssh JOBID" && return 0; '..
'ssh $(qnode $1); '..
'}', modeA={"load"}}
execute{cmd='taillog() { [ $# -lt 1 ] && echo "Usage taillog LOGFILE [JOBIDs ..]" && return 0; '..
'if [ $# -lt 2 ] ; then tail "$1" ; ' ..
'else tail "$1" "$1.$2"{.e,.o} ;' ..
'fi }', modeA={"load"}}
execute{cmd='catlog() { [ $# -lt 1 ] && echo "Usage catlog LOGFILE [JOBIDs ..]" && return 0; '..
'if [ $# -lt 2 ] ; then cat "$1" | less ; ' ..
'else cat "$1" "$1.$2"{.e,.o} | less ;' ..
'fi }', modeA={"load"}}
execute{cmd='watchlog() { [ $# -lt 2 ] && echo "Usage watchlog INTERVAL LOGFILE [JOBIDs ..]" && return 0; '..
'if [ $# -lt 3 ] ; then watch -n $1 tail "$2"; ' ..
'else watch -n $1 tail "$2" "$2.$3"{.e,.o}; ' ..
'fi }', modeA={"load"}}
execute{cmd='unset -f qnode qssh watchlog catlog taillog', modeA={"unload"}}
local path = splitFileName(myFileName());
local loadscript = pathJoin(path, '.' .. myModuleName() .. '.sh');
execute{cmd='source ' .. loadscript, modeA={"load"}}
execute{cmd='unset -f qnode qssh watchlog catlog taillog;', modeA={"unload"}}

11
.modules.kuba/tools.lua Normal file
View File

@@ -0,0 +1,11 @@
whatis([==[
Loads useful tools
]==])
local path = splitFileName(myFileName());
local loadscript = pathJoin(path, '.' .. myModuleName() .. '.sh');
execute{cmd='source ' .. loadscript, modeA={"load"}}
execute{cmd='unset -f npz_preview npz_previewi ' ..
'rsync_wrap rsync_wrap_huge selc selv cliipc clipv watch_modify' ..
';', modeA={"unload"}}

16
.vimrc
View File

@@ -34,6 +34,8 @@ if filereadable(expand(vundle_dir) . "/README.md")
Plugin 'tpope/vim-unimpaired'
Plugin 'JuliaEditorSupport/julia-vim'
Plugin 'tell-k/vim-autopep8'
Plugin 'jpalardy/vim-slime'
Plugin 'preservim/tagbar'
call vundle#end() " required
else
@@ -127,10 +129,21 @@ noremap Y y$
command! -bang -range=% -complete=file -nargs=* W <line1>,<line2>write<bang> <args>
command! -bang Q quit<bang>
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlPMixed'
let g:ctrlp_working_path_mode = 'ra' " Look for .git .hg .svn .bzr _darcs
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.(git|hg|svn|data|logs)$',
\ 'file': '\v\.(exe|so|dll)$',
\ }
" Gutentags configuration
if !executable('ctags')
let g:gutentags_enabled = 0
else
nmap <F1> :CtrlPTag<CR>
nmap <F4> :TagbarToggle<CR>
let g:gutentags_add_default_project_roots = 0
let g:gutentags_project_root = ['.git']
@@ -332,6 +345,9 @@ noremap <expr> <F7> LaTeXtoUnicode#Toggle()
noremap! <expr> <F7> LaTeXtoUnicode#Toggle()
autocmd FileType python noremap <buffer> <F8> :call Autopep8()<CR>
let g:slime_target = "tmux"
let g:slime_default_config = {"socket_name": "default", "target_pane": "{last}"}
nmap <Leader>cf :cd %:p:h <CR> " Change dir to parent of current file
nmap <Leader>cg :cd $git_root_location <CR> " Change dir to git root
nmap <Leader>vs :sp $HOME/.vimrc <CR>