diff --git a/doc.zih.tu-dresden.de/docs/software/zsh.md b/doc.zih.tu-dresden.de/docs/software/zsh.md index 8bfd39d1b0bc8a1f5af72143f9943e6ee8f1a44b..aed455feae3847aab704f6d55a5ebb536931aa70 100644 --- a/doc.zih.tu-dresden.de/docs/software/zsh.md +++ b/doc.zih.tu-dresden.de/docs/software/zsh.md @@ -86,147 +86,154 @@ arrow key.  -## Addons for your `~/.zshrc` - -If you like, add these commands to your `~/.zshrc`-file. - - - -### Create a new directory and directly `cd` into it - -```bash -mcd () { - mkdir -p $1 - cd $1 -} -``` - -You can then - -``` -marie@login$ mcd non-existent-directory -``` - -and it will create it and `cd` into it - -### Find the largest files in the current directory easily - -```bash -function treesizethis { - du -k --max-depth=1 | sort -nr | awk ' - BEGIN { - split("KB,MB,GB,TB", Units, ","); - } - { - u = 1; - while ($1 >= 1024) { - $1 = $1 / 1024; - u += 1 +## + +??? example "Addons for your shell" + === "`bash`" + ```bash + # Create a new directory and directly `cd` into it + mcd () { + mkdir -p $1 + cd $1 } - $1 = sprintf("%.1f %s", $1, Units[u]); - print $0; - } - ' -} -``` - -This lists all files, from largest to smallest, in the current directory. -### Automatically rewrite `..` as `../..` + # Find the largest files in the current directory easily + function treesizethis { + du -k --max-depth=1 | sort -nr | awk ' + BEGIN { + split("KB,MB,GB,TB", Units, ","); + } + { + u = 1; + while ($1 >= 1024) { + $1 = $1 / 1024; + u += 1 + } + $1 = sprintf("%.1f %s", $1, Units[u]); + print $0; + } + ' + } -This will automatically replace `...` with `../..` and `....` with `../../..` and so on (each additional `.` -adding another `/..`) when typing commands: + #This allows you to run `slurmlogpath $SLURM_ID` and get the log-path directly in stdout: + function slurmlogpath { + scontrol show job $1 | sed -n -e 's/^\s*StdOut=//p' + } -``` bash -rationalise-dot() { - if [[ $LBUFFER = *.. ]]; then - LBUFFER+=/.. - else - LBUFFER+=. + # `ftails` follow-tails a slurm-log. Call it without parameters to tail the only running job or + # get a list of running jobs or use `ftails $JOBID` to tail a specific job + function ftails { + JOBID=$1 + if [[ -z $JOBID ]]; then + JOBS=$(squeue --format="%i \\'%j\\' " --me | grep -v JOBID) + NUMBER_OF_JOBS=$(echo "$JOBS" | wc -l) + JOBID= + if [[ "$NUMBER_OF_JOBS" -eq 1 ]]; then + JOBID=$(echo $JOBS | sed -e "s/'//g" | sed -e 's/ .*//') + else + JOBS=$(echo $JOBS | tr -d '\n') + JOBID=$(eval "whiptail --title 'Choose jobs to tail' --menu 'Choose Job to tail' 25 78 16 $JOBS" 3>&1 1>&2 2>&3) + fi fi -} -zle -N rationalise-dot -bindkey . rationalise-dot -``` - -### Auto-completion for `module load` - -This allows auto-completion for `module load`: - -```bash -function _module { - MODULE_COMMANDS=( - '-t:Show computer parsable output' - 'load:Load a module' - 'unload:Unload a module' - 'spider:Search for a module' - 'avail:Show available modules' - 'list:List loaded modules' - ) - - MODULE_COMMANDS_STR=$(printf "\n'%s'" "${MODULE_COMMANDS[@]}") - - eval "_describe 'command' \"($MODULE_COMMANDS_STR)\"" - _values -s ' ' 'flags' $(ml -t avail | sed -e 's#/$##' | tr '\n' ' ') -} - -compdef _module "module" -``` - -### Slurm-specific shortcuts - -#### Show Slurm log path - -This allows you to run `slurmlogpath $SLURM_ID` and get the log-path directly in stdout: - -```bash -function slurmlogpath { - scontrol show job $1 | sed -n -e 's/^\s*StdOut=//p' -} -``` + SLURMLOGPATH=$(slurmlogpath $JOBID) + if [[ -e $SLURMLOGPATH ]]; then + tail -n100 -f $SLURMLOGPATH + else + echo "No slurm-log-file found" + fi + } -#### Follow jobs more easily + #With this, you only need to type `sq` instead of `squeue -u $USER`. + alias sq="squeue --me" + ``` + === "`zsh`" + ```bash + # Create a new directory and directly `cd` into it + mcd () { + mkdir -p $1 + cd $1 + } -This `tail -f`s a job's output easily. If you write `ftails $SLURM_ID` it will show the output of the -`SLURM_ID`. If you write no `SLURM_ID` and there is only one job running, it will tail that job. -If there are multiple jobs running, it will show you a list of them and let you choose one to `tail`. + # Find the largest files in the current directory easily + function treesizethis { + du -k --max-depth=1 | sort -nr | awk ' + BEGIN { + split("KB,MB,GB,TB", Units, ","); + } + { + u = 1; + while ($1 >= 1024) { + $1 = $1 / 1024; + u += 1 + } + $1 = sprintf("%.1f %s", $1, Units[u]); + print $0; + } + ' + } -```bash -function ftails { - JOBID=$1 - if [[ -z $JOBID ]]; then - JOBS=$(squeue --format="%i \\'%j\\' " --me | grep -v JOBID) - NUMBER_OF_JOBS=$(echo "$JOBS" | wc -l) - - JOBID= - - if [[ "$NUMBER_OF_JOBS" -eq 1 ]]; then - JOBID=$(echo $JOBS | sed -e "s/'//g" | sed -e 's/ .*//') - else - JOBS=$(echo $JOBS | tr -d '\n') - - JOBID=$(eval "whiptail --title 'Choose jobs to tail' --menu 'Choose Job to tail' 25 78 16 $JOBS" 3>&1 1>&2 2>&3) - fi - fi - - SLURMLOGPATH=$(slurmlogpath $JOBID) - if [[ -e $SLURMLOGPATH ]]; then - tail -n100 -f $SLURMLOGPATH - else - echo "No slurm-log-file found" - fi -} -``` + #This allows you to run `slurmlogpath $SLURM_ID` and get the log-path directly in stdout: + function slurmlogpath { + scontrol show job $1 | sed -n -e 's/^\s*StdOut=//p' + } -#### Alias for `squeue -u $USER` + # `ftails` follow-tails a slurm-log. Call it without parameters to tail the only running job or + # get a list of running jobs or use `ftails $JOBID` to tail a specific job + function ftails { + JOBID=$1 + if [[ -z $JOBID ]]; then + JOBS=$(squeue --format="%i \\'%j\\' " --me | grep -v JOBID) + NUMBER_OF_JOBS=$(echo "$JOBS" | wc -l) + JOBID= + if [[ "$NUMBER_OF_JOBS" -eq 1 ]]; then + JOBID=$(echo $JOBS | sed -e "s/'//g" | sed -e 's/ .*//') + else + JOBS=$(echo $JOBS | tr -d '\n') + JOBID=$(eval "whiptail --title 'Choose jobs to tail' --menu 'Choose Job to tail' 25 78 16 $JOBS" 3>&1 1>&2 2>&3) + fi + fi + SLURMLOGPATH=$(slurmlogpath $JOBID) + if [[ -e $SLURMLOGPATH ]]; then + tail -n100 -f $SLURMLOGPATH + else + echo "No slurm-log-file found" + fi + } -This is way faster to type: + #With this, you only need to type `sq` instead of `squeue -u $USER`. + alias sq="squeue --me" -```bash -alias sq="squeue --me" -``` + #This will automatically replace `...` with `../..` and `....` with `../../..` + # and so on (each additional `.` adding another `/..`) when typing commands: + rationalise-dot() { + if [[ $LBUFFER = *.. ]]; then + LBUFFER+=/.. + else + LBUFFER+=. + fi + } + zle -N rationalise-dot + bindkey . rationalise-dot + + # This allows auto-completion for `module load`: + function _module { + MODULE_COMMANDS=( + '-t:Show computer parsable output' + 'load:Load a module' + 'unload:Unload a module' + 'spider:Search for a module' + 'avail:Show available modules' + 'list:List loaded modules' + ) + + MODULE_COMMANDS_STR=$(printf "\n'%s'" "${MODULE_COMMANDS[@]}") + + eval "_describe 'command' \"($MODULE_COMMANDS_STR)\"" + _values -s ' ' 'flags' $(ml -t avail | sed -e 's#/$##' | tr '\n' ' ') + } -Now you only need to type `sq` instead of `squeue -u $USER`. + compdef _module "module" + ``` ## Setting `zsh` as default-shell