~kota/dprint

dc9c0f39360e4ecda0a05a42292171366a764563 — Dakota Walsh 1 year, 2 months ago 0354b2e
simplify checkName function
1 files changed, 4 insertions(+), 8 deletions(-)

M main.go
M main.go => main.go +4 -8
@@ 7,7 7,6 @@ import (
	"log"
	"os"
	"path/filepath"
	"regexp"
	"strings"

	"git.sr.ht/~kota/xdg/basedir"


@@ 21,9 20,6 @@ var (
	Config  string
)

// regex to check if the file is a desktop file
var r = regexp.MustCompile(`(?m)(.*)\.desktop`)

// usage prints some basic usage information
func usage() {
	log.Fatal("Usage: dprint [-v] [-d path] [-i key:val] [-o key]")


@@ 104,10 100,10 @@ func setConfig(d string) string {
	return d
}

// cName checks that the file info is a desktop file
func cName(fi os.FileInfo) bool {
// checkName checks that the file info is a desktop file
func checkName(fi os.FileInfo) bool {
	if !fi.IsDir() {
		if r.MatchString(fi.Name()) {
		if filepath.Ext(fi.Name()) == ".desktop" {
			return true
		}
	}


@@ 127,7 123,7 @@ func walk(dir string) ([]desktop.Entry, error) {
	}
	var entries []desktop.Entry
	for _, fi := range infos {
		if cName(fi) {
		if checkName(fi) {
			path := filepath.Join(dir, fi.Name())
			dat, err := os.Open(path)
			if err != nil {