Home | News | Download | Packages | Forum | Wiki | Github

Xbps-src bash completion script


(Viatcheslav) #1


May be is useful for somebody?


#2

I installed this file by putting it here:
/etc/bash_completion.d/xbps-src.completion
and now it gives great tab completion when using xbps-src. A fantastic time saving achievement. This could potentially be a Void patch for the bash-completion package because probably most Void users would appreciate it.
:tickets: :balloon: :ticket:


(Viatcheslav) #3

Add completion for options.


#4

The command is ./xbps-src not xbps-src
Thanks for sharing.

--- xbps-src.completion.old	2017-07-18 11:23:43.748698454 -0400
+++ xbps-src.completion.new	2017-07-18 11:33:38.255266100 -0400
@@ -1,4 +1,4 @@
-_xbps_src() {
+_./xbps_src() {
local targets cur prev archs pkgs
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
@@ -65,7 +65,7 @@
pkgs=$(compgen -f srcpkgs/ | sed -e 's,srcpkgs/,,')

case "$prev" in
-		*xbps-src| \
+		*./xbps-src| \
             -[CEfGgILNt]|[0-9])
		COMPREPLY=($(compgen -W "${targets}" -- ${cur}))
		return 0
@@ -105,4 +105,4 @@
return 0
}

-complete -F _xbps_src xbps-src
+complete -F _./xbps_src ./xbps-src

#5

But surely ./ just means “located in the present working directory” and is a shorthand way of writing “/full/path/to/xbps-src” which would also work to run the executable?
If you do ls -a you see:
. (the current directory)
… (the directory above)
so you can refer to the current one as “.”, and do say cd …/…/somedir to go 2 dirs up then down one in the second say.
I think xbps-src might be run in this way directly from the void-packages directory so you can have multiple instances which are different somehow and use them independently. Most commands are located in the PATH variable so you don’t need ./ or the full path, but they can be run just the same, for example cd /usr/bin then ./(some command located in there).
Or am I misunderstanding somehow? It seemed to work, when I typed ./x it autocompleted to ./xbps-src with a tab press anyhow.


(Viatcheslav) #6

Ok, let’s me trying to explain my script.
First of all, in the “Programmable Completion” (https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html#Programmable-Completion) we can see:

“First, the command name is identified. If a compspec has been defined for that command,
the compspec is used to generate the list of possible completions for the word.
If the command word is the empty string (completion attempted at the beginning of
an empty line), any compspec defined with the -E option to complete is used.
If the command word is a full pathname, a compspec for the full pathname is searched
for first. If no compspec is found for the full pathname, an attempt is made to find
a compspec for the portion following the final slash. If those searches do not result
in a compspec, any compspec defined with the -D option to complete is used as the default.”

That is, the difference between “./xbps-src” and “xbps-src” is the first one processing first in the “complete” command.

Second, in my variant you can install xbps-src script into your $PATH and work with different sets of etc/ and common/ dirs. I don’t like to work with “git branch” style in that case (in the future i want to patch xbps-src for unbind from current dir).

Of course, i don’t force you for using my variant, but my one is more general.