Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I would like to discuss exclude and clipboad. #31

Open
yasainet opened this issue Jul 8, 2024 · 12 comments
Open

I would like to discuss exclude and clipboad. #31

yasainet opened this issue Jul 8, 2024 · 12 comments
Assignees

Comments

@yasainet
Copy link

yasainet commented Jul 8, 2024

Basically, I am a Mac developer. However, I sometimes develop on Ubuntu with Windows WSL2 due to circumstances.

I can use Mac without any problem, but in WSL2 environment, the following commands do not work as expected.

1.code2prompt /home/USER/PJ --exclude="**/package-lock.json"

The purpose is to exclude package-lock.json existing in PJ/server, PJ/client, etc.
However, the output result includes the contents of package-lock.json.
Is there a way to properly use --exclude?

  1. code2prompt /home/USER/PJ

I am expecting the output results to be saved to the clipboard as a result of running this command, but sometimes they are not.
So, I use the following command every time.
code2prompt /home/USER/PJ --ouput /home/USER/PJ/output.txt.

It accomplishes the purpose, but it is better to be saved to the clipboard.

Can you give me some advice on how to solve this problem?


P.S.
Very nice app, can't develop anymore without it! I look forward to more in the future.

Translated with DeepL.com (free version)

@yspmymt
Copy link

yspmymt commented Jul 8, 2024

Same!
I have to delete the code myself every time to pass it to the AI, but it is quite difficult.

@ODAncona
Copy link
Collaborator

ODAncona commented Jul 9, 2024

How the Glob Pattern Tool Works

The tool uses glob patterns to include or exclude files and directories, and works similarly to tools like tree or grep. Here’s a detailed explanation:

Key Concepts

  1. Include List ($\mathbf{A}$): A set containing the glob patterns for files and directories you want to include.
  2. Exclude List ($\mathbf{B}$): A set containing the glob patterns for files and directories you want to exclude.
  3. Universe ($\mathbf{\Omega}$): The set of all files and directories.

When you specify an --exclude list and/or an --include list, the following logic applies:

  • $\neg A \cap \neg B$: No include list, no exclude list $\rightarrow$ Include everything: $\mathbf{\Omega}$
  • $\neg A \cap B$: No include list, with exclude list $\rightarrow$ Include everything except what matches the exclude list: $\mathbf{\Omega} \setminus \mathbf{B}$
  • $A \cap \neg B$: With include list, no exclude list $\rightarrow$ Include only what matches the include list: $\mathbf{A}$
  • $A \cap B$: With include list and exclude list $\rightarrow$ Include what matches the include list, exclude what matches the exclude list. Decide what to do with the intersection based on the include_priority parameter:
    • Include: $\mathbf{A} \setminus (\mathbf{A} \cap \mathbf{B})$
    • Exclude: $\mathbf{B} \setminus (\mathbf{A} \cap \mathbf{B})$

Here’s a visual representation of the last case:

Venn Diagram

Question 1

In your case, the command is indeed correct code2prompt <pathtoyourcodebase> --exclude "**/package.json"
It can still appear in the directory tree, if you don't want it you can use the flag --exclude-from-tree. I tried on my own on some JS project and it's working fine.

Question 2

Code2prompt use the ARboard crate for managing the clipboard. You should go check whether this package is working in WSL. Otherwise, I suggest to use the no-clipboard option with the -o (--output) flag to dump your codebase into a file. You can take a look at the PR #26 or #30.

@yasainet
Copy link
Author

@somas1

Read code2prompt --help

  -e, --exclude <EXCLUDE>.
          Optional comma-separated list of file extensions to exclude

      --exclude-files <EXCLUDE_FILES>
          Optional comma-separated list of file names to exclude

      --exclude-folders <EXCLUDE_FOLDERS>
          Optional comma-separated list of folder paths to exclude

      --tokens
          Display the token count of the generated prompt.

This option may solve your problem!

@yasainet
Copy link
Author

