Hi
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.
_______________________________________________
Fish-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fish-users