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

Re: file completion(?) erases word typed



Bart Schaefer wrote on Wed, Aug 24, 2016 at 17:04:54 -0700:
> On Aug 24,  7:13pm, Daniel Shahaf wrote:
> }
> } >           +_path_files:713> compadd -Qf -J -default- -p usr/local/bin/ -s '' -W /usr/local/bin/ -M 'r:|/=* r:|=*' -a tmp1
> } > 
> } > I have no idea why ignoring the path minus its leading slash would ever
> } > be correct, but in any case this appears to be adding the full path by
> } > two different and contradictory approaches.
> } 
> } What _absolute_command_paths intended to be is:
> } 
> } - You can type in an absolute path to an executable file, even if that
> }   file is not in $PATH or in $commands.
> 
> What's the reason for passing -P / to _path_files in _typed-in_* ?

_typed-in_* must complete only absolute paths.  The -P / was an attempt
to disallow non-absolute paths.

Perhaps this would be better?  There may be a way to rewrite it without
-P entirely, but that evades me at the moment.

diff --git a/Completion/Unix/Type/_absolute_command_paths b/Completion/Unix/Type/_absolute_command_paths
index e9ab170..f61f04d 100644
--- a/Completion/Unix/Type/_absolute_command_paths
+++ b/Completion/Unix/Type/_absolute_command_paths
@@ -16,7 +18,13 @@ _hashed_absolute_command_paths() {
 # This function completes absolute pathnames of executables, e.g., /etc/rc.local
 _typed-in_absolute_command_paths() {
   # TODO: the description "full path to an executable" and tag in the caller are ignored by _path_files
-  _path_files -/ -g '*(-*)' -P / -W /
+  if [[ -z $PREFIX ]]; then
+    _path_files -/ -g '*(-*)' -P / -W /
+  elif [[ $PREFIX[1] == / ]]; then
+    _path_files -/ -g '*(-*)' -W /
+  else
+    return 1
+  fi
 }
 
 _absolute_command_paths() {

> That's what's causing the strange -p usr/local/bin getting passed to
> compadd.  Despite what the doc says, _path_files doesn't actually pass
> the -P option along to compadd, instead it calls "compset -P" which
> makes it an ignored prefix instead.
> 
> I'm still not sure whether (or what) this has to do with the word on
> the line disappearing.

*nod*



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