[Home] Zsh logo

autobg

Zsh Wizard

Download autobg Return to Examples
  1. # From: "Bart Schaefer" <schaefer>
  2. # Subject: Re: Contrl-Z action.
  3. #
  4. # On Nov 5, 8:49pm, Alexey Solovyov wrote:
  5. # } Subject: Re: Contrl-Z action.
  6. # }
  7. # } > :But I've got a question. Once I came up why I want to have my job
  8. # } > :suspended by pressing Cntrl-Z ? Ok, I want it to run in background
  9. # } > :right after that.
  10. # } >
  11. # } > I can't think of a elegant way of doing this automatically without a
  12. # } > lot of overhead.
  13. # }
  14. # } Thanks, I will probably do it this way though actually I was thinking
  15. # } about changing the sources... :)
  16. #
  17. # Eww, don't do that.
  18. #
  19. # } But anyway suggestions about eliminating the second Ctrl-Z are welcome.
  20. function autobg() {
  21. jobs -s >| /tmp/j$$
  22. while read jnum jdesc
  23. do
  24. bg %${${jnum#\[}%\]}
  25. done < /tmp/j$$
  26. rm -f /tmp/j$$
  27. }
  28. # function precmd() {
  29. # autobg
  30. # }
  31. #
  32. # I really question whether this is the behavior you want, though. You
  33. # might want to change the `bg ...' command in autobg to something like
  34. #
  35. # case $jdesc in
  36. # (*( vi | vim | *emacs )*) ;; # Don't autobg any editors,
  37. # (*) bg %${${jnum#\[}%\]} ;; # but anything else is OK.
  38. # esac
  39. #
  40. # or possibly something even more restrictive where you list the things
  41. # that you *do* want to autobg rather than those that you don't.