zsh-users
 help / color / mirror / code / Atom feed
* Edit result of last command
@ 2004-11-29 19:35 zzapper
  2004-11-29 19:58 ` Thomas Köhler
  2004-11-29 20:02 ` Bart Schaefer
  0 siblings, 2 replies; 9+ messages in thread
From: zzapper @ 2004-11-29 19:35 UTC (permalink / raw)
  To: zsh-users

Hi

say I've done a command a find/ls whatever

eg 
>ls *add*
which returns
addition.html

I can then type
> vi $(!!)

But that's way too tiring

So I wrote the following function vr

function vr () { 
gvim.exe $($(history -1 | sed "s/^ *[0-9]* *//g")) &
}

This does the trick, but how would you zedii do it?
zzapper (vim, cygwin, wiki & zsh)
--

vim -c ":%s%s*%CyrnfrTfcbafbeROenzSZbbyranne%|:%s)[R-T]) )Ig|:norm G1VGg?"

http://www.vim.org/tips/tip.php?tip_id=305  Best of Vim Tips


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Edit result of last command
  2004-11-29 19:35 Edit result of last command zzapper
@ 2004-11-29 19:58 ` Thomas Köhler
  2004-11-29 20:02 ` Bart Schaefer
  1 sibling, 0 replies; 9+ messages in thread
From: Thomas Köhler @ 2004-11-29 19:58 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 742 bytes --]

Hi,

zzapper wrote:
> Hi
> 
> say I've done a command a find/ls whatever
> 
> eg 
> >ls *add*
> which returns
> addition.html
> 
> I can then type
> > vi $(!!)
> 
> But that's way too tiring
> 
> So I wrote the following function vr
> 
> function vr () { 
> gvim.exe $($(history -1 | sed "s/^ *[0-9]* *//g")) &
> }
> 
> This does the trick, but how would you zedii do it?

function VR() {
BUFFER='gvim.exe $(!!)' 
}
zle -N VR
bindkey vr VR

Ciao,
Thomas

-- 
 Thomas Köhler       Email:       jean-luc@picard.franken.de
     <><             WWW:              http://gott-gehabt.de
                     IRC:                           tkoehler
                     PGP public key available from Homepage!

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Edit result of last command
  2004-11-29 19:35 Edit result of last command zzapper
  2004-11-29 19:58 ` Thomas Köhler
@ 2004-11-29 20:02 ` Bart Schaefer
  2004-11-29 21:34   ` Juhapekka Tolvanen
                     ` (2 more replies)
  1 sibling, 3 replies; 9+ messages in thread
From: Bart Schaefer @ 2004-11-29 20:02 UTC (permalink / raw)
  To: zsh-users

On Mon, 29 Nov 2004, zzapper wrote:

> say I've done a command a find/ls whatever
[...]
> This does the trick, but how would you zedii do it?

Don't you remember the "Tip of the day: previous command output" thread 
from back in August?

  keep *add*
  vi $kept

or

  find . -name '*add*' -print | keep
  vi $kept

or any one of several completion-based variants also in that thread.

I also have this pair of keybindings:

  bindkey "^[f" forward-word
  bindkey -s "^[v" '^E)^Avi $(^[f"

which means I scroll back in the history to the command I want to capture

  ls *add*

then type esc-v and end up with

  vi $(ls *add*)
         ^
