@tnqai/alim 1.2.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 +99 -77
  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,6 +188,11 @@ const commands = {
159
188
  process.exit(1);
160
189
  }
161
190
 
191
+ // Check almx wrapper if running as almx
192
+ if (isAlmx && !checkAlmxWrapper()) {
193
+ process.exit(1);
194
+ }
195
+
162
196
  // Check if alias already exists
163
197
  const existing = loadAllAliases().find(a => a.name === name);
164
198
  if (existing) {
@@ -170,55 +204,43 @@ const commands = {
170
204
  ensureShellConfig();
171
205
 
172
206
  console.log(`✅ Added alias: ${name} → ${command} [${category}]`);
173
- console.log(`\nRun: source ${getShellConfig()}`);
207
+
208
+ if (isAlmx) {
209
+ console.log(`✅ Alias will be loaded automatically (via shell wrapper)`);
210
+ } else {
211
+ console.log(`\nRun: source ${getShellConfig()}`);
212
+ }
174
213
  },
175
214
 
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(', '));
215
+
216
+ remove(args) {
217
+ const name = args[0];
218
+ if (!name) {
219
+ console.error('Usage: alias-manager remove <name>');
182
220
  process.exit(1);
183
221
  }
184
222
 
185
- if (!CATEGORIES.includes(category)) {
186
- console.error(`Invalid category. Choose from: ${CATEGORIES.join(', ')}`);
223
+ // Check almx wrapper if running as almx
224
+ if (isAlmx && !checkAlmxWrapper()) {
187
225
  process.exit(1);
188
226
  }
189
227
 
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
- }
228
+ const aliases = loadAllAliases();
229
+ const alias = aliases.find(a => a.name === name);
209
230
 
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}"`);
231
+ if (!alias) {
232
+ console.error(`Alias "${name}" not found`);
214
233
  process.exit(1);
215
234
  }
216
235
 
217
- saveAlias(name, command, category);
218
- ensureShellConfig();
236
+ removeAlias(name, alias.category);
237
+ console.log(`✅ Removed alias: ${name} [${alias.category}]`);
219
238
 
220
- console.log(`✅ Added alias: ${name} → ${command} [${category}]`);
221
- console.log(`✅ Alias will be loaded automatically (via shell wrapper)`);
239
+ if (isAlmx) {
240
+ console.log(`✅ Changes will be loaded automatically (via shell wrapper)`);
241
+ } else {
242
+ console.log(`\nRun: source ${getShellConfig()}`);
243
+ }
222
244
  },
223
245
 
224
246
  'install-wrapper'() {
@@ -226,47 +248,26 @@ const commands = {
226
248
 
227
249
  if (fs.existsSync(shellConfig)) {
228
250
  const content = fs.readFileSync(shellConfig, 'utf8');
229
- if (content.includes('alm() {') || content.includes('function alm')) {
251
+ if (content.includes('almx() {') || content.includes('function almx')) {
230
252
  console.log('✅ Shell wrapper function already installed');
231
253
  return;
232
254
  }
233
255
  }
234
256
 
235
257
  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
258
+ # Alias Manager wrapper function for almx
259
+ almx() {
260
+ command almx "$@" && source ${shellConfig}
243
261
  }
244
262
  `;
245
263
 
246
264
  fs.appendFileSync(shellConfig, wrapperFunction);
247
265
  console.log(`✅ Shell wrapper function installed to ${shellConfig}`);
248
266
  console.log(`\nRun: source ${shellConfig}`);
249
- console.log('Now you can use: alm addx <name> <command> [category]');
250
- },
251
-
252
- remove(args) {
253
- const name = args[0];
254
- if (!name) {
255
- console.error('Usage: alias-manager remove <name>');
256
- process.exit(1);
257
- }
258
-
259
- const aliases = loadAllAliases();
260
- const alias = aliases.find(a => a.name === name);
261
-
262
- if (!alias) {
263
- console.error(`Alias "${name}" not found`);
264
- process.exit(1);
265
- }
266
-
267
- removeAlias(name, alias.category);
268
- console.log(`✅ Removed alias: ${name} [${alias.category}]`);
269
- console.log(`\nRun: source ${getShellConfig()}`);
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');
270
271
  },
271
272
 
272
273
  categories() {
@@ -292,6 +293,11 @@ alm() {
292
293
  process.exit(1);
293
294
  }
294
295
 
296
+ // Check almx wrapper if running as almx
297
+ if (isAlmx && !checkAlmxWrapper()) {
298
+ process.exit(1);
299
+ }
300
+
295
301
  const aliases = JSON.parse(fs.readFileSync(inputFile, 'utf8'));
296
302
  let count = 0;
297
303
 
@@ -305,39 +311,55 @@ alm() {
305
311
 
306
312
  ensureShellConfig();
307
313
  console.log(`✅ Imported ${count} aliases`);
308
- 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
+ }
309
320
  },
310
321
 
311
322
  help() {
323
+ const cmdName = isAlmx ? 'almx' : 'alm';
312
324
  console.log(`
313
325
  📦 Alias Manager
314
326
 
315
327
  Usage:
316
- alias-manager <command> [args]
328
+ ${cmdName} <command> [args]
317
329
 
318
330
  Commands:
319
331
  list [category] List all aliases (or by category)
320
332
  find <keyword> Search aliases
321
333
  add <name> <cmd> [cat] Add new alias
322
- addx <name> <cmd> [cat] Add new alias and auto-load it (requires wrapper)
323
334
  remove <name> Remove alias
324
335
  categories Show all categories
325
336
  export [file] Export aliases to JSON
326
337
  import <file> Import aliases from JSON
327
- install-wrapper Install shell wrapper function for addx
338
+ install-wrapper Install shell wrapper function for almx
328
339
  help Show this help
329
340
 
330
341
  Categories: ${CATEGORIES.join(', ')}
331
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
+
332
347
  Examples:
333
- alias-manager list
334
- alias-manager list git
335
- alias-manager find push
336
- alias-manager add gp "git push" git
337
- alias-manager install-wrapper
338
- alias-manager addx gst "git status" git
339
- alias-manager remove gp
340
- 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
341
363
  `);
342
364
  }
343
365
  };
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@tnqai/alim",
3
- "version": "1.2.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",