-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·34 lines (31 loc) · 1.02 KB
/
index.js
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
#!/usr/bin/env node
const { execSync } = require("child_process");
const os = require("os");
function copyToClipboard(text) {
const platform = os.platform();
try {
if (platform === "win32") {
execSync(`echo ${text} | clip`);
} else if (platform === "darwin") {
execSync(`echo "${text}" | pbcopy`);
} else if (platform === "linux") {
if (execSync("command -v xclip").toString().trim()) {
execSync(`echo "${text}" | xclip -selection clipboard`);
} else if (execSync("command -v xsel").toString().trim()) {
execSync(`echo "${text}" | xsel --clipboard --input`);
} else {
console.error(
"Clipboard tool not found. Please install xclip or xsel."
);
process.exit(1);
}
} else {
console.error(`Unsupported platform: ${platform}`);
process.exit(1);
}
} catch (error) {
console.error("Error copying to clipboard:", error);
}
}
copyToClipboard(process.cwd());
console.log(`Directory ${process.cwd()} copied to clipboard.`);