-
-
Notifications
You must be signed in to change notification settings - Fork 603
Expand file tree
/
Copy pathtest_copy_command.c
More file actions
49 lines (41 loc) · 1.48 KB
/
Copy pathtest_copy_command.c
File metadata and controls
49 lines (41 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
// Test the copy command logic without htop dependencies
void test_copyCommand(const char* command) {
if (!command) return;
char copyCmd[1024];
bool success = false;
printf("Testing copy for command: %s\n", command);
#ifdef __APPLE__
snprintf(copyCmd, sizeof(copyCmd), "printf '%%s' '%s' | pbcopy", command);
printf("macOS command: %s\n", copyCmd);
success = (system(copyCmd) == 0);
#elif defined(__linux__) || defined(__unix__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
snprintf(copyCmd, sizeof(copyCmd), "printf '%%s' '%s' | xclip -selection clipboard 2>/dev/null", command);
printf("Linux command (xclip): %s\n", copyCmd);
if (system(copyCmd) != 0) {
snprintf(copyCmd, sizeof(copyCmd), "printf '%%s' '%s' | xsel --clipboard 2>/dev/null", command);
printf("Linux command (xsel): %s\n", copyCmd);
success = (system(copyCmd) == 0);
} else {
success = true;
}
#endif
if (success) {
printf("✅ Command copied to clipboard\n");
} else {
printf("❌ Copy failed - clipboard not available\n");
}
printf("\n");
}
int main() {
printf("Testing copy command functionality...\n\n");
// Test various command types
test_copyCommand("/usr/bin/vim /etc/hosts");
test_copyCommand("python3 -m http.server 8000");
test_copyCommand("htop");
test_copyCommand("ls -la /home/user");
return 0;
}