picosh 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/bin/cli.js +6 -0
- package/index.js +59 -0
- package/package.json +12 -0
- package/scripts/postinstall.js +32 -0
- package/scripts/preuninstall.js +25 -0
- package/target/ignore_this.js +6 -0
- package/target/renderer/bundle.js +6 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Vercel, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/bin/cli.js
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
|
|
7
|
+
const SAVE_DIR = path.join(os.tmpdir(), 'picosh');
|
|
8
|
+
|
|
9
|
+
function saveClipboardImage(clipboard) {
|
|
10
|
+
const img = clipboard.readImage();
|
|
11
|
+
if (img.isEmpty()) return null;
|
|
12
|
+
|
|
13
|
+
fs.mkdirSync(SAVE_DIR, {recursive: true});
|
|
14
|
+
const filepath = path.join(SAVE_DIR, `clip_${Date.now()}.png`);
|
|
15
|
+
fs.writeFileSync(filepath, img.toPNG());
|
|
16
|
+
return filepath;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exports.middleware = (store) => (next) => (action) => {
|
|
20
|
+
if (action.type === 'SESSION_PTY_DATA') {
|
|
21
|
+
return next(action);
|
|
22
|
+
}
|
|
23
|
+
return next(action);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
exports.decorateTerm = (Term, {React, notify}) => {
|
|
27
|
+
return class extends React.Component {
|
|
28
|
+
constructor(props) {
|
|
29
|
+
super(props);
|
|
30
|
+
this._handleKeyDown = this._handleKeyDown.bind(this);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
_handleKeyDown(e) {
|
|
34
|
+
const isCtrlV = (e.ctrlKey || e.metaKey) && e.key === 'v';
|
|
35
|
+
if (!isCtrlV) return;
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const {clipboard} = require('electron');
|
|
39
|
+
const filepath = saveClipboardImage(clipboard);
|
|
40
|
+
if (!filepath) return;
|
|
41
|
+
|
|
42
|
+
e.preventDefault();
|
|
43
|
+
e.stopPropagation();
|
|
44
|
+
|
|
45
|
+
if (this.props.onData) {
|
|
46
|
+
this.props.onData(filepath);
|
|
47
|
+
}
|
|
48
|
+
} catch (err) {
|
|
49
|
+
// clipboard had no image, let default paste happen
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
render() {
|
|
54
|
+
return React.createElement(Term, Object.assign({}, this.props, {
|
|
55
|
+
onKeyDown: this._handleKeyDown,
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "picosh",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Hyper plugin: paste clipboard images as file paths",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": ["hyper", "hyper-plugin"],
|
|
8
|
+
"scripts": {
|
|
9
|
+
"postinstall": "node scripts/postinstall.js",
|
|
10
|
+
"preuninstall": "node scripts/preuninstall.js"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {execSync} = require('child_process');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
|
|
8
|
+
const HYPER_CLI_PATHS = [
|
|
9
|
+
path.join(os.homedir(), 'AppData', 'Local', 'Programs', 'Hyper', 'resources', 'bin', 'hyper.cmd'),
|
|
10
|
+
'/Applications/Hyper.app/Contents/Resources/bin/hyper',
|
|
11
|
+
'/usr/local/bin/hyper',
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
function findHyperCli() {
|
|
15
|
+
return HYPER_CLI_PATHS.find((p) => fs.existsSync(p));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const cli = findHyperCli();
|
|
19
|
+
|
|
20
|
+
if (!cli) {
|
|
21
|
+
console.log('[picosh] Hyper not found. Install Hyper first: https://hyper.is');
|
|
22
|
+
console.log('[picosh] Then run: hyper i picosh');
|
|
23
|
+
process.exit(0);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
console.log('[picosh] Registering plugin with Hyper...');
|
|
28
|
+
execSync(`"${cli}" i picosh`, {stdio: 'inherit'});
|
|
29
|
+
console.log('[picosh] Done! Restart Hyper to activate.');
|
|
30
|
+
} catch (e) {
|
|
31
|
+
console.log('[picosh] Could not auto-register. Run manually: hyper i picosh');
|
|
32
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {execSync} = require('child_process');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
|
|
8
|
+
const HYPER_CLI_PATHS = [
|
|
9
|
+
path.join(os.homedir(), 'AppData', 'Local', 'Programs', 'Hyper', 'resources', 'bin', 'hyper.cmd'),
|
|
10
|
+
'/Applications/Hyper.app/Contents/Resources/bin/hyper',
|
|
11
|
+
'/usr/local/bin/hyper',
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
function findHyperCli() {
|
|
15
|
+
return HYPER_CLI_PATHS.find((p) => fs.existsSync(p));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const cli = findHyperCli();
|
|
19
|
+
if (!cli) process.exit(0);
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
execSync(`"${cli}" u picosh`, {stdio: 'inherit'});
|
|
23
|
+
} catch (e) {
|
|
24
|
+
// ignore
|
|
25
|
+
}
|