Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
emerge -<tab> completion in ZSH
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
La`res
Arch/Herd Tester
Arch/Herd Tester


Joined: 11 Aug 2003
Posts: 79
Location: ::0

PostPosted: Sat Jan 17, 2004 10:15 pm    Post subject: emerge -<tab> completion in ZSH Reply with quote

This is a work in progress so please post any changes or errors and I will update if nessessary.

One of the wonders of zsh (and one of the things that makes zsh rock), is tab Completion. Finally got my emerge -<tab> to work so Here it is.

First a new dir needs to be made.
Code:
% mkdir ~/.zsh
% mkdir ~/.zsh/Completions

Then we need to add the Completion Sub-routine to this directory and call it _emerge
Code:
#compdef emerge

# ~/.zsh/Completions/_emerge

typeset -A opt_args
local context state line

_arguments -s -S \
   "(--help)-h[Help]" \
   "(--help -h --clean)-c[Clean the system]" \
   "(--help -h --inject)-i[Add a stub entry for a package]" \
   "(--help -h --prune)-P[WARNING - Removes older verions of a package]" \
   "(--help -h --search)-s[Search]" \
   "(--help -h --unmerge)-C[WARNING - Removes all matching packages]" \
   "(--help -h --buildpkg)-b[Build a bianary package]" \
   "(--help -h --buildpkgonly)-B[Build a bianary package but do not merge on system]" \
   "(--help -h --changelog)-l[Display Changelog while --pretend]" \
   "(--help -h --debug)-d[Debug mode]" \
   "(--help -h --deep)-D[Consider the entire dependency tree]" \
   "(--help -h --emplytree)-e[Pretend there is no dependencies present]" \
   "(--help -h --fetchonly)-f[Only fetch packages]" \
   "(--help -h --nodeps)-O[Merge with no dependencies]" \
   "(--help -h --noreplace)-n[Skip already merged packages]" \
   "(--help -h --onlydeps)-o[Only merge the dependencies]" \
   "(--help -h --pretend)-p[Pretend to Emerge]" \
   "(--help -h --quiet)-q[Quiet]" \
   "(--help -h --searchdesc)-S[Search Descriptions]" \
   "(--help -h --update)-u[Update]" \
   "(--help -h --upgradeonly)-U[Upgrade Only]" \
   '(--help -h --usepkg)-k[Use binaries from $PKGDIR]' \
   '(--help -h --usepkgonly)-K[Only use bianaries from $PKGDIR]' \
   "(--help -h --verbose)-v[Verbose]" \
   "(--help -h --version)-V[Version]" \
   -- \

The Next thing that needs to be done is to add the following to ~/.zshrc
Code:
fpath=(~/.zsh/Completions $fpath)
autoload -U ~/.zsh/Completions/*(:t)
and the following if it is not in there already
Code:
autoload -U compinit
compinit

That should do it... So the nexttime you are at your prompt Just
Code:
% emerge -<tab>
and you have all the options there. ;)

-----------------
Changelog
1.0.1 Changed " to ' on $PKGDIR lines, so the Variable is printed, not Evaluated
1.0.0 Original
_________________
Lares Moreau <lares.moreau@gmail.com>
LRU: 400755 http://counter.li.org
lares/irc.freenode.net
Back to top
View user's profile Send private message
discomfitor
l33t
l33t


Joined: 21 Feb 2003
Posts: 927
Location: None

PostPosted: Tue Jan 20, 2004 5:50 pm    Post subject: Reply with quote

Interestingly enough, my zsh is able to use emerge completion without that. I guess it's just that cool
_________________
There is no substitute for experience.
Imperfection indicates a lack of effort.
Back to top
View user's profile Send private message
La`res
Arch/Herd Tester
Arch/Herd Tester


Joined: 11 Aug 2003
Posts: 79
Location: ::0

PostPosted: Tue Jan 20, 2004 11:34 pm    Post subject: Reply with quote

Hmmm.. I'm Intruiged... What's your .zshrc and /etc/zsh/profile like??? or any other configs that may be relevent.
_________________
Lares Moreau <lares.moreau@gmail.com>
LRU: 400755 http://counter.li.org
lares/irc.freenode.net
Back to top
View user's profile Send private message
zojas
Veteran
Veteran


