From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: zsh-users@sunsite.dk
Subject: Fix up the history upon "fg"
Date: Wed, 4 Apr 2001 22:41:08 +0000 [thread overview]
Message-ID: <1010404224108.ZM434@candle.brasslantern.com> (raw)
Here's a possibly-handy function. When you use "fg" or "bg" (or one of
the abbreviations, e.g. "%+"), "getjobs" finds the original text of that
command and inserts it into the history, so that e.g., "!!" will execute
that command again rather than executing "fg" again.
If you use several arguments to "fg", e.g. "fg %2 %3 %1", the commands
for all those jobs are collected and concatenated with semicolons.
Arguably this could be implemented in C as an optional behavior of bin_fg,
so the fg command itself could be removed from the history and replaced
with the job text; but I'm not feeling that ambitious today.
This requires at least zsh-3.1.9, I think. Definitely not 3.0.anything.
# Call this from the preexec function like so:
# preexec() {
# getjobs "${(z)1}"
# }
getjobs () {
setopt localoptions noshwordsplit noksharrays
local texts
case $1 in
fg|bg) shift; [[ -n $1 ]] || set -- %% ;;
%*) ;;
*) return 0 ;;
esac
repeat $#
do
# This case statement emulates jobs.c:getjob()
case $1 in
%(|[%+])) 1=${(k)jobstates[(r)*:+:*]} ;;
%-) 1=${(k)jobstates[(r)*:-:*]} ;;
%<->) 1=${1#%} ;;
%[?]*) 1=${${(Ok)jobtexts[(R)*${1#%[?]}*]}[1]} ;;
*) 1=${${(Ok)jobtexts[(R)$1*]}[1]} ;;
esac
[[ -n $1 ]] && texts=($texts ${jobtexts[$1]})
shift
done
# Remove the "-s" below if you'd prefer that this just report
# what jobs are being affected rather than modify the history
(( $#texts )) && print -s ${(j:; :)texts}
return 0
}
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
next reply other threads:[~2001-04-04 22:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-04-04 22:41 Bart Schaefer [this message]
2001-04-10 4:43 Felix Rosencrantz
2001-04-10 7:48 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1010404224108.ZM434@candle.brasslantern.com \
--to=schaefer@candle.brasslantern.com \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).