zsh-users
 help / color / mirror / code / Atom feed
From: Nikolai Weibull <mailing-lists.zsh-users@rawuncut.elitemail.org>
To: zsh-users@sunsite.dk
Subject: Re: Simple Tip of the Day
Date: Fri, 28 Oct 2005 14:26:44 +0200	[thread overview]
Message-ID: <20051028122644.GA9035@puritan.petwork> (raw)
In-Reply-To: <87ek65zwuw.fsf@trews52.bothi.fi>

Hannu Koivisto wrote:

> zzapper <david@tvis.co.uk> writes:

> > bindkey -M viins '^O' copy-prev-word
> >
> > "^O" copy-prev-word

> Wouldn't copy-prev-shell-word be even more useful for that purpose?
> It handles things like cp filename\ with\ spaces.txt ^O

What I was going to say as well, but thanks for introducing
copy-prev-word to me, as I was wanting that functionality but hadn't
found it earlier.

> > Your most useful binding?

> Hmm, I can't name just one.  But I couldn't imagine using zsh without
> the following:
> 
> bindkey '^[[A' history-beginning-search-backward # "Up"
> bindkey '^[[B' history-beginning-search-forward  # "Down"

Like Vim does it.  I have only one binding for these:

bindkey "^X^L" history-beginning-search-backward

That's also how Vim does it, in insert mode.

My most useful binding is

_sudo-command-line() {
  [[ $BUFFER != sudo\ * ]] && LBUFFER="sudo $LBUFFER"
}
zle -N sudo-command-line _sudo-command-line
bindkey "^Os" sudo-command-line

as I always forget to add a sudo...

> Just in case you are wondering what that 'cds' is, it is an
> interactive way to select a directory from the directory
> stack-treated-as-history, along the lines of a similar feature in 4nt:
> 
> cds () {
>     local DIR="$PWD"
>     if [[ ! -z "$dirstack" ]]; then
>         DIR=$(print -rl $dirstack | tac \
>             > iselect -a -f -n chdir -Q "$PWD" -t "Change directory to..." -p ${#dirstack})
>     fi
>     cd "$DIR"
> >
> 
> As you can see, it requires 'iselect' utility that is available as a
> Debian package, for example.  (I wish I could implement an iselect
> replacement using only zsh/zle.)  Also, in order to be useful it
> requires you to setopt auto_pushd.  I also setopt pushd_ignore_dups
> and set DIRSTACKSIZE to a reasonably large value.

Here's my version of a command like that:

~/.zsh/functions/d:

# contents: d command.
#
# Copyright © 2005 Nikolai Weibull <nikolai@bitwi.se>

emulate -L zsh

autoload -U colors

local color=$fg_bold[blue]
integer i=0
dirs -p | while read dir; do
  local num="${$(printf "%-4d " $i)/ /.}"
  printf " %s  $color%s$reset_color\n" $num $dir
  (( i++ ))
done
integer dir=-1
read -r 'dir?Jump to directory: ' || return
(( dir == -1 )) && return
if (( dir < 0 || dir >= i )); then
  echo d: no such directory stack entry: $dir
  return 1
fi
cd ~$dir

I don't know how iselect works, but this works very well for me.

-- 
Nikolai Weibull: now available free of charge at http://bitwi.se/!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


  reply	other threads:[~2005-10-28 12:27 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-28 11:11 zzapper
2005-10-28 11:32 ` Jean Chalard
2005-10-28 15:25   ` Bart Schaefer
2005-10-28 17:40     ` Jean Chalard
2005-10-28 15:53   ` zzapper
2005-10-28 11:47 ` Hannu Koivisto
2005-10-28 12:26   ` Nikolai Weibull [this message]
2005-10-29 12:37   ` Konstantin Sobolev
2005-10-29 14:52     ` Christian Taylor
2005-11-01 16:55       ` run-help and \cmd (was: Simple Tip of the Day) Vincent Lefevre
2005-11-01 18:02         ` Peter Stephenson
2005-11-01 18:23           ` Peter Stephenson
2005-11-01 18:55           ` Vincent Lefevre
2005-10-28 20:08 ` Simple Tip of the Day DervishD
2005-10-30  5:10 ` Philippe Troin
2005-11-01 16:58   ` Vincent Lefevre
2005-11-30 20:32 Simple Tip of The Day zzapper
2005-11-30 23:27 ` Przemyslaw Gawronski
2005-12-01 20:38 Simple Tip of the Day zzapper
2005-12-02  1:09 ` Vincent Lefevre
2005-12-02  9:13   ` Thorsten Kampe
2005-12-02 12:49     ` Mikael Magnusson
2005-12-02 19:20       ` zzapper
2005-12-03 20:28         ` zzapper
2005-12-03 22:08           ` Mikael Magnusson
2005-12-03 22:20             ` zzapper
2005-12-04  1:32               ` Mikael Magnusson

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=20051028122644.GA9035@puritan.petwork \
    --to=mailing-lists.zsh-users@rawuncut.elitemail.org \
    --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).