You are not logged in.

#1 2011-06-18 19:45:33

dodo3773
Member
Registered: 2011-03-17
Posts: 814

[SOLVED] autocomplete arument with zsh question

I am brand new to zsh after reading the wiki and searching around I have:

# Auto Completion And Additional Settings
autoload -U compinit
compinit
zstyle ':completion:*' menu select
export HISTFILE=~/.zsh_history
export HISTSIZE=50000
export SAVEHIST=50000
eval `dircolors -b`
setopt autopushd pushdminus pushdsilent pushdtohome
setopt autocd
setopt cdablevars
setopt ignoreeof
setopt interactivecomments
setopt nobanghist
setopt noclobber
setopt HIST_REDUCE_BLANKS
setopt HIST_IGNORE_SPACE
setopt SH_WORD_SPLIT
setopt nohup

setopt correctall

#Colored Prompt
autoload -U promptinit
promptinit

#Colors
autoload -U colors && colors

# allow approximate
zstyle ':completion:*' completer _complete _match _approximate
zstyle ':completion:*:match:*' original only
zstyle ':completion:*:approximate:*' max-errors 1 numeric

# tab completion for PID :D
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*' force-list always

# cd not select parent dir
zstyle ':completion:*:cd:*' ignore-parents parent pwd

#Special Keys
typeset -g -A key
bindkey '^?' backward-delete-char
bindkey '^[[1~' beginning-of-line
bindkey '^[[5~' up-line-or-history
bindkey '^[[3~' delete-char
bindkey '^[[4~' end-of-line
bindkey '^[[6~' down-line-or-history
bindkey '^[[A' up-line-or-search
bindkey '^[[D' backward-char
bindkey '^[[B' down-line-or-search
bindkey '^[[C' forward-char 
# completion in the middle of a line
bindkey '^i' expand-or-complete-prefix

#Directory Colors
LS_COLORS='rs=0:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:tw=30;42:ow=34;42:st=37;44:ex=01;32:';
export LS_COLORS

#History Search
bindkey "^[[A" history-search-backward
bindkey "^[[B" history-search-forward

#Aliases
alias -s txt=$EDITOR






#Moved From Bash
#CLI editor 
export EDITOR="nano"

#Update System

alias update='sudo pacman-color -Syu && yaourt -Su --aur'


# dvdauthor
export VIDEO_FORMAT=NTSC

## Aliases

alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias ls='ls --color=auto'


alias sudo='sudo '
alias pacman='pacman-color'

alias hist="history | grep "

#Colorize Man Pages

export LESS_TERMCAP_mb=$'\E[01;31m'      # begin blinking
export LESS_TERMCAP_md=$'\E[01;31m'      # begin bold
export LESS_TERMCAP_me=$'\E[0m'          # end mode
export LESS_TERMCAP_se=$'\E[0m'          # end standout-mode                 
export LESS_TERMCAP_so=$'\E[01;44;33m'   # begin standout-mode - info box                              
export LESS_TERMCAP_ue=$'\E[0m'          # end underline
export LESS_TERMCAP_us=$'\E[01;32m'      # begin underline


#Del send to trash
alias del='mv -t ~/.local/share/Trash/files'


### FUNCTIONS

# Easy extract
extract () {
  if [ -f $1 ] ; then
      case $1 in
          *.tar.bz2)   tar xvjf $1    ;;
          *.tar.gz)    tar xvzf $1    ;;
          *.bz2)       bunzip2 $1     ;;
          *.rar)       rar x $1       ;;
          *.gz)        gunzip $1      ;;
      *.jar)       jar xf $1      ;;       
          *.tar)       tar xvf $1     ;;
          *.tbz2)      tar xvjf $1    ;;
          *.tgz)       tar xvzf $1    ;;
          *.zip)       unzip $1       ;;
          *.Z)         uncompress $1  ;;
          *.7z)        7z x $1        ;;
          *)           echo "don't know how to extract '$1'..." ;;
      esac
  else
      echo "'$1' is not a valid file!"
  fi
}


#List All Available Commands
function command
{
    echo -n $PATH | xargs -d : -I {} find {} -maxdepth 1 \
        -executable -type f -printf '%P\n' | sort -u
}

function command
{
    COMMANDS=`echo -n $PATH | xargs -d : -I {} find {} -maxdepth 1 \
        -executable -type f -printf '%P\n'`
    ALIASES=`alias | cut -d '=' -f 1`
    echo "$COMMANDS"$'\n'"$ALIASES" | sort -u
}



#Custom Terminal
PS1="%* %~$ "

#Syntax Highlighting
source /home/dodo3773/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

The problem I am running into is that sometimes when I hit tab twice after I type a "-" for a command line switch I get options and sometimes I don't. For example when I type

rm -<tab><tab>

I get

--force             -f      -- ignore nonexistent files, never prompt         
--help                      -- display help message and exit                  
-i                          -- prompt before every removal                    
-I                          -- prompt when removing many files                
--interactive               -- prompt under given condition (defaulting to alw
--no-preserve-root          -- do not treat / specially                       
--one-file-system           -- stay within filesystems of files given as argum
--preserve-root             -- do not remove / (default)                      
--recursive         -R  -r  -- remove directories and their contents recursive
--verbose           -v      -- explain what is being done                     
--version                   -- output version information and exit   

and I can pick between them.

But if I do something like

 cat -<tab><tab>

or

pacman -<tab><tab>

I get

No matches for: `file'

A second question I have is when I do something like

grep -<tab><tab>

I get

zsh: do you wish to see all 160 possibilities (42 lines)? 

If I hit "y" I can see them all. But what I wanted to know is if there is a way to change the minimum number that is alright so that I can pick between them still.


Edit: I had pacman as an alias so I added "setopt completealiases" to my .zshrc and now it works. On the second question I just had to hit tab again real quick so <tab><tab><tab> worked. I believe "cat" and "echo" are not able to autocomplete the command line switches because the - could be the beginning of a file name to read.

Added

For autocompletion of command line switches for aliases, add the following to:
File: ~/.zshrc

setopt completealiases

to zsh wiki entry.

Last edited by dodo3773 (2011-06-19 05:49:07)

Offline

Board footer

Powered by FluxBB