@gkalpak/aliases 0.14.0 → 0.14.1
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/bin/config/cfgbash.js +1 -1
- package/bin/config/cfgbash.wsl.js +1 -1
- package/bin/config/cfggit.js +1 -1
- package/bin/config/cfggit.win32.js +1 -1
- package/bin/config/cfggit.wsl.js +1 -1
- package/bin/config/cfggpg.js +1 -1
- package/bin/config/cfgssh.js +1 -1
- package/bin/config/cfgvim.js +1 -1
- package/bin/config/cfgwsl.wsl.js +2 -2
- package/bin/misc/alv.js +1 -1
- package/lib/alias-scripts/g-pick-branch.js +16 -10
- package/lib/alias-scripts/g-pick-commit.js +20 -13
- package/lib/utils.js +21 -16
- package/package.json +3 -3
- package/scripts/platformize-bin.js +9 -12
package/bin/config/cfgbash.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {stripIndentation} from '../../lib/utils.js';
|
|
3
3
|
/* eslint-disable max-len */
|
|
4
4
|
console.log(stripIndentation(`
|
|
5
|
-
### [Generated by: @gkalpak/aliases v0.14.
|
|
5
|
+
### [Generated by: @gkalpak/aliases v0.14.1]
|
|
6
6
|
### Copy the following into '~/.bashrc':
|
|
7
7
|
|
|
8
8
|
# Set up prompt.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {stripIndentation} from '../../lib/utils.js';
|
|
3
3
|
/* eslint-disable max-len */
|
|
4
4
|
console.log(stripIndentation(`
|
|
5
|
-
### [Generated by: @gkalpak/aliases v0.14.
|
|
5
|
+
### [Generated by: @gkalpak/aliases v0.14.1]
|
|
6
6
|
### Copy the following into '~/.bashrc':
|
|
7
7
|
|
|
8
8
|
# Set up prompt.
|
package/bin/config/cfggit.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {stripIndentation} from '../../lib/utils.js';
|
|
3
3
|
console.log(stripIndentation(`
|
|
4
|
-
### [Generated by: @gkalpak/aliases v0.14.
|
|
4
|
+
### [Generated by: @gkalpak/aliases v0.14.1]
|
|
5
5
|
### Run the following commands:
|
|
6
6
|
|
|
7
7
|
git config --global commit.gpgSign "true"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {stripIndentation} from '../../lib/utils.js';
|
|
3
3
|
console.log(stripIndentation(`
|
|
4
|
-
### [Generated by: @gkalpak/aliases v0.14.
|
|
4
|
+
### [Generated by: @gkalpak/aliases v0.14.1]
|
|
5
5
|
### Run the following commands:
|
|
6
6
|
|
|
7
7
|
git config --global commit.gpgSign "true"
|
package/bin/config/cfggit.wsl.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {stripIndentation} from '../../lib/utils.js';
|
|
3
3
|
console.log(stripIndentation(`
|
|
4
|
-
### [Generated by: @gkalpak/aliases v0.14.
|
|
4
|
+
### [Generated by: @gkalpak/aliases v0.14.1]
|
|
5
5
|
### Run the following commands:
|
|
6
6
|
|
|
7
7
|
git config --global commit.gpgSign "true"
|
package/bin/config/cfggpg.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {stripIndentation} from '../../lib/utils.js';
|
|
3
3
|
console.log(stripIndentation(`
|
|
4
|
-
### [Generated by: @gkalpak/aliases v0.14.
|
|
4
|
+
### [Generated by: @gkalpak/aliases v0.14.1]
|
|
5
5
|
### Copy the following into '~/.gnupg/gpg-agent.conf':
|
|
6
6
|
|
|
7
7
|
default-cache-ttl 86400
|
package/bin/config/cfgssh.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {stripIndentation} from '../../lib/utils.js';
|
|
3
3
|
console.log(stripIndentation(`
|
|
4
|
-
### [Generated by: @gkalpak/aliases v0.14.
|
|
4
|
+
### [Generated by: @gkalpak/aliases v0.14.1]
|
|
5
5
|
### Copy the following into '~/.ssh/config':
|
|
6
6
|
|
|
7
7
|
IdentityFile ~/.ssh/id-rsa-gkalpak.priv
|
package/bin/config/cfgvim.js
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
import {readFileSync} from 'node:fs';
|
|
3
3
|
import {fileURLToPath} from 'node:url';
|
|
4
4
|
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
|
5
|
-
console.log('""" [Generated by: @gkalpak/aliases v0.14.
|
|
5
|
+
console.log('""" [Generated by: @gkalpak/aliases v0.14.1]');
|
|
6
6
|
console.log('""" Copy the following into \'~/.vimrc\':\n');
|
|
7
7
|
console.log(readFileSync(`${__dirname}/../../lib/assets/vimrc.txt`, 'utf8').trim() + '\n');
|
package/bin/config/cfgwsl.wsl.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {stripIndentation} from '../../lib/utils.js';
|
|
3
3
|
console.log(stripIndentation(`
|
|
4
|
-
### [Generated by: @gkalpak/aliases v0.14.
|
|
4
|
+
### [Generated by: @gkalpak/aliases v0.14.1]
|
|
5
5
|
### Copy the following into a root-owned, 600-mode '/etc/resolv.conf' file:
|
|
6
6
|
|
|
7
7
|
# Cloudflare
|
|
@@ -14,7 +14,7 @@ console.log(stripIndentation(`
|
|
|
14
14
|
|
|
15
15
|
-----
|
|
16
16
|
|
|
17
|
-
### [Generated by: @gkalpak/aliases v0.14.
|
|
17
|
+
### [Generated by: @gkalpak/aliases v0.14.1]
|
|
18
18
|
### Copy the following into a root-owned, 600-mode '/etc/wsl.conf' file:
|
|
19
19
|
|
|
20
20
|
[network]
|
package/bin/misc/alv.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
console.log('@gkalpak/aliases v0.14.
|
|
2
|
+
console.log('@gkalpak/aliases v0.14.1');
|
|
@@ -70,7 +70,7 @@ function main(runtimeArgs, config) {
|
|
|
70
70
|
|
|
71
71
|
async function pickBranch(branchType, branches) {
|
|
72
72
|
// Ensure colors are always used (even when running with `returnOutput: <number>`).
|
|
73
|
-
const {default:
|
|
73
|
+
const {default: select, Separator} = await importWithEnv(() => import('@inquirer/select'), {FORCE_COLOR: '1'});
|
|
74
74
|
|
|
75
75
|
const currentBranchIdx = Math.max(0, branches.findIndex(({name}) => name.endsWith(branchNameSuffices['*'])));
|
|
76
76
|
|
|
@@ -84,17 +84,23 @@ async function pickBranch(branchType, branches) {
|
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
try {
|
|
87
|
-
const
|
|
88
|
-
{
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
choices: branches.concat(new inquirer.Separator()),
|
|
93
|
-
default: currentBranchIdx,
|
|
94
|
-
},
|
|
95
|
-
]);
|
|
87
|
+
const branch = await select({
|
|
88
|
+
message: `Pick a ${branchType} branch:`,
|
|
89
|
+
choices: branches.concat(new Separator()),
|
|
90
|
+
default: branches[currentBranchIdx]?.value,
|
|
91
|
+
});
|
|
96
92
|
|
|
97
93
|
return branch;
|
|
94
|
+
} catch (err) {
|
|
95
|
+
if (
|
|
96
|
+
(err instanceof Error) &&
|
|
97
|
+
(err.name === 'ExitPromptError') &&
|
|
98
|
+
err.message.startsWith('User force closed the prompt')
|
|
99
|
+
) {
|
|
100
|
+
process.stderr.write('Aborted by user.\n');
|
|
101
|
+
} else {
|
|
102
|
+
throw err;
|
|
103
|
+
}
|
|
98
104
|
} finally {
|
|
99
105
|
unlisten();
|
|
100
106
|
}
|
|
@@ -76,13 +76,14 @@ function main(runtimeArgs, config) {
|
|
|
76
76
|
|
|
77
77
|
async function pickCommit(commitsStr) {
|
|
78
78
|
// Ensure colors are always used (even when running with `returnOutput: <number>`).
|
|
79
|
-
const {default:
|
|
79
|
+
const {default: select, Separator} = await importWithEnv(() => import('@inquirer/select'), {FORCE_COLOR: '1'});
|
|
80
80
|
|
|
81
81
|
const commits = commitsStr.
|
|
82
82
|
split('\n').
|
|
83
83
|
map(line => line.trim()).
|
|
84
84
|
filter(Boolean).
|
|
85
|
-
|
|
85
|
+
map(line => ({name: line, value: line.replace(/\s+.*$/, '')})).
|
|
86
|
+
concat(new Separator());
|
|
86
87
|
|
|
87
88
|
const unlisten = processUtils.doOnExit(process, code => {
|
|
88
89
|
if (code === 0) {
|
|
@@ -94,17 +95,23 @@ async function pickCommit(commitsStr) {
|
|
|
94
95
|
});
|
|
95
96
|
|
|
96
97
|
try {
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
98
|
+
const commit = await select({
|
|
99
|
+
message: 'Pick a commit:',
|
|
100
|
+
choices: commits,
|
|
101
|
+
default: commits[0].value,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return commit;
|
|
105
|
+
} catch (err) {
|
|
106
|
+
if (
|
|
107
|
+
(err instanceof Error) &&
|
|
108
|
+
(err.name === 'ExitPromptError') &&
|
|
109
|
+
err.message.startsWith('User force closed the prompt')
|
|
110
|
+
) {
|
|
111
|
+
process.stderr.write('Aborted by user.\n');
|
|
112
|
+
} else {
|
|
113
|
+
throw err;
|
|
114
|
+
}
|
|
108
115
|
} finally {
|
|
109
116
|
unlisten();
|
|
110
117
|
}
|
package/lib/utils.js
CHANGED
|
@@ -13,6 +13,7 @@ const internal = {
|
|
|
13
13
|
_fsExistsSync,
|
|
14
14
|
_fsRealpathSync,
|
|
15
15
|
_getPlatform,
|
|
16
|
+
_importWithEnv,
|
|
16
17
|
_onError,
|
|
17
18
|
_wrapLine,
|
|
18
19
|
};
|
|
@@ -47,6 +48,24 @@ function _getPlatform() {
|
|
|
47
48
|
return PLATFORM;
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
async function _importWithEnv(importFn, tempEnvVars) {
|
|
52
|
+
const {env} = process;
|
|
53
|
+
|
|
54
|
+
const tempEnvVarNames = Object.keys(tempEnvVars);
|
|
55
|
+
const originalValues = tempEnvVarNames.
|
|
56
|
+
filter(name => hasOwnProperty(env, name)).
|
|
57
|
+
reduce((aggr, name) => Object.assign(aggr, {[name]: env[name]}), {});
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
Object.assign(env, tempEnvVars);
|
|
61
|
+
return await importFn();
|
|
62
|
+
} finally {
|
|
63
|
+
tempEnvVarNames.forEach(name => hasOwnProperty(originalValues, name) ?
|
|
64
|
+
env[name] = originalValues[name] :
|
|
65
|
+
delete env[name]);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
50
69
|
async function _onError(err) {
|
|
51
70
|
// NOTE:
|
|
52
71
|
// Avoid eagerly loading `chalk` at the top of the file to allow for it to be imported (directly
|
|
@@ -90,22 +109,8 @@ function hasOwnProperty(obj, prop) {
|
|
|
90
109
|
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
91
110
|
}
|
|
92
111
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const tempEnvVarNames = Object.keys(tempEnvVars);
|
|
97
|
-
const originalValues = tempEnvVarNames.
|
|
98
|
-
filter(name => hasOwnProperty(env, name)).
|
|
99
|
-
reduce((aggr, name) => Object.assign(aggr, {[name]: env[name]}), {});
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
Object.assign(env, tempEnvVars);
|
|
103
|
-
return await importFn();
|
|
104
|
-
} finally {
|
|
105
|
-
tempEnvVarNames.forEach(name => hasOwnProperty(originalValues, name) ?
|
|
106
|
-
env[name] = originalValues[name] :
|
|
107
|
-
delete env[name]);
|
|
108
|
-
}
|
|
112
|
+
function importWithEnv(importFn, tempEnvVars) {
|
|
113
|
+
return internal._importWithEnv(importFn, tempEnvVars);
|
|
109
114
|
}
|
|
110
115
|
|
|
111
116
|
function isMain(fileUrl) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gkalpak/aliases",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "My global aliases.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Utility"
|
|
@@ -199,9 +199,9 @@
|
|
|
199
199
|
}
|
|
200
200
|
},
|
|
201
201
|
"dependencies": {
|
|
202
|
-
"@gkalpak/cli-utils": "^0.3.
|
|
202
|
+
"@gkalpak/cli-utils": "^0.3.1",
|
|
203
|
+
"@inquirer/select": "^5.1.0",
|
|
203
204
|
"chalk": "^5.6.2",
|
|
204
|
-
"inquirer": "^13.3.0",
|
|
205
205
|
"is-wsl": "^3.1.1"
|
|
206
206
|
},
|
|
207
207
|
"devDependencies": {
|
|
@@ -20,7 +20,7 @@ function _main() {
|
|
|
20
20
|
const defaultScripts = findFiles(BIN_DIR).filter(x => defaultExtRe.test(x));
|
|
21
21
|
defaultScripts.forEach(defaultScriptPath => {
|
|
22
22
|
const activeScriptPath = defaultScriptPath.replace(defaultExtRe, '.js');
|
|
23
|
-
|
|
23
|
+
renameSync(defaultScriptPath, activeScriptPath);
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
// "Activate" any platform-specific scripts.
|
|
@@ -33,26 +33,27 @@ function _main() {
|
|
|
33
33
|
const activeScriptMode = statSync(activeScriptPath).mode;
|
|
34
34
|
|
|
35
35
|
// Back up the default script for future restoration.
|
|
36
|
-
|
|
36
|
+
renameSync(activeScriptPath, defaultScriptPath);
|
|
37
37
|
|
|
38
38
|
// Copy the platform-specific script (not move just in case).
|
|
39
|
-
|
|
39
|
+
copyFileSync(platformScriptPath, activeScriptPath);
|
|
40
40
|
|
|
41
41
|
// Preserve active script mode (including "executability") for the scripts to work on *nix platforms.
|
|
42
42
|
chmodSync(activeScriptPath, activeScriptMode);
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
46
|
+
/**
|
|
47
|
+
* @param {string} rootDir
|
|
48
|
+
* @returns {string[]}
|
|
49
|
+
*/
|
|
50
50
|
function findFiles(rootDir) {
|
|
51
51
|
const unvisitedDirectories = [rootDir];
|
|
52
|
+
/** @type {string[]} */
|
|
52
53
|
const files = [];
|
|
53
54
|
|
|
54
55
|
while (unvisitedDirectories.length) {
|
|
55
|
-
const currentDir = unvisitedDirectories.pop();
|
|
56
|
+
const currentDir = /** @type {string} */(unvisitedDirectories.pop());
|
|
56
57
|
readdirSync(currentDir).forEach(name => {
|
|
57
58
|
const path = join(currentDir, name);
|
|
58
59
|
const info = statSync(path);
|
|
@@ -64,7 +65,3 @@ function findFiles(rootDir) {
|
|
|
64
65
|
|
|
65
66
|
return files;
|
|
66
67
|
}
|
|
67
|
-
|
|
68
|
-
function moveFile(fromPath, toPath) {
|
|
69
|
-
renameSync(fromPath, toPath);
|
|
70
|
-
}
|