From: "Benjamin R. Haskell" <zsh@benizi.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Completion for command-not-found "commands"
Date: Tue, 24 Jul 2012 00:08:49 -0400 (EDT) [thread overview]
Message-ID: <alpine.LNX.2.01.1207232334460.27115@hp.internal> (raw)
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 <Tab>` would complete branches and
tags. And, with:
_git-co () { _git-checkout "$@" }
`g co <Tab>` would behave the same.
--
Best,
Ben
next reply other threads:[~2012-07-24 4:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-24 4:08 Benjamin R. Haskell [this message]
2012-07-24 15:49 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LNX.2.01.1207232334460.27115@hp.internal \
--to=zsh@benizi.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).