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...") |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | 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.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. | + | 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 zsh with the plugin [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 <code>~/.zshrc</code>. | If you're interested in one of these, put them in your <code>~/.zshrc</code>. | ||
Line 8: | Line 8: | ||
== 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> |
Line 58: | Line 52: | ||
When using this, you will be able to follow jobs more easily. If you have just one sbatch job running, and enter <code>ftails</code>, 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 <code>slurmlogpath</code>, which, when called like <code>slurmlogpath $SBATCH_ID</code> will print the log path to stdout. | When using this, you will be able to follow jobs more easily. If you have just one sbatch job running, and enter <code>ftails</code>, 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 <code>slurmlogpath</code>, which, when called like <code>slurmlogpath $SBATCH_ID</code> 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 == | ||
Line 93: | Line 81: | ||
Sometimes one has to know which jobs are still running and this is done by <code>squeue -u $USER</code>. This is tough to type, and writing <code>sq</code> for that is easier. | Sometimes one has to know which jobs are still running and this is done by <code>squeue -u $USER</code>. This is tough to type, and writing <code>sq</code> for that is easier. | ||
− | < | + | <pre> |
alias sq="squeue -u $USER" | alias sq="squeue -u $USER" | ||
− | </ | + | </pre> |
+ | |||
+ | [[Category:Basics]] |
Latest revision as of 09:48, 17 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 zsh with the plugin 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"