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

Re: Simple Tip of the Day



Hannu Koivisto wrote:

> zzapper <david@xxxxxxxxxx> 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@xxxxxxxx>

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);}



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