zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: Automatic completion on <return>
Date: Thu, 11 Apr 2013 09:51:00 -0700	[thread overview]
Message-ID: <130411095100.ZM9077@torch.brasslantern.com> (raw)
In-Reply-To: <OFC3CCF1B0.362C13EF-ONC1257B4A.00267D76-C1257B4A.00279747@de.ibm.com>

On Apr 11,  9:12am, Dominik Vogt wrote:
} Subject: Automatic completion on <return>
}
} I've another idea how to extend this, but I'll write another message
} for that.

I think your Subject on this message is actually about the other message?

} I already have a "smart" cd-script that allows to "cd" into files:
} 
[...]
} 
} Now I wonder how this logic could be extended to work with the autocd
} option.  Is it possible to augment command execution with a script.  Is
} there any "hook" function that is automatically called if a command
} from the command line cannot be executed because it does not exist?

There is a command_not_found_handler shell function, but you can't use it
for this because it doesn't run until after the parent shell has forked
once to attempt to execute an external command.

You might be able to do something in the zle-line-finish widget:

    zle-line-finish() {
	setopt localoptions no_nomatch no_nullglob no_cshnullglob
	set -- ${(z)BUFFER}
	if (( $# <= 2 )) && [[ ! -x =$1 ]]
	then BUFFER="cd $BUFFER"
	fi
    }
    zle -N zle-line-finish

This won't work for "automatic cd" attempts buried inside multi-line
constructs, etc., and you probably want some additional tests to avoid
having this fire on the first line of a multi-line input or when there
is an unmatched quote.  Once you have it right, you could change

    BUFFER="cd $BUFFER"

to be

    cd "$@" && BUFFER=

but you likely don't want that to excute at the PS2 prompt (for example).

For your enhancement of this idea, you could override the accept-line
widget to do a similar test and invoke completion on the first word
before (or instead of) actually accepting the line.  This would require
something along the lines of

    CURSOR=$#1
    zle complete-word

and then grab the BUFFER contents again and repeat the -x test.

-- 
Barton E. Schaefer


      reply	other threads:[~2013-04-11 16:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-11  7:12 Dominik Vogt
2013-04-11 16:51 ` Bart Schaefer [this message]

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=130411095100.ZM9077@torch.brasslantern.com \
    --to=schaefer@brasslantern.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).