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

feat: copy to clipboard #234

Merged
merged 5 commits into from
Nov 10, 2024
Merged

Conversation

0xbrayo
Copy link
Collaborator

@0xbrayo 0xbrayo commented Oct 30, 2024

Closes #232

Important

Adds clipboard copy functionality with platform-specific handling, refactors utility functions, and integrates into shell and tmux modules.

  • Clipboard Functionality:
    • Adds set_copytext() and copy() in clipboard.py for clipboard management.
    • Supports Linux (xclip, wl-copy) and macOS (pbcopy).
  • Utility Functions:
    • Moves get_system_distro() and get_installed_programs() to platform_utils.py and util.py.
    • Refactors print_preview() in util.py to support clipboard copying.
  • Integration:
    • Updates execute_shell() in shell.py and execute_tmux() in tmux.py to use print_preview() with clipboard copy option.

This description was created by Ellipsis for 28e11a4. It will automatically update as commits are pushed.

@0xbrayo
Copy link
Collaborator Author

0xbrayo commented Oct 30, 2024

Closes #232

@0xbrayo 0xbrayo requested a review from ErikBjare October 30, 2024 10:46
@0xbrayo
Copy link
Collaborator Author

0xbrayo commented Oct 30, 2024

Experimented with a few approaches, ask_execute does not have access to the cmd variable. Passing it would involve rewriting all instances that confirmFunc is used. This was the simpler way I found to do it. Assumes that the print_preview is always called before ask_execute which is should always be the case. What do you think?

@0xbrayo
Copy link
Collaborator Author

0xbrayo commented Oct 30, 2024

Noticed that other confirmation dialogs such as overwrite file have the "copy" option.

Copy link
Owner

@ErikBjare ErikBjare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, nice workaround with the preview stuff, but some concerns about pyperclip.

pyproject.toml Outdated Show resolved Hide resolved
gptme/util.py Outdated
@@ -131,6 +133,7 @@ def epoch_to_age(epoch):
def print_preview(code: str, lang: str): # pragma: no cover
print()
print("[bold white]Preview[/bold white]")
set_text(code)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't really work for patches, but I guess that's ok for now.

poetry.lock Outdated Show resolved Hide resolved
@0xbrayo
Copy link
Collaborator Author

0xbrayo commented Oct 31, 2024

I will try clipboard instead Also not maintained. Will call the native copy commands directly.

@0xbrayo 0xbrayo force-pushed the copy-to-clipboard branch 4 times, most recently from 7246af7 to e71aaa8 Compare November 1, 2024 07:27
gptme/tools/tmux.py Show resolved Hide resolved
gptme/platform_utils.py Outdated Show resolved Hide resolved
gptme/util.py Outdated Show resolved Hide resolved
gptme/util.py Outdated Show resolved Hide resolved
gptme/util.py Outdated Show resolved Hide resolved
@0xbrayo 0xbrayo marked this pull request as ready for review November 7, 2024 13:08
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Changes requested. Reviewed everything up to f263c5d in 1 minute and 3 seconds

More details
  • Looked at 312 lines of code in 6 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. gptme/util.py:343
  • Draft comment:
    The get_system_distro function is duplicated in multiple files. Consider defining it in one place and importing it where needed to avoid redundancy.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    The comment is speculative as it assumes the function is duplicated without providing evidence. The diff only shows the function being added here, and without evidence of duplication, the comment does not meet the criteria for being kept.
    I might be missing the broader context of the codebase where this function could indeed be duplicated. However, based on the provided information, there's no evidence of duplication.
    The task is to review the diff and comments based on the provided information. Without evidence of duplication in the diff or context, the comment should be removed.
    Remove the comment as it is speculative and not based on evidence from the provided diff or context.
