Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] _fc: allow the user to limit the number of events



Which can be useful when someone has an very large HISTFILE.
I am open to a better style name if someone can think of one.

---
 Completion/Zsh/Command/_fc | 5 ++++-
 Doc/Zsh/compsys.yo         | 5 +++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/Completion/Zsh/Command/_fc b/Completion/Zsh/Command/_fc
index 68456cc..5044451 100644
--- a/Completion/Zsh/Command/_fc
+++ b/Completion/Zsh/Command/_fc
@@ -1,7 +1,7 @@
 #compdef fc history r
 
 local curcontext="$curcontext" state state_descr line ret=1
-local events num cmd sep
+local events num cmd sep _histno _histi
 typeset -A opt_args
 local fc_common fc_hist fc_r
 
@@ -75,7 +75,10 @@ if [[ -n $state ]]; then
     _wanted -2V events expl "$state_descr" compadd -M "B:0=" -ld events - \
         "${events[@]%% *}"
   elif [[ -prefix - ]]; then
+    zstyle -s ":completion:${curcontext}:history-events" history-events _histno
+    _histno=${_histno%%:<->}; [[ $_histno = <-> ]] || _histno=$((HISTNO+1))
     for num cmd in "${(kv@)history}"; do
+      (( ++_histi < _histno )) || break
       (( num=num - HISTNO ))
       events+=( "${(r.1+$#HISTNO.)num} $sep $cmd" )
     done
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index fb0abce..fa20b6b 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -1691,6 +1691,11 @@ in the list.  To avoid having matches considered as possible
 completions at all, the tt(tag-order) style can be modified as described
 below.
 )
+kindex(history-events, completion style)
+item(tt(history-events))(
+If this is set to a number, it is used to limit the number of history
+events when completing tt(fc) or tt(history).
+)
 kindex(hosts, completion style)
 item(tt(hosts))(
 A list of names of hosts that should be completed.  If this is not set,
-- 
2.6.6



Messages sorted by: Reverse Date, Date, Thread, Author