From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13940 invoked by alias); 24 Jul 2012 04:17:14 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17184 Received: (qmail 22197 invoked from network); 24 Jul 2012 04:17:10 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at benizi.com designates 64.130.10.15 as permitted sender) Date: Tue, 24 Jul 2012 00:08:49 -0400 (EDT) From: "Benjamin R. Haskell" To: Zsh Users Subject: Completion for command-not-found "commands" Message-ID: User-Agent: Alpine 2.01 (LNX 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII 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.) Longer version: A colleague of mine finally convinced me that using his 'g___' aliases for git commands was superior to using my 'g ___' versions. E.g.: ==> in his ~/.bashrc <== alias gst='git status' alias gco='git checkout' ======================== ==> vs. my ~/.gitconfig <== [alias] st = status co = checkout ==> and my ~/.zshrc <== alias g=git ======================= However, I'm still convinced that I'd rather keep mine as git [alias]'es, rather than shell aliases (When getting slightly complex, git [alias]es can be shell functions). So, I wrote the following: valid_git_alias () { git config -l | grep -qF "alias.$1=" } valid_git_command () { # my `awk` is better than my `zsh` for this kind of string manipulation: git help --all | awk '/---/ { ok=1 ; OFS="\n" ; ORS="" } /^ / { NF=NF+1 ; if (ok) print $0 }' | grep -qF $1 } command_not_found_handler () { [[ $1 = g* ]] || return 1 local al=${1#g} shift valid_git_alias $al || valid_git_command $al || return 1 git $al "$@" return 0 } This lets me do: `gst` -- gets converted to `git st` (which is one of my git [alias]es) `grm` -- gets converted to `git rm` (which is a built-in git command) The problem is that I've lost shell-completion (which I had with the `g ___` version). E.g. `g checkout ` would complete branches and tags. And, with: _git-co () { _git-checkout "$@" } `g co ` would behave the same. -- Best, Ben