-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
When using fish completions with a cobra.Command.ValidArgsFunction to specify custom completions, leading ~s and environment variables are not expanded before the argument to complete is passed to the ValidArgsFunction.
For example, if the user types the following to trigger shell completion:
$ command arg ~/.z<tab>ValidArgsFunction is called with the toComplete argument equal to ~/.z. The tilde expansion should be done before this, i.e. the toComplete argument should be /home/user/.z where /home/user is the user's home directory.
Similarly, if the user types:
$ command arg $SOME_VAR/.zthen ValidArgsFunction is called with the toComplete argument equal to $SOME_VAR/.z. Instead, toComplete should have the value with $SOME_VAR expanded.
This is different to other shell completions (e.g. zsh), where ~ and environment variables are expanded by the shell before being passed to ValidArgsFunction.
The expansion of ~ and environment variables must be done in the fish shell itself. It cannot be done by the ValidArgsFunction because:
- The value of environment variables might not be known. For example, if
toCompletecontains an unexported environment variable then its value is not available to the process executingValidArgsFunction. - The exact interpretation of
~depends on the shell. Example common interpretations include~for the user's home directory,~/filefor a file in the user's home directory,~usernamefor a different user's home directory, and~username/filefor a file in a different user's home directory. It is unreasonable for theValidArgsFunctionto emulate fish's behavior exactly. - As the fish completions behave differently to other shell completions, implementing fish's logic in
ValidArgsFunctionwould break other shell completions.