# A splash of color Pimping up your terminal experience --- ## The default experience Most of us are probably doing must of our EB work 1. on a ~RHEL 8 system 2. in bash 3. over SSH 4. using vim ---- - The terminal is pretty black and white. - Your `ls` *maybe* show some colors by default for directories and images. - Your editor doesn't know what to make of `.eb` files. --- ## The basics ### `eb` itself You do know EB supports colors right? Just install `rich`! https://docs.easybuild.io/progress-bars/ ![progress](https://docs.easybuild.io/img/progress_bar_download.png) Oh, you heard about that yesterday? ---- ## The basics ### `ls` colors I'm sure many have spotted the `LS_COLORS` environment variable, but have been to lazy to customize it. When you work a lot with eb, patch and out files (from slurm jobs) adding a few extra colors in your .bashrc is a blessing: ```bash LS_COLORS="$LS_COLORS:*.eb=93:*.out=90:*.patch=92" alias ls='ls --color=auto' ``` ---- ### Pick your favourite colors ```bash for color_code in {30..37} {90..97}; do echo -e "\e[${color_code}mTesting ${color_code}\e[0m" done ``` --- ## The slightly more advanced ### Editor highlighting - `.eb` files are just python scripts, be sure to tell your editor this - `.vimrc`: ```vim autocmd BufNewFile,BufRead *.eb set syntax=python ``` - But we can do even better! ---- ### Custom easybuild highlighting - `.vim/ftdetect/eb.vim` or `.config/nvim/ftdetect/eb.vim` ```vim autocmd BufNewFile,BufRead *.eb set syntax=easybuild ``` - `.vim/syntax/easybuild.vim` or `.config/nvim/syntax/easybuild.vim` which start off with default python: ```vim runtime! syntax/python.vim ``` To which we can add custom `keyword` or `match` rules for our constants and template arguments. ---- ### Reusing the color schemes in Vim <!-- .slide: style="font-size: 26px;" --> - The vim color schemes: - `Normal` - `Comment` - `Constant`: `String`, `Character`, `Number`, `Boolean`, `Float` - `Identifier`: `Function` - `Statement`: `Conditional`, `Repeat`, `Label`, `Operator`, `Keyword`, `Exception` - `PreProc`: `Include`, `Define`, `Macro`, `PreCondit` - `Type`: `StorageClass`, `Structure`, `Typedef` - `Special`: `SpecialChar`, `Tag`, `Delimiter`, `SpecialComment`, `Debug` - `Underlined` - `Ignore` - `Error` - `Todo` - Actual colors are typically the same for variant in this line. ---- ### Custom keywords - `Define` seems like a good fit for the pre-defined keywords. ```vim syntax keyword eb_CONSTANT \ ARCH \ SYSTEM \ SOURCE_TAR_GZ \ SOURCELOWER_TAR_GZ \ ETC... highlight link eb_CONSTANT Define ``` ---- # Template strings <!-- .slide: style="font-size: 28px;" --> - Matching any `%(template)s` strings ```vim syntax match eb_Templates "%([a-z]\+)s" containedin=pythonString contained ``` - or match the exact list of templates: ```vim syntax match eb_Templates "%(name\(l\(etter\(lower\)\?\|ower\)\)\?)s" \ containedin=pythonString contained syntax match eb_Templates "%(version\(_m\(ajor_m\)\?inor\|_major\|prefix\|suffix\)\?)s" \ containedin=pythonString contained ... ``` - Multiple matching rules can be used ```vim highlight link eb_Templates Macro ``` ---- ### and more - Why not highlight those trailing spaces that the CI is going to complain about anyway? ```vim syntax match eb_TrailingSpace /\s\+$/ highlight link eb_TrailingSpace Error ``` - Difficult to do much more with just syntax highlighting ---- ### or emacs :man-shrugging: - `.emacs`: maybe something like this ```lisp (add-to-list 'auto-mode-alist '("\\.eb\\'" . python-mode)) ``` - or define an eb-mode ```lisp (define-derived-mode eb-mode python-mode "EB") (add-to-list 'auto-mode-alist '("\\.eb\\'" . eb-mode)) ``` - and add a bunch of custom rules to that --- # More goodies ## Bash completion - EB ships with bash completion scripts, though I found them a bit lacking - The search is slow - I only want local paths when i use --new-pr ---- ## Bash completion improved <!-- .slide: style="font-size: 24px;" --> ```bash _eb_completion() { # Generate and cache these? local robot_paths=( "/apps/easybuild-easyconfigs/easybuild/easyconfigs" "/apps/c3se-easyconfigs" ) local flags=( --new-pr --update-pr --pr-commit-msg --inject-checksums ) local cur=${COMP_WORDS[COMP_CWORD]} if [[ "$cur" == -* ]]; then COMPREPLY=($(compgen -W "${flags[*]}" -- "$cur")) else local search_robot=true case "${COMP_WORDS[@]}" in *"--new-pr"*) search_robot=false ;; *"--update-pr"*) search_robot=false ;; *"--pr-commit"*) search_robot=false ;; *"--inject"*) search_robot=false ;; esac # Any eb files or patches matching the current path COMPREPLY=($(compgen -f -X '!*.@(eb|patch|py)' -- "$cur")) # Anything in any of the robot paths if $search_robot && [[ -n "$cur" && $cur != *"/"* ]]; then for robot_path in "${robot_paths[@]}"; do local first="${cur:0:1}" local first_lower="${first,}" local first_part="${cur%%-*}" local search_paths="${robot_path}/${first_lower}/${first_part}*/ ${robot_path}/${first_part}*/ ${robot_path}/" COMPREPLY+=($(find $search_paths -maxdepth 1 -type f -name "${cur}*.eb" -printf '%P\n' 2> /dev/null)) done fi fi } complete -o plusdirs -F _eb_completion eb ``` - Smarter rules - Only considers `.eb`, `.patch`, `.py` file paths. - Fast conditional traversing of robot paths and only considers `.eb` files. --- ## Tips ### Add some aliases <!-- .slide: style="font-size: 38px;" --> ```bash alias buildGPU='SBATCH_GPUS_PER_NODE=A100:1 eb -r --job' alias ebbuild='eb --upload-test-report -r --rebuild --from-pr ' alias ebrev='eb --review-pr-max=1 '\ '--module-naming-scheme=EasyBuildMNS '\ '--disable-minimal-toolchains --review-pr ' alias ebinject='eb --inject-checksums --force ' ``` ---- ## Testing builds? <!-- .slide: style="font-size: 38px;" --> ```bash testing () { module purge module unuse $MODULEPATH module use /apps/Test/modules/all module load EasyBuild export EASYBUILD_INSTALLPATH=/apps/Test/ export EASYBUILD_REPOSITORYPATH=/apps/Test/ebfiles_repo PS1="\[\e[0;32m\][Test \u@\h($ARCH) \W]\$ \[\e[m\]" } ``` Quick switching into testing mode (switching back with equivalent `prod` function) ---- ## Developing framework features <!-- .slide: style="font-size: 38px;" --> ```bash framework_dev () { module purge module unuse $MODULEPATH module use /apps/Test/modules/all export PATH=$HOME/easybuild-framework:$PATH export PYTHONPATH=$HOME/easybuild-framework:\ $HOME/easybuild-easyblocks export EASYBUILD_INSTALLPATH=/apps/Test/ export EASYBUILD_REPOSITORYPATH=/apps/Test/ebfiles_repo PS1="\[\e[0;36m\][Dev \u@\h \W]\$ \[\e[m\]" } ``` --- ## Future outlook <!-- .slide: style="font-size: 38px;" --> - Working with Yunqi on a LSP for easyconfigs: - Warnings: - ~~EC options and constants typos~~ - Filename = name+version+toolchain - ~~Dependencies and versions~~ - Autocomplete - constants and options - templates - dependencies and versions(!) --- # Get the stuff - See thread in the #eum chat for snippets - Plan: - Add the syntax highlight parts to the docs - A PythonBundle easyconfig for the LSP - Polish up the bash completion and include in EB?
{"title":"A splash of color","slideOptions":"{\"transition\":\"slide\"}","contributors":"[{\"id\":\"55eac381-f2db-4e9a-86ff-af8ac33b58d4\",\"add\":11138,\"del\":3477}]","description":"Pimping up your terminal experience"}
    409 views