@tnqai/alim 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/README.md +67 -0
- package/alias-manager.js +273 -0
- package/package.json +27 -0
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# alim
|
|
2
|
+
|
|
3
|
+
A simple and elegant alias manager for your shell.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- š¦ Organize aliases by category (git, docker, system, npm, misc)
|
|
8
|
+
- š Search aliases by name or command
|
|
9
|
+
- š¾ Export/import aliases as JSON
|
|
10
|
+
- šÆ Auto-configure shell (bash/zsh)
|
|
11
|
+
- š Simple CLI interface
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g alim
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# List all aliases
|
|
23
|
+
alm list
|
|
24
|
+
|
|
25
|
+
# List aliases by category
|
|
26
|
+
alm list git
|
|
27
|
+
|
|
28
|
+
# Add a new alias
|
|
29
|
+
alm add gst "git status" git
|
|
30
|
+
|
|
31
|
+
# Search aliases
|
|
32
|
+
alm find push
|
|
33
|
+
|
|
34
|
+
# Remove an alias
|
|
35
|
+
alm remove gst
|
|
36
|
+
|
|
37
|
+
# Show categories
|
|
38
|
+
alm categories
|
|
39
|
+
|
|
40
|
+
# Export aliases
|
|
41
|
+
alm export backup.json
|
|
42
|
+
|
|
43
|
+
# Import aliases
|
|
44
|
+
alm import backup.json
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Categories
|
|
48
|
+
|
|
49
|
+
- `git` - Git-related aliases
|
|
50
|
+
- `docker` - Docker commands
|
|
51
|
+
- `system` - System utilities
|
|
52
|
+
- `npm` - NPM/Node.js commands
|
|
53
|
+
- `misc` - Miscellaneous aliases
|
|
54
|
+
|
|
55
|
+
## How it works
|
|
56
|
+
|
|
57
|
+
alim stores your aliases in `~/.aliases/` directory, organized by category. It automatically adds source commands to your shell config file (`.bashrc` or `.zshrc`).
|
|
58
|
+
|
|
59
|
+
After adding or removing aliases, run:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
source ~/.bashrc # or ~/.zshrc
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## License
|
|
66
|
+
|
|
67
|
+
MIT
|
package/alias-manager.js
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const os = require('os');
|
|
6
|
+
|
|
7
|
+
const ALIAS_DIR = path.join(os.homedir(), '.aliases');
|
|
8
|
+
const CATEGORIES = ['git', 'docker', 'system', 'npm', 'misc'];
|
|
9
|
+
|
|
10
|
+
// Ensure alias directory exists
|
|
11
|
+
if (!fs.existsSync(ALIAS_DIR)) {
|
|
12
|
+
fs.mkdirSync(ALIAS_DIR, { recursive: true });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Get shell config file
|
|
16
|
+
function getShellConfig() {
|
|
17
|
+
const shell = process.env.SHELL || '';
|
|
18
|
+
if (shell.includes('zsh')) return path.join(os.homedir(), '.zshrc');
|
|
19
|
+
if (shell.includes('bash')) return path.join(os.homedir(), '.bashrc');
|
|
20
|
+
return path.join(os.homedir(), '.bashrc');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Load aliases from category file
|
|
24
|
+
function loadCategory(category) {
|
|
25
|
+
const file = path.join(ALIAS_DIR, `${category}.sh`);
|
|
26
|
+
if (!fs.existsSync(file)) return [];
|
|
27
|
+
|
|
28
|
+
const content = fs.readFileSync(file, 'utf8');
|
|
29
|
+
const aliases = [];
|
|
30
|
+
|
|
31
|
+
content.split('\n').forEach(line => {
|
|
32
|
+
const match = line.match(/^alias\s+([^=]+)=['"](.+)['"]/);
|
|
33
|
+
if (match) {
|
|
34
|
+
aliases.push({ name: match[1], command: match[2], category });
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return aliases;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Load all aliases
|
|
42
|
+
function loadAllAliases() {
|
|
43
|
+
const all = [];
|
|
44
|
+
CATEGORIES.forEach(cat => {
|
|
45
|
+
all.push(...loadCategory(cat));
|
|
46
|
+
});
|
|
47
|
+
return all;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Save alias to category file
|
|
51
|
+
function saveAlias(name, command, category) {
|
|
52
|
+
const file = path.join(ALIAS_DIR, `${category}.sh`);
|
|
53
|
+
const line = `alias ${name}='${command}'\n`;
|
|
54
|
+
fs.appendFileSync(file, line);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Remove alias from category file
|
|
58
|
+
function removeAlias(name, category) {
|
|
59
|
+
const file = path.join(ALIAS_DIR, `${category}.sh`);
|
|
60
|
+
if (!fs.existsSync(file)) return false;
|
|
61
|
+
|
|
62
|
+
const content = fs.readFileSync(file, 'utf8');
|
|
63
|
+
const lines = content.split('\n').filter(line => {
|
|
64
|
+
const match = line.match(/^alias\s+([^=]+)=/);
|
|
65
|
+
return !match || match[1] !== name;
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
fs.writeFileSync(file, lines.join('\n'));
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Ensure shell config sources alias files
|
|
73
|
+
function ensureShellConfig() {
|
|
74
|
+
const shellConfig = getShellConfig();
|
|
75
|
+
const sourceLines = CATEGORIES.map(cat =>
|
|
76
|
+
`[ -f ~/.aliases/${cat}.sh ] && source ~/.aliases/${cat}.sh`
|
|
77
|
+
).join('\n');
|
|
78
|
+
|
|
79
|
+
if (!fs.existsSync(shellConfig)) {
|
|
80
|
+
fs.writeFileSync(shellConfig, sourceLines + '\n');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const content = fs.readFileSync(shellConfig, 'utf8');
|
|
85
|
+
if (!content.includes('.aliases/')) {
|
|
86
|
+
fs.appendFileSync(shellConfig, '\n# Alias Manager\n' + sourceLines + '\n');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Commands
|
|
91
|
+
const commands = {
|
|
92
|
+
list(args) {
|
|
93
|
+
const category = args[0];
|
|
94
|
+
const aliases = category ? loadCategory(category) : loadAllAliases();
|
|
95
|
+
|
|
96
|
+
if (aliases.length === 0) {
|
|
97
|
+
console.log('No aliases found.');
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
console.log('\nš Aliases:\n');
|
|
102
|
+
|
|
103
|
+
if (category) {
|
|
104
|
+
aliases.forEach(a => {
|
|
105
|
+
console.log(` ${a.name.padEnd(20)} ā ${a.command}`);
|
|
106
|
+
});
|
|
107
|
+
} else {
|
|
108
|
+
const grouped = {};
|
|
109
|
+
aliases.forEach(a => {
|
|
110
|
+
if (!grouped[a.category]) grouped[a.category] = [];
|
|
111
|
+
grouped[a.category].push(a);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
Object.entries(grouped).forEach(([cat, items]) => {
|
|
115
|
+
console.log(`\n[${cat}]`);
|
|
116
|
+
items.forEach(a => {
|
|
117
|
+
console.log(` ${a.name.padEnd(20)} ā ${a.command}`);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
console.log();
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
find(args) {
|
|
125
|
+
const keyword = args[0];
|
|
126
|
+
if (!keyword) {
|
|
127
|
+
console.error('Usage: alias-manager find <keyword>');
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const aliases = loadAllAliases();
|
|
132
|
+
const matches = aliases.filter(a =>
|
|
133
|
+
a.name.includes(keyword) || a.command.includes(keyword)
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
if (matches.length === 0) {
|
|
137
|
+
console.log(`No aliases found matching "${keyword}"`);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
console.log(`\nš Found ${matches.length} matches:\n`);
|
|
142
|
+
matches.forEach(a => {
|
|
143
|
+
console.log(` [${a.category}] ${a.name.padEnd(20)} ā ${a.command}`);
|
|
144
|
+
});
|
|
145
|
+
console.log();
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
add(args) {
|
|
149
|
+
const [name, command, category = 'misc'] = args;
|
|
150
|
+
|
|
151
|
+
if (!name || !command) {
|
|
152
|
+
console.error('Usage: alias-manager add <name> <command> [category]');
|
|
153
|
+
console.error('Categories:', CATEGORIES.join(', '));
|
|
154
|
+
process.exit(1);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (!CATEGORIES.includes(category)) {
|
|
158
|
+
console.error(`Invalid category. Choose from: ${CATEGORIES.join(', ')}`);
|
|
159
|
+
process.exit(1);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Check if alias already exists
|
|
163
|
+
const existing = loadAllAliases().find(a => a.name === name);
|
|
164
|
+
if (existing) {
|
|
165
|
+
console.error(`Alias "${name}" already exists in category "${existing.category}"`);
|
|
166
|
+
process.exit(1);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
saveAlias(name, command, category);
|
|
170
|
+
ensureShellConfig();
|
|
171
|
+
|
|
172
|
+
console.log(`ā
Added alias: ${name} ā ${command} [${category}]`);
|
|
173
|
+
console.log(`\nRun: source ${getShellConfig()}`);
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
remove(args) {
|
|
177
|
+
const name = args[0];
|
|
178
|
+
if (!name) {
|
|
179
|
+
console.error('Usage: alias-manager remove <name>');
|
|
180
|
+
process.exit(1);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const aliases = loadAllAliases();
|
|
184
|
+
const alias = aliases.find(a => a.name === name);
|
|
185
|
+
|
|
186
|
+
if (!alias) {
|
|
187
|
+
console.error(`Alias "${name}" not found`);
|
|
188
|
+
process.exit(1);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
removeAlias(name, alias.category);
|
|
192
|
+
console.log(`ā
Removed alias: ${name} [${alias.category}]`);
|
|
193
|
+
console.log(`\nRun: source ${getShellConfig()}`);
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
categories() {
|
|
197
|
+
console.log('\nš Available categories:\n');
|
|
198
|
+
CATEGORIES.forEach(cat => {
|
|
199
|
+
const count = loadCategory(cat).length;
|
|
200
|
+
console.log(` ${cat.padEnd(15)} (${count} aliases)`);
|
|
201
|
+
});
|
|
202
|
+
console.log();
|
|
203
|
+
},
|
|
204
|
+
|
|
205
|
+
export(args) {
|
|
206
|
+
const outputFile = args[0] || 'aliases-backup.json';
|
|
207
|
+
const aliases = loadAllAliases();
|
|
208
|
+
fs.writeFileSync(outputFile, JSON.stringify(aliases, null, 2));
|
|
209
|
+
console.log(`ā
Exported ${aliases.length} aliases to ${outputFile}`);
|
|
210
|
+
},
|
|
211
|
+
|
|
212
|
+
import(args) {
|
|
213
|
+
const inputFile = args[0];
|
|
214
|
+
if (!inputFile || !fs.existsSync(inputFile)) {
|
|
215
|
+
console.error('Usage: alias-manager import <file.json>');
|
|
216
|
+
process.exit(1);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const aliases = JSON.parse(fs.readFileSync(inputFile, 'utf8'));
|
|
220
|
+
let count = 0;
|
|
221
|
+
|
|
222
|
+
aliases.forEach(a => {
|
|
223
|
+
const existing = loadAllAliases().find(e => e.name === a.name);
|
|
224
|
+
if (!existing) {
|
|
225
|
+
saveAlias(a.name, a.command, a.category);
|
|
226
|
+
count++;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
ensureShellConfig();
|
|
231
|
+
console.log(`ā
Imported ${count} aliases`);
|
|
232
|
+
console.log(`\nRun: source ${getShellConfig()}`);
|
|
233
|
+
},
|
|
234
|
+
|
|
235
|
+
help() {
|
|
236
|
+
console.log(`
|
|
237
|
+
š¦ Alias Manager
|
|
238
|
+
|
|
239
|
+
Usage:
|
|
240
|
+
alias-manager <command> [args]
|
|
241
|
+
|
|
242
|
+
Commands:
|
|
243
|
+
list [category] List all aliases (or by category)
|
|
244
|
+
find <keyword> Search aliases
|
|
245
|
+
add <name> <cmd> [cat] Add new alias
|
|
246
|
+
remove <name> Remove alias
|
|
247
|
+
categories Show all categories
|
|
248
|
+
export [file] Export aliases to JSON
|
|
249
|
+
import <file> Import aliases from JSON
|
|
250
|
+
help Show this help
|
|
251
|
+
|
|
252
|
+
Categories: ${CATEGORIES.join(', ')}
|
|
253
|
+
|
|
254
|
+
Examples:
|
|
255
|
+
alias-manager list
|
|
256
|
+
alias-manager list git
|
|
257
|
+
alias-manager find push
|
|
258
|
+
alias-manager add gp "git push" git
|
|
259
|
+
alias-manager remove gp
|
|
260
|
+
alias-manager export backup.json
|
|
261
|
+
`);
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
// Main
|
|
266
|
+
const [,, command, ...args] = process.argv;
|
|
267
|
+
|
|
268
|
+
if (!command || !commands[command]) {
|
|
269
|
+
commands.help();
|
|
270
|
+
process.exit(command ? 1 : 0);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
commands[command](args);
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tnqai/alim",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A simple and elegant alias manager for your shell",
|
|
5
|
+
"main": "alias-manager.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"alm": "./alias-manager.js"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"alias",
|
|
11
|
+
"shell",
|
|
12
|
+
"bash",
|
|
13
|
+
"zsh",
|
|
14
|
+
"cli",
|
|
15
|
+
"terminal",
|
|
16
|
+
"productivity"
|
|
17
|
+
],
|
|
18
|
+
"author": "",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": ""
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=12.0.0"
|
|
26
|
+
}
|
|
27
|
+
}
|