Thursday, April 18, 2024
29
rated 0 times [  29] [ 0]  / answers: 1 / hits: 27667  / 3 Years ago, tue, june 15, 2021, 1:15:39

While running the complete command on my gnome-terminal, it shows some commands.What are they? And what is the use of complete command?



$ complete
complete -F _minimal
complete -F _filedir_xspec oodraw
complete -F _filedir_xspec elinks
complete -F _filedir_xspec freeamp
complete -F _longopt split
complete -F _longopt sed
complete -F _longopt ld
complete -F _longopt grep
complete -F _service /etc/init.d/vboxweb-service
complete -F _service /etc/init.d/vboxballoonctrl-service
complete -F _service /etc/init.d/rc
complete -F _service /etc/init.d/nmbd
complete -F _service /etc/init.d/halt
complete -j -P '"%' -S '"' jobs
complete -d pushd


List goes long, so i posted some of the them.


More From » command-line

 Answers
3

complete is a bash builtin function. So there is not a binary on the system. It handles how commands will be completed when pressing tab.



Example: if you type:



user@host:~$ pidof <tab><tab>


...a list is appearing with all possible values for this command. In this case it means all running processes. See the output of the complete function:



user@host:~$ complete | grep pidof
complete -F _pgrep pidof


This means that the function _pgrep (-F) is executed when tabbing the command pidof. The definition of this function is in /etc/bash_completion.d/procps.



Another example: if you type:



user@host:~$ cd /usr/<tab><tab>
bin/ games/ include/ lib/ lib32/ local/ sbin/ share/ src/


...you see the list of folders you can cd to under /usr/. Which function is executed? greping the complete function (as above) tells us it's the funtction _cd in /etc/bash_completion.



Do it yourself: You have a program/script called /bin/myprog and you want that if you execute it as follows



user@host:~$ myprog /home/user/<tab><tab>


...it should only list folders, not files. So extend your bash completion with the following command:



user@host:~$ complete -F _cd myprog


That's it. You can also write own functions to complete custom things, for example complete only specific files or numbers or lists of static values...


[#26202] Wednesday, June 16, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
damomnning

Total Points: 422
Total Questions: 90
Total Answers: 106

Location: Mali
Member since Thu, Aug 13, 2020
4 Years ago
;