If --help is different, run --version.
The behavior of the command may be slightly different depending on the version.

@gretel
Copy link

gretel commented Jul 12, 2024

am trying to exclude a couple of files matching by extension and i don't get it to work with none of the available parameters. lastly, tried

code2prompt --filter html,log,json,scss,handlebars .

and a couple of more combinations just to find the excluded/filterered files included in any case 😞

@yasainet
Copy link
Author

using glob patterns🥳

How about asking ChatGPT the following?

  • Please exclude the following extensions from the grob pattern
  • .html, .log...

You can apply this method to do many things!

@gretel
Copy link

gretel commented Jul 13, 2024

talking to me like i am stupid while not posting the answer you seem to know?

@y00njaekim
Copy link

@gretel To exclude specific file extensions, you can use the --exclude option followed by a comma-separated list of extensions without the glob pattern. For excluding files with specific filenames, you can use the --exclude-files option. Here's an example that demonstrates both:

code2prompt . --exclude="kts,xml,json,bat,properties,pro" --exclude-files="gradlew"

This command will exclude files with the extensions .kts, .xml, .json, .bat, .properties, and .pro, as well as any file named "gradlew". This approach provides a clear and straightforward way to specify exclusions without relying on glob patterns.

@yasainet
Copy link
Author

I am Japanese and my English is not good.
I am sorry for my comment, I thought it might be useful for you.

Please understand that I write all my comments using DeepL translation.

Also, asking ChatGPT is very effective and I really encourage you to try it.
Because not only will it achieve the purpose of this project, but it will also be useful when new requests come up in the future.

@steelep
Copy link

steelep commented Aug 20, 2024

