Guest User

Untitled

a guest
Jun 22nd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #!/bin/bash
  2. # Author: x4x
  3. # Create a job queue for bash.
  4.  
  5. set -o errexit
  6. set -o nounset
  7.  
  8. FIFO=/tmp/shfifo0
  9. n=0
  10. MARK='\033[0;35m'
  11. NC='\033[0m' # No Color
  12.  
  13. trap "rm -f $FIFO" EXIT
  14.  
  15. if [[ ! -p $FIFO ]]; then
  16. mkfifo $FIFO
  17. fi
  18.  
  19. # read whatever from the named pipe.
  20. while read job < $FIFO
  21. do
  22. n=$((n+1))
  23. if [[ $job = 'quit' ]]; then
  24. echo -e "${MARK}Done processing $n jobs${NC}"
  25. exit
  26. fi
  27. echo -e "${MARK}running job $n: ${NC} $job"
  28. {
  29. (eval '$job') | sed -e 's/^/'"$n> /" &
  30. # catch errors
  31. } || {
  32. echo -e "${MARK}An Error happend${NC}"
  33. }
  34. done
  35.  
  36. # use:
  37. # run in other shell a piped comand to the FIFO
  38. # echo "ytd " > /tmp/shfifo0
  39. # #alias ytd='youtube-dl -x --audio-format mp3 '
  40. # function ytmq { echo "youtube-dl -x --audio-format mp3 $1" > /tmp/shfifo0; }
Add Comment
Please, Sign In to add comment