dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | Submodules | README | LICENSE

tsp-rerun (1802B)


      1 #!/bin/sh
      2 
      3 version=0.1
      4 
      5 show_help() {
      6     echo "usage: ${0##*/} [OPTIONS] ID1 [ID2...[ID N]]"
      7     echo "will rerun the command from each job ID from 'tsp' as a new 'tsp' job"
      8     echo "If no ID is specified, this program will expect IDs as stdin."
      9     echo
     10     echo "OPTIONS are one or more of the following:"
     11     echo "   -V,  --verbose       show diagnostic information during execution"
     12     echo "   -v,  --version       show version and license information"
     13     echo "   -h,  --help          show this message"
     14     echo "   --                   do not consider any following args as options"
     15 }
     16 
     17 show_version() {
     18     echo "${0##*/} version $version"
     19     echo "Licensed under the GNU Public License, v3+"
     20     echo "written by Anders Damsgaard, anders@adamsgaard.dk"
     21     echo "https://gitlab.com/admesg/dotfiles"
     22 }
     23 
     24 get_tsp_job_command() {
     25     tsp | grep "^$1 " | sed 's/  */ /g' | cut -d' ' -f6-
     26 }
     27 
     28 surround_paranthesis_words_with_ticks() {
     29     sed 's/(/\\(/g; s/)/\\)/g; s/?/\\?/g'
     30 }
     31 
     32 handle_id() {
     33     cmd="tsp $(get_tsp_job_command "$1" | surround_paranthesis_words_with_ticks)"
     34     [ "$verbose" = 1 ] && echo "$cmd"
     35     eval "$cmd"
     36 }
     37 
     38 die() {
     39     printf '%s\n' "$1" >&2
     40     exit 1
     41 }
     42 
     43 verbose=0
     44 while :; do
     45     case "$1" in
     46         -h|-\?|--help)
     47             show_help
     48             exit 0
     49             ;;
     50         -v|--version)
     51             show_version
     52             exit 0
     53             ;;
     54         -V|--verbose)
     55             verbose=1
     56             ;;
     57         --) # end all options
     58             shift
     59             break
     60             ;;
     61         -?*)
     62             die 'Error: Unknown option specified'
     63             ;;
     64         *)  # No more options
     65             break
     66     esac
     67     shift
     68 done
     69 
     70 if [ $# -lt 1 ]; then
     71     id="$(cat)"
     72     handle_id "$id"
     73 else
     74     for id in "$@"; do
     75         handle_id "$id"
     76     done
     77 fi