with the cursor here, so I can modify the options (add -l to grep, or 
remove -l from ls, etc.).


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Edit result of last command
  2004-11-29 20:02 ` Bart Schaefer
@ 2004-11-29 21:34   ` Juhapekka Tolvanen
  2004-11-30  2:06     ` Bart Schaefer
  2004-11-29 21:53   ` zzapper
  2004-11-30 13:29   ` zzapper
  2 siblings, 1 reply; 9+ messages in thread
From: Juhapekka Tolvanen @ 2004-11-29 21:34 UTC (permalink / raw)
  To: zsh-users



Bart Schaefer <schaefer@brasslantern.com> writes:

> On Mon, 29 Nov 2004, zzapper wrote:

> Don't you remember the "Tip of the day: previous command output"
> thread from back in August?

"Tip of the day"? Hey, I got some idea: Why don't you create a fortune
file full of zsh-tips? It would be nice thing to have.


-- 
Juhapekka "naula" Tolvanen * * http colon slash slash iki dot fi slash juhtolv
"kummaan paikkaan itsesi karkotit, syyttä syyllisten seuduille. raskaisiin
taloihin pesit, kirkuviin huoneisiin. mitä ne sinulle tekevät siellä? kuka on
raapinut nimesi pois, nimesi, kasvosi, mielesi oivat palvelemaan konetta?" CMX


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Edit result of last command
  2004-11-29 20:02 ` Bart Schaefer
  2004-11-29 21:34   ` Juhapekka Tolvanen
@ 2004-11-29 21:53   ` zzapper
  2004-11-30 13:29   ` zzapper
  2 siblings, 0 replies; 9+ messages in thread
From: zzapper @ 2004-11-29 21:53 UTC (permalink / raw)
  To: zsh-users

On Mon, 29 Nov 2004 12:02:11 -0800 (PST),  wrote:

>On Mon, 29 Nov 2004, zzapper wrote:
>
>> say I've done a command a find/ls whatever
>[...]
>> This does the trick, but how would you zedii do it?
>
>Don't you remember the "Tip of the day: previous command output" thread 
>from back in August?

Sorry Bart, I got overloaded at that time!

>
>  keep *add*
>  vi $kept
>
>or
>
>  find . -name '*add*' -print | keep
>  vi $kept
>
>or any one of several completion-based variants also in that thread.
>
>I also have this pair of keybindings:
>
>  bindkey "^[f" forward-word
>  bindkey -s "^[v" '^E)^Avi $(^[f"
>
>which means I scroll back in the history to the command I want to capture
>
>  ls *add*
>
>then type esc-v and end up with
>
>  vi $(ls *add*)
>         ^
>with the cursor here, so I can modify the options (add -l to grep, or 
>remove -l from ls, etc.).

zzapper (vim, cygwin, wiki & zsh)
--

vim -c ":%s%s*%CyrnfrTfcbafbeROenzSZbbyranne%|:%s)[R-T]) )Ig|:norm G1VGg?"

http://www.vim.org/tips/tip.php?tip_id=305  Best of Vim Tips


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Edit result of last command
  2004-11-29 21:34   ` Juhapekka Tolvanen
@ 2004-11-30  2:06     ` Bart Schaefer
  0 siblings, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2004-11-30  2:06 UTC (permalink / raw)
  To: juhtolv; +Cc: zsh-users

On Mon, 29 Nov 2004, Juhapekka Tolvanen wrote:

> "Tip of the day"? Hey, I got some idea: Why don't you create a fortune 
> file full of zsh-tips? It would be nice thing to have.

The first trouble with that idea is that I personally spend nearly all of
my time running either an email client or an editor session nowadays; I
do far less system administration and other shell-based stuff than I used
to.  So I have a hard time coming up with tips, and the ones I would come
up with aren't very widely applicable.

I'm much better at answering questions than I am at guessing what someone
might care to ask.

The second trouble is, if the "keep" tip thread is any example, that the 
good tips take too long to explain to fit them into a single fortune.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Edit result of last command
  2004-11-29 20:02 ` Bart Schaefer
  2004-11-29 21:34   ` Juhapekka Tolvanen
  2004-11-29 21:53   ` zzapper
@ 2004-11-30 13:29   ` zzapper
  2004-11-30 17:33     ` zzapper
  2004-12-01  2:38     ` Bart Schaefer
  2 siblings, 2 replies; 9+ messages in thread
From: zzapper @ 2004-11-30 13:29 UTC (permalink / raw)
  To: zsh-users

On Mon, 29 Nov 2004 12:02:11 -0800 (PST),  wrote:

>On Mon, 29 Nov 2004, zzapper wrote:
>
>> say I've done a command a find/ls whatever
>[...]
>> This does the trick, but how would you zedii do it?
>
>Don't you remember the "Tip of the day: previous command output" thread 
>from back in August?
>
>  keep *add*
>  vi $kept
>
>or
>
>  find . -name '*add*' -print | keep
>  vi $kept
>
Bart,
Your tip has disappeared off the radar (I know I can find it at mla), but hat put me off the
original thread is that it turned into a bit of a dispute between diferent zedii about how to solve
the problem. Any chance you could repost your version of keep ?
zzapper (vim, cygwin, wiki & zsh)
--

vim -c ":%s%s*%CyrnfrTfcbafbeROenzSZbbyranne%|:%s)[R-T]) )Ig|:norm G1VGg?"

http://www.vim.org/tips/tip.php?tip_id=305  Best of Vim Tips


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Edit result of last command
  2004-11-30 13:29   ` zzapper
