@tnqai/alim 1.1.0 → 2.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.
Files changed (2) hide show
  1. package/alias-manager.js +107 -54
  2. package/package.json +3 -2
package/alias-manager.js CHANGED
@@ -7,6 +7,9 @@ const os = require('os');
7
7
  const ALIAS_DIR = path.join(os.homedir(), '.aliases');
8
8
  const CATEGORIES = ['git', 'docker', 'system', 'npm', 'misc'];
9
9
 
10
+ // Detect if running as almx
11
+ const isAlmx = process.argv[1].includes('almx');
12
+
10
13
  // Ensure alias directory exists
11
14
  if (!fs.existsSync(ALIAS_DIR)) {
12
15
  fs.mkdirSync(ALIAS_DIR, { recursive: true });
@@ -87,6 +90,32 @@ function ensureShellConfig() {
87
90
  }
88
91
  }
89
92
 
93
+ // Check if almx wrapper is installed
94
+ function checkAlmxWrapper() {
95
+ if (!isAlmx) return true; // Only check when running as almx
96
+
97
+ const shellConfig = getShellConfig();
98
+ if (fs.existsSync(shellConfig)) {
99
+ const content = fs.readFileSync(shellConfig, 'utf8');
100
+ if (content.includes('almx() {') || content.includes('function almx')) {
101
+ return true;
102
+ }
103
+ }
104
+
105
+ console.log('⚠️ Shell wrapper function not found!\n');
106
+ console.log('To make almx work automatically, add this function to your shell:\n');
107
+ console.log('almx() {');
108
+ console.log(' command almx "$@" && source ' + shellConfig);
109
+ console.log('}\n');
110
+ console.log('💡 Quick install:');
111
+ console.log(' alm install-wrapper && source ' + shellConfig + '\n');
112
+ console.log('Then you can use almx commands that auto-load changes:');
113
+ console.log(' almx add gst "git status" git');
114
+ console.log(' almx remove gst');
115
+ console.log(' almx import backup.json\n');
116
+ return false;
117
+ }
118
+
90
119
  // Commands
