openmind ☃   August 28, 2008  ☃  ZSH: Job Control  ()

In bash you can background a process with CTRL+Z and bring
it to the foreground with fg <n>, where n is the 1-indexed
number of the job in order of suspension:

# sleep 10
[1]+  Stopped                 sleep 10
# sleep 20
[2]+  Stopped                 sleep 20
# sleep 30
[3]+  Stopped                 sleep 30
# jobs
[1]   Stopped                 sleep 10
[2]-  Stopped                 sleep 20
[3]+  Stopped                 sleep 30
# fg 1
sleep 10
# fg 2
sleep 20
# fg 3
sleep 30

In zsh, the same applies, but the syntax is a little different:

% sleep 10
zsh: suspended  sleep 10
% sleep 20
zsh: suspended  sleep 20
% sleep 30
zsh: suspended  sleep 30
% jobs
[1]    suspended  sleep 10
[2]  - suspended  sleep 20
[3]  + suspended  sleep 30
% fg %1
[1]    continued  sleep 10
...

Also, in zsh, you get tab-completion of just about everything,
including job control:

% fg <tab>
% fg %sleep\fg %sleep\
%1  -- sleep 10
%2  -- sleep 20
%3  -- sleep 30
%4  -- sleep 10
%5  -- sleep 20

blog comments powered by Disqus