@ 2004-11-30 17:33     ` zzapper
  2004-12-01  2:38     ` Bart Schaefer
  1 sibling, 0 replies; 9+ messages in thread
From: zzapper @ 2004-11-30 17:33 UTC (permalink / raw)
  To: zsh-users

Bart,
Found it at mla

function keep() 
{
	kept=()
	kept=( $~* )
	if [[ ! -t 0 ]]; then
	    while read line; do
		kept+=( $line )
	    done
	fi
	print -Rc - $kept
}
alias keep='noglob keep '

# use example (but also could be a real complex pipe)
ls [a-c]*.php | keep

# same as

keep [a-c]*.php

# $kept now contains your list of files or whatever for later use
vi $kept

Thanx I will be wearing out this baby!!

I can see me having functions keep1..keep9

zzapper (vim, cygwin, wiki & zsh)
--

vim -c ":%s%s*%CyrnfrTfcbafbeROenzSZbbyranne%|:%s)[R-T]) )Ig|:norm G1VGg?"

http://www.vim.org/tips/tip.php?tip_id=305  Best of Vim Tips


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Edit result of last command
  2004-11-30 13:29   ` zzapper
  2004-11-30 17:33     ` zzapper
@ 2004-12-01  2:38     ` Bart Schaefer
  1 sibling, 0 replies; 9+ messages in thread
From: Bart Schaefer @ 2004-12-01  2:38 UTC (permalink / raw)
  To: zzapper; +Cc: zsh-users

On Tue, 30 Nov 2004, zzapper wrote:

> Any chance you could repost your version of keep ?

I see you found something, but you also asked back then if I could 
summarize the thread, and I found a message sitting in my drafts folder
where clearly I intended to do that.  So, here in one place, is the end
result of the thread, with a couple of corrections thrown in.

The "keep" function and alias:

    function keep {
        setopt localoptions nomarkdirs nonomatch nocshnullglob nullglob
        kept=()         # Erase old value in case of error on next line
        kept=($~*)
        if [[ ! -t 0 ]]; then
            local line
            while read line; do
                kept+=( $line )         # += is a zsh 4.2+ feature
            done
        fi
        print -Rc - ${^kept%/}(T)
    }

    alias keep='noglob keep'

The "_insert_kept" widget:

    _insert_kept() {
      (( $#kept )) || return 1
      local action
      zstyle -s :completion:$curcontext insert-kept action
      if [[ -n $action ]]
      then compstate[insert]=$action
      elif [[ $WIDGET = *expand* ]]
      then compstate[insert]=all
      fi
      if [[ $WIDGET = *expand* ]]
      then compadd -U ${(M)kept:#${~words[CURRENT]}}
      else compadd -a kept
      fi
    }

    zle -C insert-kept-result complete-word _generic
    zle -C expand-kept-result complete-word _generic  
    zstyle ':completion:*-kept-result:*' completer _insert_kept

    bindkey '^Xk' insert-kept-result
    bindkey '^XK' expand-kept-result	# shift-K to get expansion

And the "_expand_word_and_keep" replacement for _expand_word:

    _expand_word_and_keep() {
        function compadd() {
            local -A args
            zparseopts -E -A args J:
            if [[ $args[-J] == all-expansions ]]
            then
                builtin compadd -A kept "$@"
                kept=( ${(Q)${(z)kept}} )
            fi
            builtin compadd "$@"
        }
        local result
        _main_complete _expand
        result=$?
        unfunction compadd
        return result
    }

    # This line must come after "compinit" in startup:
    zle -C _expand_word complete-word _expand_word_and_keep

    # No bindkey needed, it's already ^Xe from _expand_word


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2004-12-01  2:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-29 19:35 Edit result of last command zzapper
2004-11-29 19:58 ` Thomas Köhler
2004-11-29 20:02 ` Bart Schaefer
2004-11-29 21:34   ` Juhapekka Tolvanen
2004-11-30  2:06     ` Bart Schaefer
2004-11-29 21:53   ` zzapper
2004-11-30 13:29   ` zzapper
2004-11-30 17:33     ` zzapper
2004-12-01  2:38     ` Bart Schaefer

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).