2. gptme/util.py:355
  • Draft comment:
    The get_installed_programs function is duplicated in multiple files. Consider defining it in one place and importing it where needed to avoid redundancy.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    The comment is about a cross-file issue, which is not relevant to the changes made in this diff. The rules specify to ignore cross-file issues and focus only on the file being reviewed. Since there's no evidence of duplication within this file, the comment should be removed.
    I might be missing the context of other files where this function could be duplicated, but the task is to focus only on the current file.
    The rules are clear about ignoring cross-file issues, so the lack of evidence in this file is sufficient to disregard the comment.
    Remove the comment as it pertains to a cross-file issue, which is not relevant to the current diff.
3. gptme/util.py:153
  • Draft comment:
    The print_preview function has been modified to include a copy parameter, but the logic for setting copiable and set_copytext is not clear. Ensure these are only set when necessary.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The print_preview function has been modified to include a copy parameter, but the logic for setting copiable and set_copytext is not clear. It should be ensured that these are only set when necessary.
4. gptme/platform_utils.py:20
  • Draft comment:
    Duplicate function get_installed_programs found in gptme/util.py. Use the existing function instead of adding a new one.

  • function get_installed_programs (util.py)

  • Reason this comment was not posted:
    Marked as duplicate.

Workflow ID: wflow_n5fjgRTZQRD07l0Y


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

gptme/clipboard.py Show resolved Hide resolved
@0xbrayo 0xbrayo requested a review from ErikBjare November 7, 2024 13:12
feat: add copiable variable

fix: update the copystr

refactor: revert to "[c] to copy"

feat: copy to clipboard

refactor: revert to [c] to copy. handle circular import

feat: simplify the input handling.
@0xbrayo
Copy link
Collaborator Author

0xbrayo commented Nov 8, 2024

@ellipsis-dev review

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Changes requested. Reviewed everything up to 28e11a4 in 1 minute and 5 seconds

More details
  • Looked at 200 lines of code in 5 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 drafted comments based on config settings.
1. gptme/clipboard.py:28
  • Draft comment:
    Consider using subprocess.run(..., check=True) to ensure that an exception is raised if the command fails, which can help in debugging and error handling.
  • Reason this comment was not posted:
    Marked as duplicate.
2. gptme/clipboard.py:39
  • Draft comment:
    Consider using subprocess.run(..., check=True) to ensure that an exception is raised if the command fails, which can help in debugging and error handling.
  • Reason this comment was not posted:
    Marked as duplicate.
3. gptme/util.py:357
  • Draft comment:
    The get_installed_programs function is duplicated in shell.py. Consider removing the one in shell.py to avoid redundancy.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The get_installed_programs function in util.py is duplicated in shell.py. The one in shell.py should be removed as it is not used and the one in util.py is more generic and used in clipboard.py.

Workflow ID: wflow_fskQ5vvxcb7pEBGE


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

gptme/clipboard.py Outdated Show resolved Hide resolved
gptme/util.py Show resolved Hide resolved
@0xbrayo
Copy link
Collaborator Author

0xbrayo commented Nov 9, 2024

@ErikBjare ping

Copy link
Owner

@ErikBjare ErikBjare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the remaining ellipsis comments (should fix mypy + lint warnings), looks good otherwise. Haven't actually tested it.

@ErikBjare ErikBjare changed the title feat: Copy to clipboard feat: copy to clipboard Nov 9, 2024
gptme/util.py Outdated Show resolved Hide resolved
0xbrayo and others added 3 commits November 9, 2024 22:20
@ErikBjare ErikBjare merged commit 7ad4c94 into ErikBjare:master Nov 10, 2024
4 of 7 checks passed
@ErikBjare
Copy link
Owner

Nice, merged!

@NikitaBeloglazov
Copy link

NikitaBeloglazov commented Dec 16, 2024

Actually, I don't understand, there is the reason for building something unknown if you could just take clipman (an alternative to pyperclip) which was mentioned above. Or is there something missing?

@ErikBjare
Copy link
Owner

@NikitaBeloglazov There is no "building something unknown", the called executables should exist on their respective platforms.

I don't want to add another dependency for something so simple.

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

Successfully merging this pull request may close these issues.

Copy to clipboard suggested command
3 participants