1

I'm working on a completion script for a command, and I'm stuck. The docs and various websites I find don't fit what I need. The main command is pacstall and it has the flags: -I -S -R -C -U -V -L -Up -Qd -Qi. For most of the flags, I need the completions to be the output of a command (if I ran pacstall -I, then tabbed, it would show the output of the command curl -s $(cat /usr/share/pacstall/repo/pacstallrepo.txt)/packagelist. This is what I have so far:

set -l pacstall_commands "-I -S -R -C -U -V -L -Up -Qd -Qi"
complete -f --command pacstall -n "not __fish_seen_subcommand_from $pacstall_commands" -a -I -d 'Install package'
complete -f --command pacstall -n "not __fish_seen_subcommand_from $pacstall_commands" -a -S -d 'Search for package'
complete -f --command pacstall -n "not __fish_seen_subcommand_from $pacstall_commands" -a -R -d 'Remove package'
complete -f --command pacstall -n "not __fish_seen_subcommand_from $pacstall_commands" -a -C -d 'Change repository'
complete -f --command pacstall -n "not __fish_seen_subcommand_from $pacstall_commands" -a -U -d 'Update pacstall scripts'
complete -f --command pacstall -n "not __fish_seen_subcommand_from $pacstall_commands" -a -V -d 'Print pacstall version'
complete -f --command pacstall -n "not __fish_seen_subcommand_from $pacstall_commands" -a -L -d 'List packages installed'
complete -f --command pacstall -n "not __fish_seen_subcommand_from $pacstall_commands" -a -Up -d 'Upgrade packages'
complete -f --command pacstall -n "not __fish_seen_subcommand_from $pacstall_commands" -a -Qd -d 'Query the dependencies of a package'
complete -f --command pacstall -n "not __fish_seen_subcommand_from $pacstall_commands" -a -Qi -d 'Get package info'

Also the script keeps tab completing even after typing in the flag

3
  • Please edit your question and give us some details. What do you have so far? What works? What doesn't work? How does it fail? Also, this is probably not very relevant, but you never know, so please also tell us what operating system you are running.
    – terdon
    May 21, 2021 at 22:24
  • What is the question? Please edit your question and tell us what the problem is. May 22, 2021 at 1:46
  • I did: ` I need the completions to be the output of a command (if I ran pacstall -I, then tabbed, it would show the output of the command curl -s $(cat /usr/share/pacstall/repo/pacstallrepo.txt)/packagelist`
    – Plasma
    May 22, 2021 at 1:55

1 Answer 1

2

The -n flag of the complete command allows you to specify a condition for the completion to occur. In this case, you can use the __fish_seen_subcommand_from function to specify whether the subcommand -I has been seen already.

After this, you can specify with the -a flag the command you want to run in ().

complete -f --command pacstall -n "__fish_seen_subcommand_from -I" -a "(curl -s (cat /usr/share/pacstall/repo/pacstallrepo.txt)/packagelist)"

As a note, in fish, you don't use the $ symbol when capturing the result of a command as you posted in your question.

As for your final point at the end. If you remove the quotes from the set, that should solve the issue of the duplicates. By using quotes in that fashion, it specifies one long command rather than separate ones.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .