Skip to content

feat: add xsel fallback; implement program_exists via PATH search; - #5

Merged
trethore merged 1 commit into
mainfrom
xsel-support
Dec 8, 2025
Merged

feat: add xsel fallback; implement program_exists via PATH search;#5
trethore merged 1 commit into
mainfrom
xsel-support

Conversation

@trethore

Copy link
Copy Markdown
Owner

Some recap v2.1 features:

  • j'ajouterais aussi le support pour xsel sur linux. moi j'ai xsel mais pas xclip
  • mettre les commandes platform-specific de copy_file_content_to_clipboard dans des macros pour pouvoir revenir dessus facilement

@trethore
trethore requested a review from Copilot September 27, 2025 11:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds xsel as a fallback clipboard utility for Linux systems and implements a proper PATH-based program existence check. The changes enhance clipboard functionality robustness by supporting multiple clipboard utilities and improving the detection mechanism.

  • Added program_exists() function that searches PATH directories for executable programs
  • Enhanced Linux clipboard support with xsel as an alternative to xclip
  • Updated documentation to reflect the new xsel support

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/utils.c Implements program_exists() function and refactors clipboard logic to support xclip, xsel, and wl-copy with proper fallback handling
src/recap.h Adds function declaration for program_exists()
README.md Updates documentation to mention xsel as an alternative X11 clipboard utility

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/utils.c
result = system(command);
if (result != 0) {
fprintf(stderr, "Warning: 'wl-copy' command failed. Is 'wl-clipboard' installed?\n");
if (!getenv("WAYLAND_DISPLAY")) {

Copilot AI Sep 27, 2025

Copy link

Choose a reason for hiding this comment

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

The logic is inverted. This condition should check if (getenv("WAYLAND_DISPLAY")) to handle Wayland environments, or the X11 and Wayland blocks should be swapped. Currently, X11 clipboard utilities are being used when WAYLAND_DISPLAY is NOT set, which is backwards.

Copilot uses AI. Check for mistakes.
Comment thread src/utils.c
char* dir = strtok_r(paths, ":", &saveptr);
while (dir) {
char candidate[MAX_PATH_SIZE];
snprintf(candidate, sizeof(candidate), "%s/%s", dir, name);

Copilot AI Sep 27, 2025

Copy link

Choose a reason for hiding this comment

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

Potential buffer overflow if the combined path length exceeds MAX_PATH_SIZE. Consider checking the length of dir and name before concatenation, or use a safer approach like asprintf() for dynamic allocation.

Suggested change
snprintf(candidate, sizeof(candidate), "%s/%s", dir, name);
int n = snprintf(candidate, sizeof(candidate), "%s/%s", dir, name);
if (n < 0 || (size_t)n >= sizeof(candidate)) {
// Path too long, skip this entry
dir = strtok_r(NULL, ":", &saveptr);
continue;
}

Copilot uses AI. Check for mistakes.
Comment thread src/utils.c
Comment on lines +239 to +247
else if (program_exists("wl-copy")) {
snprintf(command, sizeof(command), "cat \"%s\" | wl-copy", filepath);
result = system(command);
if (result != 0) {
fprintf(stderr, "Warning: 'wl-copy' command failed.\n");
}
}
else {
fprintf(stderr, "Error: No clipboard utility found. Install 'xclip', 'xsel', or 'wl-clipboard'.\n");

Copilot AI Sep 27, 2025

Copy link

Choose a reason for hiding this comment

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

In the X11 block (when WAYLAND_DISPLAY is not set), checking for wl-copy as a fallback is illogical. Wayland utilities should not be used in X11 environments. Consider removing this check or moving it to the appropriate context.

Copilot uses AI. Check for mistakes.
@trethore
trethore merged commit 93a67da into main Dec 8, 2025
2 checks passed
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.

3 participants