mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-15 20:23:50 -07:00
Allow comments in $FZF_DEFAULT_OPTS and $FZF_DEFAULT_OPTS_FILE
Close #3961
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/junegunn/fzf/src/algo"
|
||||
"github.com/junegunn/fzf/src/tui"
|
||||
|
||||
"github.com/mattn/go-shellwords"
|
||||
"github.com/junegunn/go-shellwords"
|
||||
"github.com/rivo/uniseg"
|
||||
)
|
||||
|
||||
@@ -2915,6 +2915,12 @@ func postProcessOptions(opts *Options) error {
|
||||
return processScheme(opts)
|
||||
}
|
||||
|
||||
func parseShellWords(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 := parseShellWords(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 := parseShellWords(os.Getenv("FZF_DEFAULT_OPTS"))
|
||||
if parseErr != nil {
|
||||
return nil, errors.New("$FZF_DEFAULT_OPTS: " + parseErr.Error())
|
||||
}
|
||||
|
Reference in New Issue
Block a user