git-show-link 1.0.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/package.json +15 -0
- package/src/app/index.js +61 -0
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "git-show-link",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Get clickable HTTPS commit links from SSH remotes",
|
|
5
|
+
"main": "src/app/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"git-show-link": "./src/app/index.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
12
|
+
},
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC"
|
|
15
|
+
}
|
package/src/app/index.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { execSync } from 'child_process';
|
|
3
|
+
|
|
4
|
+
try {
|
|
5
|
+
const args = process.argv.slice(2);
|
|
6
|
+
|
|
7
|
+
let targetCommit = null;
|
|
8
|
+
let isCommitLink = false;
|
|
9
|
+
let shouldOpen = false;
|
|
10
|
+
|
|
11
|
+
if (args.includes('-C') || args.includes('--commit')) {
|
|
12
|
+
targetCommit = 'HEAD';
|
|
13
|
+
isCommitLink = true;
|
|
14
|
+
} else if (args.includes('-c')) {
|
|
15
|
+
const cIndex = args.indexOf('-c');
|
|
16
|
+
targetCommit = args[cIndex + 1];
|
|
17
|
+
|
|
18
|
+
if (!targetCommit || targetCommit.startsWith('-')) {
|
|
19
|
+
console.error("\nError: Please specify the commit hash after -c (e.g. git show-link -c a1b2c3d)\n");
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
isCommitLink = true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (args.includes('-o') || args.includes('--open')){
|
|
26
|
+
shouldOpen = true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const remoteUrl = execSync('git config --get remote.origin.url').toString().trim();
|
|
30
|
+
|
|
31
|
+
let httpsUrl = remoteUrl;
|
|
32
|
+
if (remoteUrl.startsWith('git@')) {
|
|
33
|
+
httpsUrl = remoteUrl.replace(':', '/').replace('git@', 'https://');
|
|
34
|
+
}
|
|
35
|
+
httpsUrl = httpsUrl.replace(/\.git$/, '');
|
|
36
|
+
|
|
37
|
+
let finalLink = httpsUrl;
|
|
38
|
+
|
|
39
|
+
if (isCommitLink) {
|
|
40
|
+
const hash = execSync(`git rev-parse ${targetCommit}`).toString().trim();
|
|
41
|
+
finalLink = `${httpsUrl}/commit/${hash}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
console.log(`\nLink: \x1b[36m\x1b[4m${finalLink}\x1b[0m\n`);
|
|
45
|
+
|
|
46
|
+
if (shouldOpen) {
|
|
47
|
+
const os = process.platform;
|
|
48
|
+
if (os === 'darwin') {
|
|
49
|
+
execSync(`open "${finalLink}"`);
|
|
50
|
+
} else if (os === 'win32') {
|
|
51
|
+
execSync(`start "" "${finalLink}"`);
|
|
52
|
+
} else {
|
|
53
|
+
execSync(`xdg-open "${finalLink}"`);
|
|
54
|
+
}
|
|
55
|
+
console.log('Opened in browser!\n');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error("\nError: Please make sure you are in a Git repository, have a remote configured, or typed the correct commit hash.\n");
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|