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

Re: Completion for command-not-found "commands"



On Jul 24, 12:08am, Benjamin R. Haskell wrote:
}
} The very-short version of my question is: How can I dynamically get 
} completion for `git rm` when what I've typed on the commandline so far 
} is `grm`?  ("dynamically" meaning without defining a bunch of compdef's 
} up front.)

You probably want to write a completer function to insert into your
"completers" style.  This is a crude version but mostly works:

    _check_for_git_alias () {
	[[ $words[1] = g* ]] || return 1
	local al=${words[1]#g}

	if valid_git_alias $al || valid_git_command $al
	then
	    words[1]=(git $al)
	    ((++CURRENT))
	    _normal
	else
	    return 1
	fi
    }
    zstyle ':completion:*' completer _check_for_git_alias \
	whatever you already had for this style goes here

Obviously there are a bunch more tests you can do to figure out whether
it's even reasonable to treat $words[1] as a git alias or command, and
you may want to try this in some other ordering of the zstyle rather
than right at the beginning, but hopefully this gets you started.

-- 
Barton E. Schaefer



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