-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support comments within FZF_DEFAULT_OPTS_FILE content #3961
Comments
Then we can diff --git a/src/options.go b/src/options.go
index 1593d6f..450ce38 100644
--- a/src/options.go
+++ b/src/options.go
@@ -2915,6 +2915,12 @@ func postProcessOptions(opts *Options) error {
return processScheme(opts)
}
+func parse(str string) ([]string, error) {
+ parser := shellwords.NewParser()
+ parser.ParseComment = true
+ return parser.Parse(str)
+}
+
// ParseOptions parses command-line options
func ParseOptions(useDefaults bool, args []string) (*Options, error) {
opts := defaultOptions()
@@ -2928,7 +2934,7 @@ func ParseOptions(useDefaults bool, args []string) (*Options, error) {
return nil, errors.New("$FZF_DEFAULT_OPTS_FILE: " + err.Error())
}
- words, parseErr := shellwords.Parse(string(bytes))
+ words, parseErr := parse(string(bytes))
if parseErr != nil {
return nil, errors.New(path + ": " + parseErr.Error())
}
@@ -2940,7 +2946,7 @@ func ParseOptions(useDefaults bool, args []string) (*Options, error) {
}
// 2. Options from $FZF_DEFAULT_OPTS string
- words, parseErr := shellwords.Parse(os.Getenv("FZF_DEFAULT_OPTS"))
+ words, parseErr := parse(os.Getenv("FZF_DEFAULT_OPTS"))
if parseErr != nil {
return nil, errors.New("$FZF_DEFAULT_OPTS: " + parseErr.Error())
} |
Nice! I did play around with it a bit, and it looks like I was going in the right direction but didn't land on anything solid. |
Hi @junegunn, do you have an idea of when 0.55.0 will be released with these changes? |
In a few days, hopefully. I was hoping to get #3951 sorted out, but we're not making much progress, so 0.55.0 will probably be released without it. |
Sounds good. Thanks for the quick response! |
Checklist
man fzf
)Output of
fzf --version
0.54.3 (af4917d)
OS
Shell
Problem / Steps to reproduce
When defining options via
FZF_DEFAULT_OPTS_FILE
the config parser doesn't support comment strings,resulting in an
invalid command line string
error.Example fzf config:
FZF_DEFAULT_OPTS_FILE="~/.config/fzf/config"
While the typical use of
FZF_DEFAULT_OPTS
doesn't easily support comments in this fashion do to how string work within shell scripts, I sort of just assumed this would work in the config file because other tools with a similar configuration format such as ripgrep do support comments within the file's contents?Example ripgrep config:
I'm not all that familiar with Golang, but after messing around with it a bit, I managed to add a basic sanitization step before the file content is sent to the options parser.
You can find the PR here: #3960
This seems like an easy enough addition, but if the implementation isn't ideal, I'd love to learn about it, thanks!
The text was updated successfully, but these errors were encountered: