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
50
51
52
53
54
55
56
57
58
59
60
'use strict';
const path = require('path');
const execa = require('execa');
const handler = error => {
if (error.code === 'ENOENT') {
throw new Error('Couldn\'t find the required `xsel` binary. On Debian/Ubuntu you can install it with: sudo apt install xsel');
}
throw error;
};
const xsel = path.join(__dirname, '../fallbacks/linux/xsel');
module.exports = {
copy: async options => {
try {
await execa(xsel, ['--clipboard', '--input'], options);
} catch (_) {
try {
await execa('xsel', ['--clipboard', '--input'], options);
} catch (error) {
handler(error);
}
}
},
paste: async options => {
try {
return await execa.stdout(xsel, ['--clipboard', '--output'], options);
} catch (_) {
try {
return await execa.stdout('xsel', ['--clipboard', '--output'], options);
} catch (error) {
handler(error);
}
}
},
copySync: options => {
try {
execa.sync(xsel, ['--clipboard', '--input'], options);
} catch (_) {
try {
execa.sync('xsel', ['--clipboard', '--input'], options);
} catch (error) {
handler(error);
}
}
},
pasteSync: options => {
try {
return execa.sync(xsel, ['--clipboard', '--output'], options);
} catch (_) {
try {
return execa.sync('xsel', ['--clipboard', '--output'], options);
} catch (error) {
handler(error);
}
}
}
};