Skip to content

Commit

Permalink
fixed and tested tab completion for zsh
Browse files Browse the repository at this point in the history
  • Loading branch information
astralarya committed Feb 19, 2013
1 parent 13cf24e commit 38e85c6
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions to.sh
Expand Up @@ -122,22 +122,21 @@ function _to_regex {
}

# tab completion generic
# $1 = COMP_WORDS (words in buffer)
# $2 = COMP_CWORDS (index to current word)
# $TO_COMP_WORDS = array of words in buffer
# $1 = index to current word
function _to {
# create empty bookmarks file if it does not exist
if [ ! -e "$TO_BOOKMARK_FILE" ]
then
"$TO_ECHO" -n > "$TO_BOOKMARK_FILE"
fi
# get parameters
declare -a comp_words=("${!1}")
local comp_cword=$2
# get parameter
local comp_cword=$1
# get components
local cur="${comp_words[comp_cword]}"
local prev="${comp_words[comp_cword-1]}"
local cur="${TO_COMP_WORDS[comp_cword]}"
local prev="${TO_COMP_WORDS[comp_cword-1]}"
local bookmark="$(_to_path_head "$cur")"
local todir="$( _to_dir "$bookmark")"
local todir="$(_to_dir "$bookmark")"
# build reply
local compreply
if [ "$prev" = "-b" -o "$prev" = "-r" ]
Expand Down Expand Up @@ -165,11 +164,9 @@ function _to {

# tab completion bash
function _to_bash {
COMPREPLY=( $(_to COMP_WORDS[@] $COMP_CWORD) )
}
# tab completion zsh TODO remove?
function _to_zsh {
\compadd - "$(_to words[@] $CURRENT)"
declare -a TO_COMP_WORDS
TO_COMP_WORDS=( "${COMP_WORDS[@]}" )
COMPREPLY=( $(_to $COMP_CWORD) )
}

# setup tab completion
Expand Down

1 comment on commit 38e85c6

@astralarya
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit provides improved (but not perfect) tab completion for zsh. It also contains architectural restructuring as described in #5

Please sign in to comment.