Compare commits
2 Commits
6e63af80a6
...
021ea61c9b
Author | SHA1 | Date | |
---|---|---|---|
021ea61c9b | |||
7f93ae2c20 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
**/__debug_bin*
|
||||
main
|
||||
/pat
|
||||
|
13
README.md
13
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
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user