Difference between revisions of "Zsh"
(Created page with "The <code>zsh</code> offers a wide variety of possibile features to simplify command-line usage. If you're interested in a more user-friendly shell, look at [https://github.co...") |
(changed <code> to <pre>) |
||
| Line 1: | Line 1: | ||
| − | The < | + | The <pre>zsh</pre> offers a wide variety of possibile features to simplify command-line usage. If you're interested in a more user-friendly shell, look at [https://github.com/ohmyzsh/ohmyzsh ohmyzsh]. It is easy to install and offers a wide variety of usability improvements, like better tab completion, integrated git status messages and so on. |
| − | If you're interested in one of these, put them in your < | + | If you're interested in one of these, put them in your <pre>~/.zshrc</pre>. |
| − | Here are some useful functions for < | + | Here are some useful functions for <pre>zsh</pre>, specific to Slurm-HPC-systems. |
== Auto-completion for scancel == | == Auto-completion for scancel == | ||
| − | < | + | <pre> |
function _scancel { | function _scancel { | ||
SQUEUE_OUTPUT=$(squeue -o "%i:%j" -u $USER | grep -v "JOBID:NAME") | SQUEUE_OUTPUT=$(squeue -o "%i:%j" -u $USER | grep -v "JOBID:NAME") | ||
| − | |||
SCANCEL_COMMANDS=( | SCANCEL_COMMANDS=( | ||
'--signal=:Signal type (USR1, USR2, INT etc.)' | '--signal=:Signal type (USR1, USR2, INT etc.)' | ||
| Line 22: | Line 21: | ||
fi | fi | ||
done <<< "$SQUEUE_OUTPUT" | done <<< "$SQUEUE_OUTPUT" | ||
| − | |||
SCANCEL_COMMANDS_STR=$(printf "\n'%s'" "${SCANCEL_COMMANDS[@]}") | SCANCEL_COMMANDS_STR=$(printf "\n'%s'" "${SCANCEL_COMMANDS[@]}") | ||
| − | |||
eval "_describe 'command' \"($SCANCEL_COMMANDS_STR)\"" | eval "_describe 'command' \"($SCANCEL_COMMANDS_STR)\"" | ||
} | } | ||
compdef _scancel "scancel" | compdef _scancel "scancel" | ||
| − | </ | + | </pre> |
== Auto completion with lmod/ml == | == Auto completion with lmod/ml == | ||
| − | < | + | <pre> |
function _ml { | function _ml { | ||
ML_COMMANDS=( | ML_COMMANDS=( | ||
| Line 43: | Line 40: | ||
'list:List loaded modules' | 'list:List loaded modules' | ||
) | ) | ||
| − | |||
ML_COMMANDS_STR=$(printf "\n'%s'" "${ML_COMMANDS[@]}") | ML_COMMANDS_STR=$(printf "\n'%s'" "${ML_COMMANDS[@]}") | ||
| − | |||
eval "_describe 'command' \"($ML_COMMANDS_STR)\"" | eval "_describe 'command' \"($ML_COMMANDS_STR)\"" | ||
_values -s ' ' 'flags' $(ml -t avail | sed -e 's#/$##' | tr '\n' ' ') | _values -s ' ' 'flags' $(ml -t avail | sed -e 's#/$##' | tr '\n' ' ') | ||
} | } | ||
| − | |||
compdef _ml "ml" | compdef _ml "ml" | ||
| − | </ | + | </pre> |
== ftails == | == ftails == | ||
| − | When using this, you will be able to follow jobs more easily. If you have just one sbatch job running, and enter < | + | When using this, you will be able to follow jobs more easily. If you have just one sbatch job running, and enter <pre>ftails</pre>, it will automatically follow that one job. If you have more than one running, it will prompt you (via whiptail) which job to choose. It also adds <pre>slurmlogpath</pre>, which, when called like <pre>slurmlogpath $SBATCH_ID</pre> will print the log path to stdout. |
| − | < | + | <pre> |
function slurmlogpath { scontrol show job $1 | grep StdOut | sed -e 's/^\s*StdOut=//' } | function slurmlogpath { scontrol show job $1 | grep StdOut | sed -e 's/^\s*StdOut=//' } | ||
| − | |||
| − | |||
function ftails { | function ftails { | ||
JOBID=$1 | JOBID=$1 | ||
| Line 67: | Line 59: | ||
JOBS=$(squeue --format="%i \\'%j\\' " -u $USER | grep -v JOBID) | JOBS=$(squeue --format="%i \\'%j\\' " -u $USER | grep -v JOBID) | ||
NUMBER_OF_JOBS=$(echo "$JOBS" | wc -l) | NUMBER_OF_JOBS=$(echo "$JOBS" | wc -l) | ||
| − | |||
JOBID= | JOBID= | ||
| − | |||
if [[ "$NUMBER_OF_JOBS" -eq 1 ]]; then | if [[ "$NUMBER_OF_JOBS" -eq 1 ]]; then | ||
JOBID=$(echo $JOBS | sed -e "s/'//g" | sed -e 's/ .*//') | JOBID=$(echo $JOBS | sed -e "s/'//g" | sed -e 's/ .*//') | ||
| Line 78: | Line 68: | ||
fi | fi | ||
fi | fi | ||
| − | |||
SLURMLOGPATH=$(slurmlogpath $JOBID) | SLURMLOGPATH=$(slurmlogpath $JOBID) | ||
if [[ -e $SLURMLOGPATH ]]; then | if [[ -e $SLURMLOGPATH ]]; then | ||
| Line 86: | Line 75: | ||
fi | fi | ||
} | } | ||
| − | </ | + | </pre> |
| − | |||
== Alias for squeue -u $USER == | == Alias for squeue -u $USER == | ||
| − | Sometimes one has to know which jobs are still running and this is done by < | + | Sometimes one has to know which jobs are still running and this is done by <pre>squeue -u $USER</pre>. This is tough to type, and writing <pre>sq</pre> for that is easier. |
| − | < | + | <pre> |
alias sq="squeue -u $USER" | alias sq="squeue -u $USER" | ||
| − | </ | + | </pre> |
Revision as of 14:25, 16 October 2021
The
zsh
offers a wide variety of possibile features to simplify command-line usage. If you're interested in a more user-friendly shell, look at ohmyzsh. It is easy to install and offers a wide variety of usability improvements, like better tab completion, integrated git status messages and so on. If you're interested in one of these, put them in your
~/.zshrc
. Here are some useful functions for
zsh
, specific to Slurm-HPC-systems.
Auto-completion for scancel
function _scancel {
SQUEUE_OUTPUT=$(squeue -o "%i:%j" -u $USER | grep -v "JOBID:NAME")
SCANCEL_COMMANDS=(
'--signal=:Signal type (USR1, USR2, INT etc.)'
'--batch:Send signal to all batch steps'
)
while IFS= read -r line; do
if [[ ! -z $line ]]; then
SCANCEL_COMMANDS+=("$line")
fi
done <<< "$SQUEUE_OUTPUT"
SCANCEL_COMMANDS_STR=$(printf "\n'%s'" "${SCANCEL_COMMANDS[@]}")
eval "_describe 'command' \"($SCANCEL_COMMANDS_STR)\""
}
compdef _scancel "scancel"
Auto completion with lmod/ml
function _ml {
ML_COMMANDS=(
'-t:Show computer parsable output'
'unload:Unload a Module'
'spider:Search for a module'
'avail:Show available modules'
'list:List loaded modules'
)
ML_COMMANDS_STR=$(printf "\n'%s'" "${ML_COMMANDS[@]}")
eval "_describe 'command' \"($ML_COMMANDS_STR)\""
_values -s ' ' 'flags' $(ml -t avail | sed -e 's#/$##' | tr '\n' ' ')
}
compdef _ml "ml"
ftails
When using this, you will be able to follow jobs more easily. If you have just one sbatch job running, and enter
ftails
, it will automatically follow that one job. If you have more than one running, it will prompt you (via whiptail) which job to choose. It also adds
slurmlogpath
, which, when called like
slurmlogpath $SBATCH_ID
will print the log path to stdout.
function slurmlogpath { scontrol show job $1 | grep StdOut | sed -e 's/^\s*StdOut=//' }
function ftails {
JOBID=$1
if [[ -z $JOBID ]]; then
JOBS=$(squeue --format="%i \\'%j\\' " -u $USER | 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
}
Alias for squeue -u $USER
Sometimes one has to know which jobs are still running and this is done by
squeue -u $USER
. This is tough to type, and writing
sq
for that is easier.
alias sq="squeue -u $USER"