[linux-l] TAB-completion fuer Optionen des ip-befehls
Ivan F. Villanueva B.
iv at artificialidea.com
Fr Nov 23 14:59:26 CET 2007
Am Di, Nov 20, 2007 07:02:43 +0100, Marek Froehlich schrieb:
> On Tue, Nov 20, 2007 at 05:41:44PM +0100, Ivan F. Villanueva B. wrote:
> > Am Di, Nov 20, 2007 08:11:02 +0100, Marek Froehlich schrieb:
> > > Hallo,
> > >
> > > kennt einer eine Moeglichkeit sich fuer das 'ip'-Kommandos nach
> > > Eingabe des Befehls per <TAB> oder '?' die weiteren moeglichen Optionen
> > > anzeigen zu lassen?
> [...]
> > Der zsh kann es. Zum Beispiel wenn ich type
> > [ivan at samsung]% ip route <TAB>
> > kommt folgende Menü:
> >
> > route command
> > add -- add new network route
> > change -- change existing network route
> [...]
>
> Hallo,
>
> bei mir leider nicht. Habe zsh mal eben installiert (ubuntu server 6.06)
> und genau das getestet, was Du beschrieben hast - klappt nicht. zsh
> schlaegt 355 completions vor ...
> Gibts bei der zsh noch irgendwelche completion-settings?
Ja sicher. Hier mein .zshrc
# Used for the vim plugin Tag List
export Tlist_Ctags_Cmd="/usr/bin/ctags"
# Makes firefox display mathml correctly
export MOZ_DISABLE_PANGO=1
# ls colors
# eval `dircolors -b ~/.dir_colors`
# Because otherwise ,v doesn't work
export LS_COLORS="no=00:fi=00:di=01;34:ln=36;47:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=31:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=00;35:*.JPG=00;35:*.jpeg=00;35:*.JPEG=00;35:*.gif=00;35:*.GIF=00;35:*.pnm=00;35:*.PNM=00;35:*.bmp=00;35:*.BMP=00;35:*.pbm=00;35:*.pgm=00;35:*.ppm=00;35:*.tga=00;35:*.xbm=00;35:*.xpm=00;35:*.tif=00;35:*.TIF=00;35:*.tiff=00;35:*.TIFF=00;35:*.png=00;35:*.mpg=01;04;35:*.MPG=01;04;35:*.mpeg=01;04;35:*.MPEG=01;04;35:*.avi=01;04;35:*.AVI=01;04;35:*.asf=01;04;35:*.ASF=01;04;35:*.fli=01;04;35:*.gl=01;04;35:*.dl=01;04;35:*.xcf=01;04;35:*.xwd=01;04;35:*.mov=01;04;35:*.wmv=01;04;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:*.java=04;36:*.html=00;34:*,v=00;34"
# print current directory in terminal title
chpwd() {
[[ -t 1 ]] || return
case $TERM in
sun-cmd) print -Pn "\e]l%~\e\\"
;;
*xterm*|rxvt|(dt|k|E)term) print -Pn "\e]2;%~\a"
;;
esac
}
case $TERM in
*xterm*) case `whoami` in
ivan|idea) export TERM="xterm-256color"
;;
*) export TERM="linux"
;;
esac
;;
esac
hosts=(golem samsung)
# Console prompt
export PS1=$'%{\e[0;34m%}[%{\e[0;35m%}%n%{\e[0;34m%}@%{\e[0;31m%}%m%{\e[0;34m%}]%# %{\e[0;37m%}'
alias black="export PS1=$PS1%{\e[0;30m%}"
alias white="export PS1=$PS1%{\e[0;37m%}"
export COLORTERM=yes
export EDITOR=vim
export PAGER=less
export BROWSER=/usr/local/bin/firefox
export LESS=aiJMSwR
# history
HISTSIZE=1000
SAVEHIST=1000
HISTFILE=~/.history_zsh
# vim modus
bindkey -v
bindkey -v '^w' backward-kill-word
bindkey "^?" backward-delete-char
# Ask for corrections
SPROMPT='zsh: correct '%R' to '%r'? ([Y]es/[N]o/[E]dit/[A]bort) '
setopt \
append_history \
complete_in_word \
auto_cd \
auto_pushd \
chase_links \
pushd_ignore_dups \
auto_list \
auto_menu \
hist_find_no_dups \
menu_complete \
complete_aliases \
glob \
extended_glob \
nonomatch
# aliases
alias svnd='svn diff | colordiff | less -R'
alias svns='svn status -u'
# Google
function google () { $BROWSER "http://www.google.com/search?q=$*"; }
alias g=google
# Change directory
function cdplus () { cd +$*; }
alias c=cdplus
alias vimrc='vim /home/ivan/.vimrc'
alias netw='watch "sudo netstat --inet -nvpa L"'
alias df='df -h'
alias cdai='cd ~/data/java/artificialidea'
alias cds='cd /home/ivan/data/mathematic/statistics'
alias xlock='xlock -mode blank'
alias psg='ps a --forest -o pgrp,nice,cmd'
alias tidy='tidy -i -utf8 -wrap 80 -asxml -asxhtml'
alias cdd='cd /usr/share/doc'
alias a=alias
alias ua=unalias
alias ls='ls --color=auto'
alias pwd='pwd -P'
alias ll='ls -lh'
alias la='ls -A'
alias l='ls -CF'
alias lsl='ls -lh'
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias r='remind -n | sort -r | less'
alias cdc='cd ~/data/java/artificialidea/src/com/artificialidea/problemsolving/adversarialsearch/chess4'
alias cdS='cd ~/data/StudyIdea'
alias px='ps aufx'
alias cd..='cd ..'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
# see 'DIRSTACKSIZE'
alias d='dirs -v'
alias h='history'
alias l=less -r
alias less=less -r
alias zl=zless -r
alias zless=zless -r
alias v=vim
alias gget='gpg --recv-keys'
alias gput='gpg --send-keys'
alias glist='gpg --fingerprint --list-keys'
# the newest 10 files
alias lsnew='ls -rtl *(.) | tail'
# the oldest 10 files
alias lsold='ls -tl *(.) | tail'
alias igrep='grep -i --color=auto'
alias oo='openoffice'
alias M='mplayer'
alias __='$EDITOR ~/.zshrc'
alias ___='exec zsh'
alias s='remind -c+2'
# global aliases
alias -g L='| less -r'
alias -g G='| grep -i --color=auto'
alias '..'='cd ..'
alias -g ...='../..'
alias -g ....='../../..'
alias -g .....='../../../..'
alias -g P='|'
alias -g O='`!!`'
# mime aliases
# alias -s java=vim
# completion for many programms
autoload -U compinit ; compinit
# color completion
zmodload -i zsh/complist
# display, show completions
compctl -g '*.(jpeg|JPEG|jpg|JPG|gif|GIF|tif|TIF|tiff|TIFF)' display
compctl -g '*.(jpeg|JPEG|jpg|JPG|gif|GIF|tif|TIF|tiff|TIFF)' show
# directory completions
compctl -/ cd
# Only shows directories for commands like cd, rmdir, etc.
compctl -g '*(-/)' + -g '.*(/)' cd chdir dirs pushd rmdir dircmp cl
# Only shows compressed files and directories
compctl -g '*.(gz|z|Z|t[agp]z|tarZ|tz)' + -g '*(-/)' gunzip gzcat zcat
# Only shows html files and directories
compctl -g "*.(html|HTML|htm|HTM)" + -g "*(-/)" + -g ".*(-/)" + -H 0 '' w3m lynx elinks wget opera dillo
compctl -g '*.(mp3|MP3|ogg|OGG|temp|TEMP|m3u|pls)' + -g '*(-/)' mpg123 xmms
compctl -g '*.(jpg|JPG|jpeg|JPEG|gif|GIF|png|PNG|bmp)' + -g '*(-/)' gimp xv display gqview
compctl -g '*.dvi' + -g '*(-/)' dvips xdvi gxdvi
compctl -g '*.ps' + -g '*(-/)' lp gv
compctl -g '*.(avi|AVI|mpg|MPG|mpeg|MPEG|ogm|OGM)' mplayer M
fignore=( ,v .BAK .bak .alt .old .aux .toc \~)
# zstyle - neue Completion. Syntax:
# zstyle 'completion:function:completer:command:argument:tag' property value[s]
#
# Beispiel aus dem Manual zshcompsys(1):
# zstyle ':completion::complete:dvips:option-o-1:files' menu yes
# DIeses Kommando stellt bei einem dvips -o <Tab> alle Dateien und
# Verzeichnisse in einem Menü zur Verfügung.
# Maximal zwei Fehler pro Kommando.
# zstyle ':completion:*:correct:*' max-errors 2 numeric
# Fügt den ursprünglich eingegebenen String auch als Completion auf.
zstyle ':completion:*:correct:*' original true
zstyle ':completion:*:correct:*' insert-unambiguous true # RTFM :P
# Welche Funktionen sollen zur Vervollständigung genutzt werden?
zstyle ':completion:*' completer _complete _correct _approximate
# Globbing
zstyle ':completion:*' glob true
# Verbose. Immer doch!
zstyle ':completion:*' verbose yes
# Format der Corrections, Warnungen, etc.
zstyle ':completion:*:corrections' format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}'
zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}%d%{\e[0m%}'
zstyle ':completion:*:messages' format $'%{\e[0;31m%}%d%{\e[0m%}'
zstyle ':completion:*:warnings' format $'%{\e[0;31m%}No matches for: %d%{\e[0m%}'
zstyle ':completion:*' group-name ''
zstyle -e ':completion:*:approximate:*' max-errors \
'reply=( $(( ($#PREFIX+$#SUFFIX)/3 )) numeric )'
# Farbige Completions. Nutzt für Dateinamencompletion $LS_COLORS.
zstyle ':completion:*' list-colors ''
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
# Bei der Completion: Menü mit inversen aktiven Einträgen. Cool!
zstyle ':completion:*' menu yes=long-list
zstyle ':completion:*' menu select=2
##################################
# Completions for some programs:
##################################
# java,javac
# unset the function for completion of java (because it search in all files
# in CLASSPATH and takes too long when there are a lot.
compdef -d java
zstyle ':completion:*:*:java:*' file-patterns '*(/):directories *.class:classes'
zstyle ':completion:*:*:javac:*' file-patterns '*(/):directories *.java:sources'
# Other possibility:
# compctl -g '*(-/)' -J directories -t+ + -g '*.class' -J classes java
# SSH - Erst User, dann Host.
zstyle ':completion:*:ssh:*' group-order 'hosts' 'users'
zstyle ':completion:*:(ssh|scp):*' hosts \
golem humunculus egal me.in-berlin.de boadilla.dyndns.org
zstyle ':completion:*:(ssh|scp):*:users' ignored-patterns \
adm bin daemon halt lp named shutdown sync
# rm - Reihenfolge: Erst Backupdateien, dann Bytecompiled Files,
# danach core-Files, erst dann restliche Dateien.
zstyle ':completion:*:*:rm:*' file-patterns '(*~|\\#*\\#):backup-files' \
'*.zwc:zsh\ bytecompiled\ files' 'core(|.*):core\ files' '*:all-files'
# kill - unglaubliche Completions!
zstyle ':completion:*:kill:*' command 'ps xf -u $USER -o pid,%cpu,tty,cputime,cmd'
zstyle ':completion:*:kill:*' insert-ids single
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*' force-list always
# less und mutt: Umfangreiches Menü.
zstyle ':completion:*:*:less:*' menu yes select
zstyle ':completion:*:*:mutt:*' menu yes select
# 2005-02-27: Navigation im Completion-Menü. GENIAL!
# Navigation in der Completion-Liste (Tab-Tab): hjkl wählt aus, Return fügt ein
# und beendet das Menü (wobei es weiterhin angezeigt wird)
#
# Die Befehle funktionieren nur, *nachdem* zsh/complist geladen wurde!
bindkey -M menuselect 'h' vi-backward-char # links
bindkey -M menuselect 'j' vi-down-line-or-history # unten
bindkey -M menuselect 'k' vi-up-line-or-history # oben
bindkey -M menuselect 'l' vi-forward-char # rechts
# Fügt die Completion auf der Kommandozeile ein, lässt aber das Menü
# für eine Weitere Vervollständigung offen.
bindkey -M menuselect 'i' accept-and-menu-complete
# Fügt die Completion auf der Kommandozeile ein und zeigt dann ein
# Menü mit weiterhin möglichen Completions. "Engere Auswahl"
bindkey -M menuselect 'o' accept-and-infer-next-history
# Output last command in menus pressing CTRL-o
_jh-prev-result () {
hstring=$(eval `fc -l -n -1`)
set -A hlist ${(@s/
/)hstring}
compadd - ${hlist}
}
zle -C jh-prev-comp menu-complete _jh-prev-result
bindkey '^o' jh-prev-comp
# Keep output in variable $kept
keep() {
kept=()
kept=( $~* )
if [[ ! -t 0 ]]; then
while read line; do
kept+=( $line )
done
fi
print -Rc - $kept
}
# Then you can write
# locate -i pictures | grep -i thursday | grep -i png | keep
# and thanks to the magic of zsh running the last command of a pipe in the
# current shell when that command is a function or builtin, you get what you
# want in $kept.
Mehr Informationen über die Mailingliste linux-l