diff --git a/cmd/zenity/main.go b/cmd/zenity/main.go index 7ce1557..e5b0713 100644 --- a/cmd/zenity/main.go +++ b/cmd/zenity/main.go @@ -240,7 +240,7 @@ func (f *FileFilters) String() string { func (f *FileFilters) Set(s string) error { var filter zenity.FileFilter - if split := strings.SplitN(s, "|", 2); len(split) > 0 { + if split := strings.SplitN(s, "|", 2); len(split) > 1 { filter.Name = split[0] s = split[1] } diff --git a/file_darwin.go b/file_darwin.go index c4850af..f7ba02a 100644 --- a/file_darwin.go +++ b/file_darwin.go @@ -4,6 +4,7 @@ import ( "os/exec" "strings" + "github.com/ncruces/zenity/internal/cmd" "github.com/ncruces/zenity/internal/osa" ) @@ -34,6 +35,7 @@ func SelectFileMutiple(options ...Option) ([]string, error) { Multiple: true, Prompt: opts.title, Location: opts.filename, + Separator: cmd.Separator, Type: appleFilters(opts.filters), }) if err, ok := err.(*exec.ExitError); ok && err.ExitCode() == 1 { @@ -48,7 +50,7 @@ func SelectFileMutiple(options ...Option) ([]string, error) { if len(out) == 0 { return nil, nil } - return strings.Split(string(out), "\x00"), nil + return strings.Split(string(out), cmd.Separator), nil } func SelectFileSave(options ...Option) (string, error) { @@ -93,7 +95,16 @@ func appleFilters(filters []FileFilter) []string { var filter []string for _, f := range filters { for _, p := range f.Patterns { - filter = append(filter, p) // FIXME + star := strings.LastIndexByte(p, '*') + if star >= 0 { + dot := strings.LastIndexByte(p, '.') + if star > dot { + return nil + } + filter = append(filter, p[dot+1:]) + } else { + filter = append(filter, p) + } } } return filter diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index f4809e9..4e9c44e 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -1,4 +1,4 @@ package cmd var Command bool -var Separator string +var Separator = "\x00" diff --git a/internal/osa/osa_darwin.go b/internal/osa/osa_darwin.go index 4ec8240..54a9c82 100644 --- a/internal/osa/osa_darwin.go +++ b/internal/osa/osa_darwin.go @@ -38,9 +38,9 @@ type File struct { Prompt string Name string Location string + Separator string Type []string Multiple bool - Separator rune } type Msg struct { diff --git a/internal/osa/scripts/file.gots b/internal/osa/scripts/file.gots index 475067a..b0430fe 100644 --- a/internal/osa/scripts/file.gots +++ b/internal/osa/scripts/file.gots @@ -18,7 +18,7 @@ opts.multipleSelectionsAllowed = {{.Multiple}} var res = app[{{.Operation}}](opts) if (Array.isArray(res)) { - res.join(String.fromCodePoint({{.Separator}})) + res.join({{.Separator}}) } else { res.toString() } \ No newline at end of file