The d command
Run make or other commands in the background, with output to a file.

If you use the command line very much at all...

Usage: d [ -f file ]     c[a][n][r][x][f|w|!|p] cmd [ arg ... ]
or:    d [ -f file ]     m[a][n][r][x][f|w|!|p] [ make-arg ... ]
or:    d [ -f file ] [s|e][a][n][r][x][f|w|!|p] [ additional-arg ... ]
or:    d [ -f file ]     h[x]

Run a command in the background, with its stdout and stderr redirected to a log file called 'out' or to file. The -f file option changes the name of the log file persistently.

The 'd' command does
   mv out ,out
before creating a new 'out' file unless told to append instead.

The first argument to the 'd' command, the todo argument, must consist of one of these:
c Run the following command. You can use ; | > etc. if you escape them.
m Run 'make' with the arguments given.
s Run the same command again. Extracts the last command from 'out' and runs it again, as root if the previous run was as root, and without 'nice' unless you ask for 'nice' again.
e like s but lets you edit the command before running
h Print a history of commands logged in 'out'.
You can add any of these:
a Append to 'out'.
n Run with 'nice'.
r Run as root.
x Clear the screen.
, mv ,out out before proceeding.
and one of these:
p Just print the command that would be executed; don't run it.
w Wait for it.
f Wait for it, and show the command output as it progresses.
! Disown the process, so it will continue if you log out. Put this last so your shell won't interpret it as asking for shell history.

You have to go to some lengths to preserve quotes around arguments, e.g.,
   d c echo '"'a   b'"'

The 'd' command comes along with several helper shell functions:

q tail -f out
qq cat out
qt tail -20 out
cq clear ; q
cqq clear ; qq
wq wait "$@" ; printf "\007" ; qq
wqt wait "$@" ; printf "\007" ; qt

The output from d into the file 'out' consists of
   prologue
   output from the command
   epilogue
as shown in the example below, which does this:

223 Z% d c 'sleep 5 ; echo Hello Folks'
[5] 3937
224 Z% 
[5]  + 3937 done       yostD_run
224 Z% d sna
Run again nice: sleep 5 ; echo Hello Folks!
[5] 3965
225 Z% 
[5]  + 3965 done       yostD_run
225 Z% qq
=d= tbegin 2014-06-16T21:23:51 PDT Mon
=d= see    http://yost.com/computers/d/
=d= host   DaveMBP
=d= uname  Darwin DaveMBP 13.3.0 Darwin Kernel Version 13.3.0: Tue Jun  3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
=d= path   /Users/yost/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin::
=d= wd     /Users/yost/Desktop
=d= cmd    sleep 5 ; echo Hello Folks
=d==begin / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \
Hello Folks
  0.01s user 0.02s system 0% cpu 5.029 total
=d==end   \ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /
=d= status 0
=d= tend   2014-06-16T21:23:57 PDT Mon
========== =====================================================================
=d= tbegin 2014-06-16T21:24:05 PDT Mon
=d= see    http://yost.com/computers/d/
=d= host   DaveMBP
=d= uname  Darwin DaveMBP 13.3.0 Darwin Kernel Version 13.3.0: Tue Jun  3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
=d= path   /Users/yost/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin::
=d= wd     /Users/yost/Desktop
=d= cmd    nice sleep 5 ; echo Hello Folks!
=d==begin / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \
Hello Folks!
  0.01s user 0.02s system 0% cpu 5.029 total
=d==end   \ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /
=d= status 0
=d= tend   2014-06-16T21:24:10 PDT Mon
========== =====================================================================
226 Z% d sp
sleep 5 ; echo Hello Folks!     
227 Z% d h
tbegin 2014-06-16T21:23:51 PDT Mon
cmd    sleep 5 ; echo Hello Folks
status 0
tend   2014-06-16T21:23:57 PDT Mon
====== =====================================================================
tbegin 2014-06-16T21:24:05 PDT Mon
cmd    nice sleep 5 ; echo Hello Folks!
status 0
tend   2014-06-16T21:24:10 PDT Mon
====== =====================================================================
228 Z% d erf
Run again sudo: echo Hello, Folks!
Password: 
Hello, Folks!
  0.01s user 0.02s system 132% cpu 0.024 total
229 Z% d h
tbegin 2014-06-16T21:24:44 PDT Mon
cmd    sudo echo Hello, Folks!
status 0
tend   2014-06-16T21:24:44 PDT Mon
====== =====================================================================
230 Z% 

Download d.sh.

To use the d command and its helpers, you need to source d.sh from your zsh or bash.

I have tested this only with zsh 5.0.5 and bash 3.2.51(1)-release. Please feel free to send bug fixes.


http://Yost.com/computers/d/ - this page
1991-04-xx 2.0 Separate, sourceable file for zsh
2004-12-19 4.0
2006-07-09 5.0 Published on the web
2006-07-09 5.1 License fixed
2006-07-14 5.2 'd s' now echoes the command it will execute.
2006-12-14 5.3 fix "d s" bug when 'out' file doesn't exist
2006-12-27 5.4 make it work with bash, ksh, and sh
2006-12-28 6.0 New options: f tail -f, x clear, + c++filt
2010-08-07 6.1 Cleaned up the --help
2012-02-08 7.0 Help improvements, new =d= line beginning, lots of cleanup
2013-01-13 8.0 Added space after =d= line beginning, -begin and -end
2014-06-12 9.0 Lots of changes. See the comment at top of the script
2014-06-15 10.0 s in zsh lets you modify before running, f works better
2014-09-02 11.0 e in zsh lets you modify before running (not s)