From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12475 invoked by alias); 1 Jun 2015 04:02:49 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 35350 Received: (qmail 23389 invoked from network); 1 Jun 2015 04:02:47 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.0 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=U5Q8C7FQ9kvhsARF9b8WJVF7dFcYcqM2/G+HL4F1NR4=; b=BWiroNV6GgFI8NPWYRiwzDBv7fzCzi/OlaIgTW3LiOgQWurtAJEmu1JKxrZAFG338F JjsaNuTsnWgSOiGs3Zk/UZSPOLt4bO/pTmTx7D3eZhiI1MKzojdmqkyDxcRaz4I2nzCe OH/i6XjJTjaG8qL+4J0w95MZyD1wx2D3w8GpE/0c1Ym2tTBEUUjszXPYGdEUcjzBHJmN yIEvsOk+kwzuHmJmBMuhegNlanGaK189LI+YpLTbkhmrOlqqBYApKNxKrA6JAQ4J1mbC mlpXhC3aDdxQGkXKXbJX4Z/u6pRXM53rEewXxoZnFMlK1sdh2smlcG0wkI5w58ltercn 7R2A== X-Gm-Message-State: ALoCoQlHdwVSTjmxJPAeDgTtolHXjHHjmWj+uEt+jHfQJRw5Ph4KkAV2oTyBN6tAt29jPBeEAO4f X-Received: by 10.60.47.165 with SMTP id e5mr16339696oen.52.1433131364360; Sun, 31 May 2015 21:02:44 -0700 (PDT) From: Bart Schaefer Message-Id: <150531210240.ZM30683@torch.brasslantern.com> Date: Sun, 31 May 2015 21:02:40 -0700 In-Reply-To: Comments: In reply to Mikael Magnusson "Re: Finding the first history event of the current instance" (Jun 1, 3:50am) References: <87r3q7nzkr.fsf@gmail.com> <150529171657.ZM15077@torch.brasslantern.com> <150530154236.ZM17511@torch.brasslantern.com> <12467.1433064564@thecus.kiddle.eu> <150531165942.ZM13040@torch.brasslantern.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh workers Subject: Re: Finding the first history event of the current instance MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Jun 1, 3:50am, Mikael Magnusson wrote: } } > } > The options -N (new), -O (old), and -F (foreign) are all unused } > } } > } I think I'd favour +L for foreign (i.e. not local). It's easier to } > } remember that way. } > } > I don't think it'll affect that at all. However, it will mean that } > "fc +l" has the same meaning as "fc -l" } } It's also a lot less discoverable by fc -. And maybe a bit } confusing that neither -L nor +L would be the default. OK, so here's another step in this direction. I chose to overload the -I option ("internal"/"incremental") rather than add -N or +L. Turns out the HIST_READ flag is set for anything read from a file, so its negation is the criterion for "internal" (think of as "interactive") history. Included are updates to _fc and to the doc (which has been reordered a bit and references to "commands" mostly changed to "events"). I'm not sure how useful the inverses are. Note that foreign history is already marked with a "*" in the "fc -l" output unless line numbering is suppressed with -n. I suppose that could be mentioned in the doc, but I didn't. diff --git a/Completion/Zsh/Command/_fc b/Completion/Zsh/Command/_fc index c298721..1589244 100644 --- a/Completion/Zsh/Command/_fc +++ b/Completion/Zsh/Command/_fc @@ -12,8 +12,10 @@ words=( "${(@)words[1,CURRENT-1]:#*=*}" "${(@)words[CURRENT,-1]}" ) fc_common=( -s -S - '(-A -R -W -I -p -P)-r[reverse order of the commands]' - '(-A -R -W -I -e -p -P)-n[suppress line numbers]' + '(-A -R -W -p -P)-I[include internal (new) events only]' + '(-A -R -W -p -P)-L[include local events only]' + '(-A -R -W -p -P)-r[reverse order of the events]' + '(-A -R -W -e -p -P)-n[suppress line numbers]' ) if [[ -n ${words[(r)-[pa](|[ap])]} ]]; then @@ -32,20 +34,20 @@ else fi fc_hist=( - '(-A -R -W -I -a -p -P 2)-m[treat argument as a pattern]' - '(-A -R -W -I -e -f -E -i -t -a -p -P)-d[print time-stamps]' - '(-A -R -W -I -e -d -E -i -t -a -p -P)-f[mm/dd/yyyy format time-stamps]' - '(-A -R -W -I -e -d -f -i -t -a -p -P)-E[dd.mm.yyyy format time-stamps]' - '(-A -R -W -I -e -d -f -E -t -a -p -P)-i[yyyy-mm-dd format time-stamps]' - '(-A -R -W -I -e -d -f -E -i -a -p -P)-t[print time-stamps in specified format]:date format' - '(-A -R -W -I -e -a -p -P)-D[print elapsed times]' + '(-A -R -W -a -p -P 2)-m[treat argument as a pattern]' + '(-A -R -W -e -f -E -i -t -a -p -P)-d[print time-stamps]' + '(-A -R -W -e -d -E -i -t -a -p -P)-f[mm/dd/yyyy format time-stamps]' + '(-A -R -W -e -d -f -i -t -a -p -P)-E[dd.mm.yyyy format time-stamps]' + '(-A -R -W -e -d -f -E -t -a -p -P)-i[yyyy-mm-dd format time-stamps]' + '(-A -R -W -e -d -f -E -i -a -p -P)-t[print time-stamps in specified format]:date format' + '(-A -R -W -e -a -p -P)-D[print elapsed times]' '(-A -R -W -I -e -d -f -i -l -m -n -r -D -E -t -P)-a[with -p, automatically pop history on function return]' '(-A -R -W -I -e -d -f -i -l -m -n -r -D -E -t -P)-p[push current history to stack]' '(- *)-P[pop history from stack]' ) -fc_r='(-A -R -W -I -e)-l[list resulting commands on stdout]' +fc_r='(-A -R -W -e)-l[list resulting commands on stdout]' case $service in history) @@ -56,12 +58,11 @@ case $service in ;; *) _arguments "$fc_common[@]" "$fc_hist[@]" "$fc_r" \ - '(-A -R -W -I -a -l -n -d -f -E -i -r -t -D -p -P)-e+[specify editor to invoke]:editor to invoke:_command_names -e' \ - '(-a -l -m -e -r -n -d -f -t -E -i -R -D -A -W -p -P *)-'{\ + '(-A -R -W -a -l -n -d -f -E -i -r -t -D -p -P)-e+[specify editor to invoke]:editor to invoke:_command_names -e' \ + '(-a -l -L -m -e -r -n -d -f -t -E -i -R -D -A -W -p -P *)-'{\ 'R[read history from file]',\ 'A[append history to file]',\ -'W[write history to file]',\ -'I[read/write new events only]'} && ret=0 +'W[write history to file]'} && ret=0 ;; esac diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 1fcc7c2..2c55fab 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -662,8 +662,8 @@ findex(fc) cindex(history, editing) cindex(editing history) redef(SPACES)(0)(tt(ifztexi(NOTRANS(@ @ @ @ @ @ ))ifnztexi( ))) -xitem(tt(fc) [ tt(-e) var(ename) ] [-L] [ tt(-m) var(match) ] [ var(old)tt(=)var(new) ... ] [ var(first) [ var(last) ] ]) -xitem(tt(fc -l )[ tt(-LnrdfEiD) ] [ tt(-t) var(timefmt) ] [ tt(-m) var(match) ]) +xitem(tt(fc) [ tt(-e) var(ename) ] [ tt(-LI) ] [ tt(-m) var(match) ] [ var(old)tt(=)var(new) ... ] [ var(first) [ var(last) ] ]) +xitem(tt(fc -l )[ tt(-LI) ] [ tt(-nrdfEiD) ] [ tt(-t) var(timefmt) ] [ tt(-m) var(match) ]) xitem(SPACES()[ var(old)tt(=)var(new) ... ] [ var(first) [ var(last) ] ]) xitem(tt(fc -p )[ tt(-a) ] [ var(filename) [ var(histsize) [ var(savehistsize) ] ] ]) xitem(tt(fc) tt(-P)) @@ -674,31 +674,24 @@ shell is interactive. Usually this is detected automatically, but it can be forced by setting the tt(interactive) option when starting the shell. -Select a range of commands from var(first) to var(last) from the -history list. -The arguments var(first) and var(last) may be specified as a -number or as a string. A negative number is used as an offset -to the current history event number. -A string specifies the most recent event beginning with the given string. -All substitutions var(old)tt(=)var(new), if any, are then performed -on the commands. +The first two forms of this command select a range of events from +var(first) to var(last) from the history list. The arguments var(first) +and var(last) may be specified as a number or as a string. A negative +number is used as an offset to the current history event number. A string +specifies the most recent event beginning with the given string. All +substitutions var(old)tt(=)var(new), if any, are then performed on the +text of the events. -If the tt(-L) flag is given, only the local history is considered (see +In addition to the the number range, +startsitem() +sitem(tt(-I))(restricts to only internal events (not from tt($HISTFILE))) +sitem(tt(-L))(restricts to only local events (not from other shells, see tt(SHARE_HISTORY) in ifzman(zmanref(zshoptions))\ -ifnzman(noderef(Description of Options))). -If the tt(-m) flag is given, the first argument is taken as a -pattern (should be quoted) and only the history events matching this -pattern are considered. - -When the tt(-l) flag is given, the resulting commands are listed on -standard output. -Otherwise the editor program var(ename) is invoked on a file containing -these history events. If var(ename) is not given, the value -of the parameter tt(FCEDIT) is used; if that is not set the value of the -parameter tt(EDITOR) is used; if that is not set a builtin default, usually -`tt(vi)' is used. If var(ename) is `tt(-)', -no editor is invoked. When editing is complete, the edited -command is executed. +ifnzman(noderef(Description of Options)) -- note that tt($HISTFILE) is +considered local when read at startup)) +sitem(tt(-m))(takes the first argument as a pattern (should be quoted) and +only the history events matching this pattern are considered) +endsitem() If var(first) is not specified, it will be set to -1 (the most recent event), or to -16 if the tt(-l) flag is given. @@ -708,12 +701,20 @@ However, if the current event has added entries to the history with `tt(print -s)' or `tt(fc -R)', then the default var(last) for tt(-l) includes all new history entries since the current event began. -The flag tt(-r) reverses the order of the commands and the -flag tt(-n) suppresses command numbers when listing. +When the tt(-l) flag is given, the resulting events are listed on +standard output. Otherwise the editor program var(ename) is invoked on a +file containing these history events. If var(ename) is not given, the +value of the parameter tt(FCEDIT) is used; if that is not set the value of +the parameter tt(EDITOR) is used; if that is not set a builtin default, +usually `tt(vi)' is used. If var(ename) is `tt(-)', no editor is invoked. +When editing is complete, the edited command is executed. + +The flag tt(-r) reverses the order of the events and the +flag tt(-n) suppresses event numbers when listing. Also when listing, startsitem() -sitem(tt(-d))(prints timestamps for each command) +sitem(tt(-d))(prints timestamps for each event) sitem(tt(-f))(prints full time-date stamps in the US `var(MM)tt(/)var(DD)tt(/)var(YY) var(hh):var(mm)' format) sitem(tt(-E))(prints full time-date stamps in the European @@ -725,15 +726,14 @@ var(fmt) is formatted with the strftime function with the zsh extensions described for the tt(%D{)var(string)tt(}) prompt format in ifzman(the section EXPANSION OF PROMPT SEQUENCES in zmanref(zshmisc))\ ifnzman(noderef(Prompt Expansion)). The resulting formatted string must be -no more than 256 characters or will not be printed. +no more than 256 characters or will not be printed ) sitem(tt(-D))(prints elapsed times; may be combined with one of the -options above.) +options above) endsitem() cindex(history, stack) cindex(stack, history) - `tt(fc -p)' pushes the current history list onto a stack and switches to a new history list. If the tt(-a) option is also specified, this history list will be automatically popped when the current function scope is exited, which diff --git a/Src/builtin.c b/Src/builtin.c index 9358e8b..cfa6bc2 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -104,7 +104,7 @@ static struct builtin builtins[] = BUILTIN("pushd", BINF_SKIPINVALID | BINF_SKIPDASH | BINF_DASHDASHVALID, bin_cd, 0, 2, BIN_PUSHD, "qsPL", NULL), BUILTIN("pushln", 0, bin_print, 0, -1, BIN_PRINT, NULL, "-nz"), BUILTIN("pwd", 0, bin_pwd, 0, 0, 0, "rLP", NULL), - BUILTIN("r", 0, bin_fc, 0, -1, BIN_R, "nrlL", NULL), + BUILTIN("r", 0, bin_fc, 0, -1, BIN_R, "IlLnr", NULL), BUILTIN("read", 0, bin_read, 0, -1, 0, "cd:ek:%lnpqrst:%zu:AE", NULL), BUILTIN("readonly", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "AE:%F:%HL:%R:%TUZ:%afghi:%lptux", "r"), BUILTIN("rehash", 0, bin_hash, 0, 0, 0, "df", "r"), @@ -1435,10 +1435,6 @@ bin_fc(char *nam, char **argv, Options ops, int func) unqueue_signals(); return 0; } - if (OPT_ISSET(ops,'I')) { - zwarnnam(nam, "-I requires one of -R/-W/-A"); - return 1; - } if (zleactive) { zwarnnam(nam, "no interactive history within ZLE"); @@ -1672,7 +1668,7 @@ static int fclist(FILE *f, Options ops, zlong first, zlong last, struct asgment *subs, Patprog pprog, int is_command) { - int fclistdone = 0; + int fclistdone = 0, xflags = 0; zlong tmp; char *s, *tdfmt, *timebuf; Histent ent; @@ -1722,11 +1718,19 @@ fclist(FILE *f, Options ops, zlong first, zlong last, tdfmt = timebuf = NULL; } + /* xflags exclude events */ + if (OPT_ISSET(ops,'L')) { + xflags |= HIST_FOREIGN; + } + if (OPT_ISSET(ops,'I')) { + xflags |= HIST_READ; + } + for (;;) { - if (!OPT_ISSET(ops,'L') || !(ent->node.flags & HIST_FOREIGN)) - s = dupstring(ent->node.nam); - else + if (ent->node.flags & xflags) s = NULL; + else + s = dupstring(ent->node.nam); /* this if does the pattern matching, if required */ if (s && (!pprog || pattry(pprog, s))) { /* perform substitution */ @@ -1782,7 +1786,7 @@ fclist(FILE *f, Options ops, zlong first, zlong last, if (!fclistdone) { if (subs) zwarnnam("fc", "no substitutions performed"); - else if (OPT_ISSET(ops,'L') || pprog) + else if (xflags || pprog) zwarnnam("fc", "no matching events found"); return 1; } -- Barton E. Schaefer