Compare commits

...

2 Commits

Author SHA1 Message Date
021ea61c9b remove binary 2025-05-16 10:25:29 +02:00
7f93ae2c20 blob detection 2025-05-16 10:21:28 +02:00
3 changed files with 21 additions and 27 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
**/__debug_bin* **/__debug_bin*
main main
/pat

View File

@ -12,6 +12,8 @@ Example use case:
- Aggregate and view the contents of multiple files or directories in one command. - 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. - 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 ## Dependencies
@ -42,14 +44,21 @@ The binary will be placed in your $GOPATH/bin directory. Ensure $GOPATH/bin is i
## Example Usage ## Example Usage
Concatenate files and directories: ### Concatenate files and directories:
```bash ```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. 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 #### Notes

View File

@ -6,17 +6,9 @@ import (
"os" "os"
"path" "path"
"strings" "strings"
"unicode/utf8"
) )
var INVALID_SUFFIXES = []string{
"png",
"jpg",
"jpeg",
"webp",
"ico",
"ttf",
}
func (c Cater) dir(dir string) (e entry, err error) { func (c Cater) dir(dir string) (e entry, err error) {
files, err := os.ReadDir(dir) files, err := os.ReadDir(dir)
if err != nil { if err != nil {
@ -36,10 +28,6 @@ func (c Cater) dir(dir string) (e entry, err error) {
var ent entry var ent entry
if !file.IsDir() { if !file.IsDir() {
if !validSuffix(file.Name()) {
continue
}
ent, err = c.file(path) ent, err = c.file(path)
} else { } else {
ent, err = c.dir(path) ent, err = c.dir(path)
@ -59,6 +47,10 @@ func (c Cater) file(filePath string) (e entry, err error) {
} }
defer file.Close() defer file.Close()
e.fqname = filePath
e.name = name(filePath)
e.children = []entry{}
// read file into strings.Builder // read file into strings.Builder
var sb strings.Builder var sb strings.Builder
reader := bufio.NewReader(file) reader := bufio.NewReader(file)
@ -68,16 +60,17 @@ func (c Cater) file(filePath string) (e entry, err error) {
if err != nil && err != io.EOF { if err != nil && err != io.EOF {
return e, err return e, err
} }
if !utf8.Valid([]byte(line)) {
e.content = "blob\n"
return e, nil
}
sb.WriteString(line) sb.WriteString(line)
if err == io.EOF { if err == io.EOF {
break break
} }
} }
e.fqname = filePath
e.name = name(filePath)
e.content = sb.String() e.content = sb.String()
e.children = []entry{}
return return
} }
@ -86,12 +79,3 @@ func name(name string) string {
ps := strings.Split(name, "/") ps := strings.Split(name, "/")
return ps[len(ps)-1] return ps[len(ps)-1]
} }
func validSuffix(name string) bool {
for _, s := range INVALID_SUFFIXES {
if strings.HasSuffix(name, s) {
return false
}
}
return true
}