Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: following -C option in make completion
- X-seq: zsh-workers 44896
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: PATCH: following -C option in make completion
- Date: Wed, 06 Nov 2019 22:51:09 +0100
- Authentication-results: amavisd4.gkg.net (amavisd-new); dkim=pass (2048-bit key) header.d=yahoo.co.uk
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1573077066; bh=j2t4HFgc2kPdtM9yLGPLFZBRXtNLLsFVwvruLVsZHIc=; h=From:To:Subject:Date:References:From:Subject; b=Eb4iWbGyNaiELTCad5SNtyYviVqDSfhYql0kCNDHFWWsaSCj3SfjA7/jLCcmO1GJ/9MclcjEtmCiXHWg9EaFn+dcKhs4tKtsTBYOxMUH2g/d9PVL52/O4DYanZnDgHZ8FEOm2hq1vMMCN038cafDOuAJnjFt6yeHYmHD39hMGlm/NxlpE+3wJh4PmGX7176Jiga3TtgUaveEUGxYuDeBNt2qHJHZbhL1bCr/kl/AoIwSdCA4tTHhS8gzRIf/LJfKpeOfvf2MV0ZWaEPq/DPTV3uDfxs/+mANt7roEvaPaA5UXQQx85U+A6rsbABfLe2pgmBkYLrRpvgC2q8bf24YTQ==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <2024-1573077069.922525.ref@CD2K.zG8N.q383>
In the make completion, there's some very old logic for picking out the
argument to -C. _arguments makes this rather easier if we just look in
$opt_args and has the advantage that we can handle -Cdir and --directory
forms (not just -C dir).
This patch also uses the computed $basedir value for our view of the GNU
make $(CURDIR) macro so it will handle include files referenced relative
to $(CURDIR).
Previously $basedir was forced into absolute form which I don't think
gains us anything - _files -W doesn't care. Neither does finding files
to include. But perhaps this breaks things for some form or another.
I'm also not sure what the (q) modifier achieved. I've used
${(Q)~opt_args... so it'll expand usernames and remove a level of
quoting. opt_args also does some extra quoting for colons which could
also be removed. We could do with some sort of safe-eval for where
completion functions make use of bits of the command line - expanding
variables and named directories is useful but command-substitutions not
so.
Oliver
diff --git a/Completion/Unix/Command/_make b/Completion/Unix/Command/_make
index 3dcf479c3..06971f07a 100644
--- a/Completion/Unix/Command/_make
+++ b/Completion/Unix/Command/_make
@@ -118,35 +118,9 @@ _make-parseMakefile () {
done
}
-_make-findBasedir () {
- local file index basedir
- basedir=$PWD
- for (( index=0; index < $#@; index++ ))
- do
- if [[ $@[index] == -C ]]
- then
- file=${~@[index+1]} 2>/dev/null
- if [[ -z $file ]]
- then
- # make returns with an error if an empty arg is given
- # even if the concatenated path is a valid directory
- return
- elif [[ $file == /* ]]
- then
- # Absolute path, replace base directory
- basedir=$file
- else
- # Relative, concatenate path
- basedir=$basedir/$file
- fi
- fi
- done
- print -- $basedir
-}
-
_make() {
- local prev="$words[CURRENT-1]" file expl tmp is_gnu incl match
+ local prev="$words[CURRENT-1]" file expl tmp is_gnu incl match basedir
local context state state_descr line
local -a option_specs
local -A VARIABLES VAR_ARGS opt_args
@@ -214,15 +188,18 @@ _make() {
_arguments -s $option_specs \
'*:make target:->target' && ret=0
+ basedir=${(Q)~opt_args[-C]:-${opt_args[--directory]}}
+ VAR_ARGS[CURDIR]="${basedir:=$PWD}"
+
case $state in
(dir)
_description directories expl "$state_descr"
- _files "$expl[@]" -W ${(q)$(_make-findBasedir ${words[1,CURRENT-1]})} -/ && ret=0
+ _files "$expl[@]" -W $basedir -/ && ret=0
;;
(file)
_description files expl "$state_descr"
- _files "$expl[@]" -W ${(q)$(_make-findBasedir $words)} && ret=0
+ _files "$expl[@]" -W $basedir && ret=0
;;
(debug)
@@ -239,11 +216,9 @@ _make() {
file=${(v)opt_args[(I)(-f|--file|--makefile)]}
if [[ -n $file ]]
then
- [[ $file == [^/]* ]] && file=${(q)$(_make-findBasedir $words)}/$file
+ [[ $file == [^/]* ]] && file=$basedir/$file
[[ -r $file ]] || file=
else
- local basedir
- basedir=${$(_make-findBasedir $words)}
if [[ $is_gnu == gnu && -r $basedir/GNUmakefile ]]
then
file=$basedir/GNUmakefile
@@ -287,7 +262,7 @@ _make() {
_alternative \
'targets:make target:compadd -Q -a TARGETS' \
'variables:make variable:compadd -S = -F keys -k VARIABLES' \
- '*:file:_files' && ret=0
+ '*:file:_files -W $basedir' && ret=0
fi
esac
Messages sorted by:
Reverse Date,
Date,
Thread,
Author