Joined: 22 Apr 2002
Posts: 1138
Location: Phoenix, AZ

PostPosted: Thu Jan 22, 2004 3:01 am    Post subject: Reply with quote

my zsh segfaults when I hit tab. kind of sucks.

[edit]

I had emerged zsh-4.1.1-r2 on my ibook. when I updated to zsh-4.1.1-r4 tab worked again.
_________________
http://www.desertsol.com/~kevin/ppc
Back to top
View user's profile Send private message
discomfitor
l33t
l33t


Joined: 21 Feb 2003
Posts: 927
Location: None

PostPosted: Thu Jan 22, 2004 6:05 am    Post subject: Reply with quote

zprofile:
Code:
#/etc/zsh/zshenv

#xterms buggy login things d?sn't work!
if [[ $- != *l* && -n ${PROMPT} && -n ${WINDOWID} && -n ${DISPLAY} && $SHLVL -eq 1 ]];then
  exec zsh -l
fi

[[ -o rcs ]] || return 0

setopt nullglob autocd

[[ -e "/etc/profile.env" ]] && source /etc/profile.env

#077 would be more secure, but 022 is generally quite realistic
umask 022

if [[ $(/usr/bin/whoami) == 'root' ]]
then
  export PATH="/bin:/sbin:/usr/bin:/usr/sbin:${ROOTPATH}"
  #if [ "$SHELL" = "/bin/zsh" ];then
  #fi
else
  export PATH="/bin:/usr/bin:${PATH}"
fi

[[ -n ${PROMPT} ]] && [[ $(tset -IQ - 2>&1) == *unknown* ]] && unset TERM

# Make sure that TERM is set correctly
if [[ -z ${TERM} && -n ${PS1} ]]; then
  TERM=$( tset -Q - -m 'sa:?vt100'     \
                    -m 'dialup:?vt100' \
                    -m 'su:?vt100'     \
                    -m 'dec-vt100:vt100' vt100 )
fi
#[ -z "$TERM" ] && export TERM="xterm"
export TERM="xterm"

unset PS1
unset ROOTPATH

# Colors
export red=$'%{\e[0;31m%}'
#export RED=$'%{\e[1;31m%}'
export green=$'%{\e[0;32m%}'
#export GREEN=$'%{\e[1;32m%}'
export blue=$'%{\e[0;34m%}'
#export BLUE=$'%{\e[1;34m%}'
export purple=$'%{\e[0;35m%}'
#export PURPLE=$'%{\e[1;35m}'
export cyan=$'%{\e[0;36m%}'
#export CYAN=$'%{\e[1;36m}'
#export WHITE=$'%{\e[1;37m}'
export white=$'%{\e[0;37m}'
export NC=$'%{\e[0m%}'

#Don't set a prompt if we aren't interactive
#This is the default prompt. It can be changed in a .rc file.
if [[ $- = *i* ]];then
  export RPROMPT="${cyan}(${NC}%30<...<%~%<<${cyan})${NC}"
  export PROMPT="${cyan}%t %n@%m%(!.${red}#${NC}.$)${NC} "
fi

export HOSTTYPE="$(uname -m)"
bindkey "^[[B" down-line-or-history
bindkey "^[[A" up-line-or-history
bindkey "^[[D" backward-char
bindkey "^[[C" forward-char
bindkey "^R" history-incremental-search-backward
bindkey "^F" history-incremental-search-forward
bindkey "^E" vi-end-of-line
bindkey "^A" vi-beginning-of-line
bindkey "^W" vi-forward-blank-word
bindkey "^B" vi-backward-blank-word
bindkey '\e[3~' delete-char
bindkey "^[[8~" vi-end-of-line
bindkey "^[[7~" vi-beginning-of-line


.zshrc:
Code:
HISTFILE=~/.zshhistory
HISTSIZE=30000
SAVEHIST=30000
LISTMAX=0

# Expansion options
zstyle ':completion:*' completer _complete _prefix
zstyle ':completion::prefix-1:*' completer _complete
zstyle ':completion:incremental:*' completer _complete _correct
zstyle ':completion:predict:*' completer _complete

# Completion caching
zstyle ':completion::complete:*' use-cache 1
zstyle ':completion::complete:*' cache-path ~/.zsh/cache/$HOST