91
120
  const commands = {
92
121
  list(args) {
@@ -159,31 +188,8 @@ const commands = {
159
188
  process.exit(1);
160
189
  }
161
190
 
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
- 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(', ')}`);
191
+ // Check almx wrapper if running as almx
192
+ if (isAlmx && !checkAlmxWrapper()) {
187
193
  process.exit(1);
188
194
  }
189
195
 
@@ -198,28 +204,15 @@ const commands = {
198
204
  ensureShellConfig();
199
205
 
200
206
  console.log(`✅ Added alias: ${name} → ${command} [${category}]`);
201
- console.log(`\n💡 To use immediately, run:`);
202
- console.log(` eval "$(alm addx-eval ${name})"`);
203
- console.log(`\nOr source your shell config:`);
204
- console.log(` source ${getShellConfig()}`);
205
- },
206
-
207
- 'addx-eval'(args) {
208
- const name = args[0];
209
- if (!name) {
210
- process.exit(1);
211
- }
212
207
 
213
- const aliases = loadAllAliases();
214
- const alias = aliases.find(a => a.name === name);
215
-
216
- if (alias) {
217
- // Escape single quotes in command
218
- const escapedCommand = alias.command.replace(/'/g, "'\\''");
219
- console.log(`alias ${alias.name}='${escapedCommand}'`);
208
+ if (isAlmx) {
209
+ console.log(`✅ Alias will be loaded automatically (via shell wrapper)`);
210
+ } else {
211
+ console.log(`\nRun: source ${getShellConfig()}`);
220
212
  }
221
213
  },
222
214
 
215
+
223
216
  remove(args) {
224
217
  const name = args[0];
225
218
  if (!name) {
@@ -227,6 +220,11 @@ const commands = {
227
220
  process.exit(1);
228
221
  }
229
222
 
223
+ // Check almx wrapper if running as almx
224
+ if (isAlmx && !checkAlmxWrapper()) {
225
+ process.exit(1);
226
+ }
227
+
230
228
  const aliases = loadAllAliases();
231
229
  const alias = aliases.find(a => a.name === name);
232
230
 
@@ -237,7 +235,39 @@ const commands = {
237
235
 
238
236
  removeAlias(name, alias.category);
239
237
  console.log(`✅ Removed alias: ${name} [${alias.category}]`);
240
- console.log(`\nRun: source ${getShellConfig()}`);
238
+
239
+ if (isAlmx) {
240
+ console.log(`✅ Changes will be loaded automatically (via shell wrapper)`);
241
+ } else {
242
+ console.log(`\nRun: source ${getShellConfig()}`);
243
+ }
244
+ },
245
+
246
+ 'install-wrapper'() {
247
+ const shellConfig = getShellConfig();
248
+
249
+ if (fs.existsSync(shellConfig)) {
250
+ const content = fs.readFileSync(shellConfig, 'utf8');
251
+ if (content.includes('almx() {') || content.includes('function almx')) {
252
+ console.log('✅ Shell wrapper function already installed');
253
+ return;
254
+ }
255
+ }
256
+
257
+ const wrapperFunction = `
258
+ # Alias Manager wrapper function for almx
259
+ almx() {
260
+ command almx "$@" && source ${shellConfig}
261
+ }
262
+ `;
263
+
264
+ fs.appendFileSync(shellConfig, wrapperFunction);
265
+ console.log(`✅ Shell wrapper function installed to ${shellConfig}`);
266
+ console.log(`\nRun: source ${shellConfig}`);
267
+ console.log('Now you can use almx commands that auto-load changes:');
268
+ console.log(' almx add gst "git status" git');
269
+ console.log(' almx remove gst');
270
+ console.log(' almx import backup.json');
241
271
  },
242
272
 
243
273
  categories() {
@@ -263,6 +293,11 @@ const commands = {
263
293
  process.exit(1);
264
294
  }
265
295
 
296
+ // Check almx wrapper if running as almx
297
+ if (isAlmx && !checkAlmxWrapper()) {
298
+ process.exit(1);
299
+ }
300
+
266
301
  const aliases = JSON.parse(fs.readFileSync(inputFile, 'utf8'));
267
302
  let count = 0;
268
303
 
@@ -276,37 +311,55 @@ const commands = {
276
311
 
277
312
  ensureShellConfig();
278
313
  console.log(`✅ Imported ${count} aliases`);
279
- console.log(`\nRun: source ${getShellConfig()}`);
314
+
315
+ if (isAlmx) {
316
+ console.log(`✅ Changes will be loaded automatically (via shell wrapper)`);
317
+ } else {
318
+ console.log(`\nRun: source ${getShellConfig()}`);
319
+ }
280
320
  },
281
321
 
282
322
  help() {
323
+ const cmdName = isAlmx ? 'almx' : 'alm';
283
324
  console.log(`
284
325
  📦 Alias Manager
285
326
 
286
327
  Usage:
287
- alias-manager <command> [args]
328
+ ${cmdName} <command> [args]
288
329
 
289
330
  Commands:
290
331
  list [category] List all aliases (or by category)
291
332
  find <keyword> Search aliases
292
333
  add <name> <cmd> [cat] Add new alias
293
- addx <name> <cmd> [cat] Add new alias and auto-load it
294
334
  remove <name> Remove alias
295
335
  categories Show all categories
296
336
  export [file] Export aliases to JSON
297
337
  import <file> Import aliases from JSON
338
+ install-wrapper Install shell wrapper function for almx
298
339
  help Show this help
299
340
 
300
341
  Categories: ${CATEGORIES.join(', ')}
301
342
 
343
+ Difference between alm and almx:
344
+ alm - Manual mode: prompts you to run 'source ~/.bashrc' after changes
345
+ almx - Auto mode: automatically loads changes (requires wrapper installation)
346
+
302
347
  Examples:
303
- alias-manager list
304
- alias-manager list git
305
- alias-manager find push
306
- alias-manager add gp "git push" git
307
- alias-manager addx gst "git status" git
308
- alias-manager remove gp
309
- alias-manager export backup.json
348
+ # Using alm (manual)
349
+ alm add gp "git push" git
350
+ source ~/.bashrc
351
+
352
+ # Using almx (auto, requires setup)
353
+ alm install-wrapper && source ~/.bashrc
354
+ almx add gst "git status" git # Auto-loaded!
355
+ almx remove gst # Auto-loaded!
356
+ almx import backup.json # Auto-loaded!
357
+
358
+ # Other commands
359
+ alm list
360
+ alm list git
361
+ alm find push
362
+ alm export backup.json
310
363
  `);
311
364
  }
312
365
  };
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@tnqai/alim",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "description": "A simple and elegant alias manager for your shell",
5
5
  "main": "alias-manager.js",
6
6
  "bin": {
7
- "alm": "./alias-manager.js"
7
+ "alm": "./alias-manager.js",
8
+ "almx": "./alias-manager.js"
8
9
  },
9
10
  "keywords": [
10
11
  "alias",