diff --git a/README.md b/README.md index 275ae1b..2e819b9 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,8 @@ Example use case: - Aggregate and view the contents of multiple files or directories in one command. - Automatically copy the aggregated result to the clipboard for seamless integration with other tools or platforms. +- Export your codebase to a markdown document. +- Export your codebase to a typst document. ## Dependencies @@ -42,14 +44,21 @@ The binary will be placed in your $GOPATH/bin directory. Ensure $GOPATH/bin is i ## Example Usage -Concatenate files and directories: +### Concatenate files and directories: ```bash -./pat file1.txt folder/ +pat file1.txt folder/ ``` Output is printed to the terminal and copied to the clipboard, allowing you to paste it elsewhere. +### Create printed + +```sh + +pat -t -i .gitignore . | typst compile /dev/stdin pat.pdf +``` + --- #### Notes diff --git a/pat b/pat new file mode 100755 index 0000000..a4d4e67 Binary files /dev/null and b/pat differ diff --git a/pkg/cat/read.go b/pkg/cat/read.go index d7cc735..10ea669 100644 --- a/pkg/cat/read.go +++ b/pkg/cat/read.go @@ -6,17 +6,9 @@ import ( "os" "path" "strings" + "unicode/utf8" ) -var INVALID_SUFFIXES = []string{ - "png", - "jpg", - "jpeg", - "webp", - "ico", - "ttf", -} - func (c Cater) dir(dir string) (e entry, err error) { files, err := os.ReadDir(dir) if err != nil { @@ -36,10 +28,6 @@ func (c Cater) dir(dir string) (e entry, err error) { var ent entry if !file.IsDir() { - if !validSuffix(file.Name()) { - continue - } - ent, err = c.file(path) } else { ent, err = c.dir(path) @@ -59,6 +47,10 @@ func (c Cater) file(filePath string) (e entry, err error) { } defer file.Close() + e.fqname = filePath + e.name = name(filePath) + e.children = []entry{} + // read file into strings.Builder var sb strings.Builder reader := bufio.NewReader(file) @@ -68,16 +60,17 @@ func (c Cater) file(filePath string) (e entry, err error) { if err != nil && err != io.EOF { return e, err } + if !utf8.Valid([]byte(line)) { + e.content = "blob\n" + return e, nil + } sb.WriteString(line) if err == io.EOF { break } } - e.fqname = filePath - e.name = name(filePath) e.content = sb.String() - e.children = []entry{} return } @@ -86,12 +79,3 @@ func name(name string) string { ps := strings.Split(name, "/") return ps[len(ps)-1] } - -func validSuffix(name string) bool { - for _, s := range INVALID_SUFFIXES { - if strings.HasSuffix(name, s) { - return false - } - } - return true -}