Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support comments in /config/aliases #286

Closed
rmorrin opened this issue Oct 9, 2014 · 9 comments
Closed

Support comments in /config/aliases #286

rmorrin opened this issue Oct 9, 2014 · 9 comments

Comments

@rmorrin
Copy link
Contributor

rmorrin commented Oct 9, 2014

By default, doskey macro files don't support comments. There is however, a workaround that may be worth investigating: http://ben.versionzero.org/wiki/Doskey_Macros.

While certainly not essential, it would be useful for those of us that have a large number of aliases defined to be able to organize the chaos with some comments!

@cm3
Copy link

cm3 commented Oct 20, 2015

:: worked for me in /config/aliases also.

e.g.

::ls=ls --show-control-chars -F --color $* 

isn't it what you mentioned?

cf. :: is a hack based on flag grammar : and I thought some cmder bat files used that technique.

@rmorrin
Copy link
Contributor Author

rmorrin commented Oct 21, 2015

@cm3 This works well for temporarily disabling aliases, as you mentioned.

I was looking to use comments for organisational purposes:

:: convenience
ls=ls --color $*
lsa=ls -a --color $*
pwd=cd
clear=cls

:: git shortcuts
gs=git status $*
gd=git diff $*
gc=git commit $*
gca=git commit -a $*

...

Unfortunately, this shows an Invalid macro definition. message when Cmder starts.

@cm3
Copy link

cm3 commented Oct 21, 2015

Your code (before ...) worked for me. No Invalid macro definition. error.
('ls' is not recognized as an internal or external command operable program or batch file. but that is another problem.)

I'm using code below and this works fine.

:: Linux compatible

clear=cls
pwd=cd
ls=dir /B $*
mv=move $*
unalias=alias /d $1

:: http://fossil-scm.org/

f=fossil $*

:: Not nano but https://bitbucket.org/wantora/greenpad

nano="C:\Users\User\bin\greenpad\GreenPad.exe" $*

:::: trash box
:: ls=ls --show-control-chars -F --color $*
:: gl=git log --oneline --all --graph --decorate  $*
:: e.=explorer .
:: history=cat %CMDER_ROOT%\config\.history

I suspect that :

  • you have so many aliases that you need comments for organisational purposes.
  • you have so many aliases that you make a mistake other than a comment problem.

@nikolas6
Copy link

I had the same problem with cmder_mini v1.3.1 (Windows 7).
Using :: in user-aliases.cmd shows Invalid macro definition.

I use ;= rem This is a comment instead, just like the default settings in user-aliases.cmd. With that it does not show the invalid message anymore.

@cm3
Copy link

cm3 commented Oct 25, 2016

Seeing user-aliases.cmd in your comment, I realize that init.bat has been updated (https://github.com/cmderdev/cmder/commits/master/vendor/init.bat) and mechanism of user alias has been changed. That could be the problem in the last conversation with rmorrin. When cmder is updated, old init.bat is kept, in other words, I used old mechanism.

Now, I updated init.bat and your (@nikolas6) TIPS worked :)
btw, why does it works? ; and = are separators in batch program, and ...?

@rmorrin
Copy link
Contributor Author

rmorrin commented Oct 25, 2016

Looks like this issue is now resolved with the new user-aliases.cmd.

As @nikolas6 suggested, I can use ;= rem <Comment> to organise the file. 👍

@rmorrin rmorrin closed this as completed Oct 25, 2016
@nikolas6
Copy link

@cm3 I don't know what the ;= is for, and I couldn't find any information about it.
The new user-aliases.cmd even has something like ;= Add aliases below here, and it does not throw out any error message.

@cm3
Copy link

cm3 commented Oct 26, 2016

@nikolas6 now I found the answer. Explanation below is just for your information.

user-aliases.cmd is read as command script first, and then, is read as Doskey macro.
This part implement that trick.

;= @echo off
;= rem Call DOSKEY and use this file as the macrofile
;= %SystemRoot%\system32\doskey /listsize=1000 /macrofile=%0%
;= rem In batch mode, jump to the end of the file
;= goto:eof

A row begin with :: is interpreted as (pseudo-)comment in command script, but not in Doskey macro. Therefore, Invalid macro definition. error occurs.
;= is ignored in command script, and a row begin with ;= is interpreted as (pseudo-)comment Doskey macro.
;= itself is just ignored in command script, and trailing commands are not ignored. Therefore, before goto:eof, command rem is needed for comment row. But after goto:eof, those rows are ignored in the first step ("read as command script first"), so there is no rem in ;= Add aliases below here.

Why ;= function as (pseudo-)comment?
This is alias assignment about ;.
When you type ; in cmder, you'll see 'Add' is not recognized as an internal or external command, operable program or batch file. because ; is the alias of Add aliases below here now. For avoiding this, you can add an row with just ;=, no trailing comment. This row cancels the alias assignment.

References:

@nikolas6
Copy link

@cm3 make sense now. thanks for the detail explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants