@tnqai/alim 1.0.0 → 1.2.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/alias-manager.js +80 -0
- package/package.json +1 -1
package/alias-manager.js
CHANGED
|
@@ -173,6 +173,82 @@ const commands = {
|
|
|
173
173
|
console.log(`\nRun: source ${getShellConfig()}`);
|
|
174
174
|
},
|
|
175
175
|
|
|
176
|
+
addx(args) {
|
|
177
|
+
const [name, command, category = 'misc'] = args;
|
|
178
|
+
|
|
179
|
+
if (!name || !command) {
|
|
180
|
+
console.error('Usage: alias-manager addx <name> <command> [category]');
|
|
181
|
+
console.error('Categories:', CATEGORIES.join(', '));
|
|
182
|
+
process.exit(1);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (!CATEGORIES.includes(category)) {
|
|
186
|
+
console.error(`Invalid category. Choose from: ${CATEGORIES.join(', ')}`);
|
|
187
|
+
process.exit(1);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Check if shell wrapper function exists
|
|
191
|
+
const shellConfig = getShellConfig();
|
|
192
|
+
if (fs.existsSync(shellConfig)) {
|
|
193
|
+
const content = fs.readFileSync(shellConfig, 'utf8');
|
|
194
|
+
if (!content.includes('alm() {') && !content.includes('function alm')) {
|
|
195
|
+
console.log('⚠️ Shell wrapper function not found!\n');
|
|
196
|
+
console.log('To make addx work automatically, add this function to your shell:\n');
|
|
197
|
+
console.log('alm() {');
|
|
198
|
+
console.log(' if [ "$1" = "addx" ]; then');
|
|
199
|
+
console.log(' command alm "$@" && source ' + shellConfig);
|
|
200
|
+
console.log(' else');
|
|
201
|
+
console.log(' command alm "$@"');
|
|
202
|
+
console.log(' fi');
|
|
203
|
+
console.log('}\n');
|
|
204
|
+
console.log('💡 Quick install:');
|
|
205
|
+
console.log(' alm install-wrapper\n');
|
|
206
|
+
process.exit(1);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Check if alias already exists
|
|
211
|
+
const existing = loadAllAliases().find(a => a.name === name);
|
|
212
|
+
if (existing) {
|
|
213
|
+
console.error(`Alias "${name}" already exists in category "${existing.category}"`);
|
|
214
|
+
process.exit(1);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
saveAlias(name, command, category);
|
|
218
|
+
ensureShellConfig();
|
|
219
|
+
|
|
220
|
+
console.log(`✅ Added alias: ${name} → ${command} [${category}]`);
|
|
221
|
+
console.log(`✅ Alias will be loaded automatically (via shell wrapper)`);
|
|
222
|
+
},
|
|
223
|
+
|
|
224
|
+
'install-wrapper'() {
|
|
225
|
+
const shellConfig = getShellConfig();
|
|
226
|
+
|
|
227
|
+
if (fs.existsSync(shellConfig)) {
|
|
228
|
+
const content = fs.readFileSync(shellConfig, 'utf8');
|
|
229
|
+
if (content.includes('alm() {') || content.includes('function alm')) {
|
|
230
|
+
console.log('✅ Shell wrapper function already installed');
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const wrapperFunction = `
|
|
236
|
+
# Alias Manager wrapper function
|
|
237
|
+
alm() {
|
|
238
|
+
if [ "$1" = "addx" ]; then
|
|
239
|
+
command alm "$@" && source ${shellConfig}
|
|
240
|
+
else
|
|
241
|
+
command alm "$@"
|
|
242
|
+
fi
|
|
243
|
+
}
|
|
244
|
+
`;
|
|
245
|
+
|
|
246
|
+
fs.appendFileSync(shellConfig, wrapperFunction);
|
|
247
|
+
console.log(`✅ Shell wrapper function installed to ${shellConfig}`);
|
|
248
|
+
console.log(`\nRun: source ${shellConfig}`);
|
|
249
|
+
console.log('Now you can use: alm addx <name> <command> [category]');
|
|
250
|
+
},
|
|
251
|
+
|
|
176
252
|
remove(args) {
|
|
177
253
|
const name = args[0];
|
|
178
254
|
if (!name) {
|
|
@@ -243,10 +319,12 @@ Commands:
|
|
|
243
319
|
list [category] List all aliases (or by category)
|
|
244
320
|
find <keyword> Search aliases
|
|
245
321
|
add <name> <cmd> [cat] Add new alias
|
|
322
|
+
addx <name> <cmd> [cat] Add new alias and auto-load it (requires wrapper)
|
|
246
323
|
remove <name> Remove alias
|
|
247
324
|
categories Show all categories
|
|
248
325
|
export [file] Export aliases to JSON
|
|
249
326
|
import <file> Import aliases from JSON
|
|
327
|
+
install-wrapper Install shell wrapper function for addx
|
|
250
328
|
help Show this help
|
|
251
329
|
|
|
252
330
|
Categories: ${CATEGORIES.join(', ')}
|
|
@@ -256,6 +334,8 @@ Examples:
|
|
|
256
334
|
alias-manager list git
|
|
257
335
|
alias-manager find push
|
|
258
336
|
alias-manager add gp "git push" git
|
|
337
|
+
alias-manager install-wrapper
|
|
338
|
+
alias-manager addx gst "git status" git
|
|
259
339
|
alias-manager remove gp
|
|
260
340
|
alias-manager export backup.json
|
|
261
341
|
`);
|