Nice tool. FYI I too am also seeing the auto copy to the clipboard not working. I have tried both the cargo release and building from the source. (I've tried under $USER and sudo to no avail). I'm running stock Ubuntu 22.04.

@nikbrunner
Copy link

nikbrunner commented Oct 13, 2024

Thank you for this tool! But I also have a problem with the exclude flag.

I have the following Filetree and I can't get the exclude pattern to work, despite following the suggested patterns here and also asking ChatGPT.

app git:main
❯ tree
.
├── README.md
├── context.md
└── src
    ├── backend
    │   ├── deno.json
    │   ├── deno.lock
    │   ├── http
    │   │   ├── add story.bru
    │   │   ├── bruno.json
    │   │   ├── environments
    │   │   │   └── localhost.bru
    │   │   ├── status.bru
    │   │   ├── stories.bru
    │   │   └── story.bru
    │   ├── main.ts
    │   ├── routes
    │   │   ├── status.ts
    │   │   └── stories.ts
    │   ├── server.ts
    │   └── stores
    │       └── stories.ts
    ├── frontend
    │   ├── README.md
    │   ├── deno.lock
    │   ├── eslint.config.js
    │   ├── index.html
    │   ├── node_modules
    │   │   ├── @eslint
    │   │   │   └── js -> ../.deno/@[email protected]/node_modules/@eslint/js
    │   │   ├── @types
    │   │   │   ├── react -> ../.deno/@[email protected]/node_modules/@types/react
    │   │   │   └── react-dom -> ../.deno/@[email protected]/node_modules/@types/react-dom
    │   │   ├── @vitejs
    │   │   │   └── plugin-react -> ../.deno/@[email protected]/node_modules/@vitejs/plugin-react
    │   │   ├── eslint -> .deno/[email protected]/node_modules/eslint
    │   │   ├── eslint-plugin-react-hooks -> .deno/[email protected]/node_modules/eslint-plugin-react-hooks
    │   │   ├── eslint-plugin-react-refresh -> .deno/[email protected]/node_modules/eslint-plugin-react-refresh
    │   │   ├── globals -> .deno/[email protected]/node_modules/globals
    │   │   ├── react -> .deno/[email protected]/node_modules/react
    │   │   ├── react-dom -> .deno/[email protected]/node_modules/react-dom
    │   │   ├── typescript -> .deno/[email protected]/node_modules/typescript
    │   │   ├── typescript-eslint -> .deno/[email protected]/node_modules/typescript-eslint
    │   │   └── vite -> .deno/[email protected]/node_modules/vite
    │   ├── package-lock.json
    │   ├── package.json
    │   ├── public
    │   │   └── vite.svg
    │   ├── src
    │   │   ├── App.css
    │   │   ├── App.tsx
    │   │   ├── assets
    │   │   │   └── react.svg
    │   │   ├── index.css
    │   │   ├── main.tsx
    │   │   └── vite-env.d.ts
    │   ├── tsconfig.app.json
    │   ├── tsconfig.json
    │   ├── tsconfig.node.json
    │   └── vite.config.ts
    └── shared
        └── types
            └── story.ts

30 directories, 33 files

This is the command that I am using:

code2prompt . --exclude="**/deno.lock,**/package-lock.json" --output="context.md"

@ODAncona
Copy link
Collaborator

Hello @nikbrunner,

Thank you to raise this issue. I wasn't able to reproduce your issue. Maybe you omitted the --exclude-from-tree command which is responsible to remove the excluded file from the directory tree ? However, when I tried to reproduce, deno.lock or package.json files content were properly excluded from context.md even though they appear in the directory tree.

I understand this feature is confusing because you don't expect your excluded file to remain in the directory tree. However, it's sometimes practical to keep them in the tree in order to feed extra context...

Can you confirm the files content is properly excluded from context.md ?

Here's the script I used to reproduce your situation:

#!/bin/bash

# Define the directory structure and files
declare -A structure=(
  ["README.md"]="README.md"
  ["context.md"]="context.md"
  ["src/backend/deno.json"]="deno.json"
  ["src/backend/deno.lock"]="deno.lock"
  ["src/backend/http/add story.bru"]="add story.bru"
  ["src/backend/http/bruno.json"]="bruno.json"
  ["src/backend/http/environments/localhost.bru"]="localhost.bru"
  ["src/backend/http/status.bru"]="status.bru"
  ["src/backend/http/stories.bru"]="stories.bru"
  ["src/backend/http/story.bru"]="story.bru"
  ["src/backend/main.ts"]="main.ts"
  ["src/backend/routes/status.ts"]="status.ts"
  ["src/backend/routes/stories.ts"]="stories.ts"
  ["src/backend/server.ts"]="server.ts"
  ["src/backend/stores/stories.ts"]="stories.ts"
  ["src/frontend/README.md"]="README.md"
  ["src/frontend/deno.lock"]="deno.lock"
  ["src/frontend/eslint.config.js"]="eslint.config.js"
  ["src/frontend/index.html"]="index.html"
  ["src/frontend/package-lock.json"]="package-lock.json"
  ["src/frontend/package.json"]="package.json"
  ["src/frontend/public/vite.svg"]="vite.svg"
  ["src/frontend/src/App.css"]="App.css"
  ["src/frontend/src/App.tsx"]="App.tsx"
  ["src/frontend/src/assets/react.svg"]="react.svg"
  ["src/frontend/src/index.css"]="index.css"
  ["src/frontend/src/main.tsx"]="main.tsx"
  ["src/frontend/src/vite-env.d.ts"]="vite-env.d.ts"
  ["src/frontend/tsconfig.app.json"]="tsconfig.app.json"
  ["src/frontend/tsconfig.json"]="tsconfig.json"
  ["src/frontend/tsconfig.node.json"]="tsconfig.node.json"
  ["src/frontend/vite.config.ts"]="vite.config.ts"
  ["src/shared/types/story.ts"]="story.ts"
)

# Create directories and files
for path in "${!structure[@]}"; do
  # Extract the file content
  content="${structure[$path]}"
  
  # Create the directory structure
  mkdir -p "$(dirname "$path")"
  
  # Write the file content
  echo "$content" > "$path"
done

echo "All files and directories have been created successfully!"

@ODAncona ODAncona self-assigned this Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants