zsh-users
 help / color / mirror / code / Atom feed
* tab completion in an alias
@ 2010-02-24  5:21 John Magolske
  2010-02-25 14:12 ` Peter Stephenson
  2010-02-25 14:14 ` Mikael Magnusson
  0 siblings, 2 replies; 4+ messages in thread
From: John Magolske @ 2010-02-24  5:21 UTC (permalink / raw)
  To: zsh-users

I was impressed to read in the recent post on dirs & popd how

    cd -<tab>

allows one to tabcomplete the directory stack & scroll down through it
with the <down> key. I'd like to wrap this in an alias that includes
the <tab>, something like (and I know this doesn't work):

    alias d='cd -	'

So that I could type d, then the enter key, and be presented with the
directory stack as a menu to scroll down through. Is there some way to
accomplish this?

Regards,

John


-- 
John Magolske
http://B79.net/contact


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

* Re: tab completion in an alias
  2010-02-24  5:21 tab completion in an alias John Magolske
@ 2010-02-25 14:12 ` Peter Stephenson
  2010-02-25 16:40   ` Bart Schaefer
  2010-02-25 14:14 ` Mikael Magnusson
  1 sibling, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2010-02-25 14:12 UTC (permalink / raw)
  To: zsh-users

On Tue, 23 Feb 2010 21:21:36 -0800
John Magolske <listmail@b79.net> wrote:
>     alias d='cd -	'
> 
> So that I could type d, then the enter key, and be presented with the
> directory stack as a menu to scroll down through. Is there some way to
> accomplish this?

The following seemed to work (4.3.10)...


zle-line-init() {
  if [[ -n $ZLE_PUSH_STRING ]]; then
    zle -U "$ZLE_PUSH_STRING"
    unset ZLE_PUSH_STRING
  fi
}
zle -N zle-line-init
alias d="ZLE_PUSH_STRING=\$'cd -\\C-i'"


This causes it to preload the string into the line editor as a string of
characters at the start.  They have to be raw characters to make the tab
active; that's the simplest way I found of doing it.  There are no doubt
entirely different ways of geting a similar effect.

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


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

* Re: tab completion in an alias
  2010-02-24  5:21 tab completion in an alias John Magolske
  2010-02-25 14:12 ` Peter Stephenson
@ 2010-02-25 14:14 ` Mikael Magnusson
  1 sibling, 0 replies; 4+ messages in thread
From: Mikael Magnusson @ 2010-02-25 14:14 UTC (permalink / raw)
  To: John Magolske; +Cc: zsh-users

On 24 February 2010 06:21, John Magolske <listmail@b79.net> wrote:
> I was impressed to read in the recent post on dirs & popd how
>
>    cd -<tab>
>
> allows one to tabcomplete the directory stack & scroll down through it
> with the <down> key. I'd like to wrap this in an alias that includes
> the <tab>, something like (and I know this doesn't work):
>
>    alias d='cd -       '
>
> So that I could type d, then the enter key, and be presented with the
> directory stack as a menu to scroll down through. Is there some way to
> accomplish this?

I can only think of one, but it's probably too annoying to use:
bindkey -s 'd^M' $'cd -\x09'

There are two problems here:
1) you need to hit enter pretty quickly.
2) there will be a slight pause after every d you type before it appears.

Actually that's a lie, you can do something up like this too
zle -N accept-line my_accept_line_wrapper
function my_accept_line_wrapper() {
  if [[ $BUFFER = d ]]; then
    BUFFER=
    zle -U $'cd -\x09'
    #doing the above sequence by putting the text in $BUFFER and calling
    #zle expand-or-complete doesn't work, the cursor is in the wrong position
    #setting $CURSOR to 4 doesn't seem to help, nor does zle end-of-line
  else
    zle .$WIDGET
  fi
}

-- 
Mikael Magnusson


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

* Re: tab completion in an alias
  2010-02-25 14:12 ` Peter Stephenson
@ 2010-02-25 16:40   ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2010-02-25 16:40 UTC (permalink / raw)
  To: zsh-users

On Feb 25,  2:12pm, Peter Stephenson wrote:
}
} zle-line-init() {
}   if [[ -n $ZLE_PUSH_STRING ]]; then
}     zle -U "$ZLE_PUSH_STRING"
}     unset ZLE_PUSH_STRING
}   fi
} }
} zle -N zle-line-init
} alias d="ZLE_PUSH_STRING=\$'cd -\\C-i'"

I like that approach, but it doesn't work very well unless your 
zstyles etc. send you directly into menu selection on the first
tab.  It should also perhaps check whether the directory stack is
(not) empty before proceeding.

Using an alias for this seems a little strange in the first place,
because it shouldn't need to run as a command; e.g., you'd never
need/want to prime zle-line-init this way inside a "while" loop.

I'd probably do this with a "select" command to present the menu,
but then you don't get a fancy curses-based arrow-key interface.


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

end of thread, other threads:[~2010-02-25 16:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-24  5:21 tab completion in an alias John Magolske
2010-02-25 14:12 ` Peter Stephenson
2010-02-25 16:40   ` Bart Schaefer
2010-02-25 14:14 ` Mikael Magnusson

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