# Expand partial paths
zstyle ':completion:*' expand 'yes'
zstyle ':completion:*' squeeze-slashes 'yes'

# Include non-hidden directories in globbed file completions
# for certain commands

zstyle ':completion::complete:*' '\'

#  tag-order 'globbed-files directories' all-files
zstyle ':completion::complete:*:tar:directories' file-patterns '*~.*(-/)'

# Don't complete backup files as executables
zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~'

# Separate matches into groups
zstyle ':completion:*:matches' group 'yes'

# Describe each match group.
zstyle ':completion:*:descriptions' format "%B---- %d%b"

# Messages/warnings format
zstyle ':completion:*:messages' format '%B%U---- %d%u%b'
zstyle ':completion:*:warnings' format '%B%U---- no match for: %d%u%b'
# Describe options in full
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*:options' auto-description '%d'

# }}}
# {{{ Simulate my old dabbrev-expand 3.0.5 patch

zstyle ':completion:*:history-words' stop verbose
zstyle ':completion:*:history-words' remove-all-dups yes
zstyle ':completion:*:history-words' list false

zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}

zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*' force-list always

# zsh Options

setopt                       \
     NO_all_export           \
        always_last_prompt   \
     NO_always_to_end        \
        append_history       \
     NO_auto_cd              \
        auto_list            \
        auto_menu            \
     NO_auto_name_dirs       \
        auto_param_keys      \
        auto_param_slash     \
        auto_pushd           \
        auto_remove_slash    \
     NO_auto_resume          \
        bad_pattern          \
        bang_hist            \
     NO_beep                 \
        brace_ccl            \
        correct_all          \
     NO_bsd_echo             \
        cdable_vars          \
     NO_chase_links          \
     NO_clobber              \
     correct                 \
     NO_correct_all          \
        csh_junkie_history   \
     NO_csh_junkie_loops     \
     NO_csh_junkie_quotes    \
     NO_csh_null_glob        \
        equals               \
        extended_glob        \
        extended_history     \
        function_argzero     \
        glob                 \
     NO_glob_assign          \
        glob_complete        \
     NO_glob_dots            \
        glob_subst           \
        hash_cmds            \
        hash_dirs            \
        hash_list_all        \
        hist_allow_clobber   \
        hist_beep            \
        hist_ignore_dups     \
        hist_ignore_space    \
     NO_hist_no_store        \
        hist_verify          \
     NO_hup                  \
     NO_ignore_braces        \
     NO_ignore_eof           \
        interactive_comments \
        inc_append_history   \
     NO_list_ambiguous       \
     NO_list_beep            \
        list_types           \
        long_list_jobs       \
        magic_equal_subst    \
     NO_mail_warning         \
     NO_mark_dirs            \
     NO_menu_complete        \
        multios              \
        nomatch              \
        notify               \
     NO_null_glob            \
        numeric_glob_sort    \
     NO_overstrike           \
        path_dirs            \
        posix_builtins       \
     NO_print_exit_value     \
     NO_prompt_cr            \
        prompt_subst         \
        pushd_ignore_dups    \
     NO_pushd_minus          \
        pushd_silent         \
        pushd_to_home        \
        rc_expand_param      \
     NO_rc_quotes            \
     NO_rm_star_silent       \
     NO_sh_file_expansion    \
        sh_option_letters    \
        short_loops          \
     NO_sh_word_split        \
     NO_single_line_zle      \
     NO_sun_keyboard_hack    \
        unset                \
        zle

autoload -U compinit
compinit -C

_________________
There is no substitute for experience.
Imperfection indicates a lack of effort.
Back to top
View user's profile Send private message
La`res
Arch/Herd Tester
Arch/Herd Tester


Joined: 11 Aug 2003
Posts: 79
Location: ::0

PostPosted: Sat Jan 24, 2004 6:13 pm    Post subject: Reply with quote

I Just upgraded my zsh to 4.1.1r4 and it appears that emerge -<tab> completion is now included.. I I had something wrong in my config earlier.
Anyways , Hope this helped someone...
_________________
Lares Moreau <lares.moreau@gmail.com>
LRU: 400755 http://counter.li.org
lares/irc.freenode.net
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum