On Wed, Mar 6, 2019 at 3:05 PM David Adam <zanc...@ucc.gu.uwa.edu.au> wrote: > > On Sun, 3 Mar 2019, SanskritFritz wrote: > > I'm writing completions for borg. > > There is a special case where I want to achieve the following: > > Fish should give a second archive list when the following scenario is > > present (the cursor is now at the end of the line after a space): > > borg diff repo::archive1 > > yielding this: > > borg diff repo::archive1 archive2 > > I have found a solution with this code (with some debugging help as > > well for now): > > > > function __fish_borg_is_diff_second_archive > > echo (commandline) >> ~/temp/debug.txt > > return (string match --regex ' diff .*::[^ ]+ '(commandline > > --current-token) '"'(commandline)'"' >> ~/temp/debug.txt) > > end > > complete -c borg -f -n __fish_borg_is_diff_second_archive -a 'archive1 > > archive2 archive3' > > > > This works well, with one little problem, particularly that after > > borg diff repo::archive1 archive2 > > pressing tab again lists the archives which I don't want. The reason > > is that the regexp still matches the commandline. So I thought I try > > to modify the regexp like this: > > > > function __fish_borg_is_diff_second_archive > > echo (commandline) >> ~/temp/debug.txt > > return (string match --regex ' diff .*::[^ ]+ '(commandline > > --current-token)'$' '"'(commandline)'"' >> ~/temp/debug.txt) > > end > > > > The only difference to the previous one is the '$' after the > > --current-token. With that I want to achieve a more strict matching. > > However this somehow doesn't match even the second archive, I have no > > idea why. Issuing the following in the shell actually works well (this > > is how I try to test the matching part): > > > > ~> string match --regex ' .*::[^ ]+ ''$' "borg diff repo::archive1 " > > diff repo::archive1 > > ~> string match --regex ' .*::[^ ]+ 'archi'$' "borg diff repo::archive1 > > archi" > > diff repo::archive1 archi > > ~> string match --regex ' .*::[^ ]+ ''$' "borg diff repo::archive1 archive2 > > " > > ~> echo $status > > 1 > > > > Now I don't know what is going on and I need your help please. > > Hi SanskritFritz, > > I asked our resident completions expert, faho@, and he has suggested the > following: > > `'"'(commandline)'"'` is wrong. There's no need to add quotes, and that > last quote will make it so `$` isn't directly after the current token > anymore.
Hi and thanks for your answer. Indeed this way it works, but I don't understand why, because when I test that expression this works: string match --regex ' diff .*::[^ ]+ 'aaa'$' "borg diff ::aaa aaa" and this doesn't because (commandline) can contain spaces: string match --regex ' diff .*::[^ ]+ 'aaa'$' borg diff ::aaa aaa May I contact faho@ on github or is he reading this as well? _______________________________________________ Fish-users mailing list Fish-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/fish-users