Cmder: How do you create an alias?

Created on 13 Mar 2015  路  40Comments  路  Source: cmderdev/cmder

Hi

I want to create aliases to work a litle faster.
Tried creating a .bashrc folder in my home dir but it's not working

Thanks

Most helpful comment

You can create your aliases in the config/aliases folder or with the alias command.
There was also a small part about aliases in the readme:

Aliases

You can define simple aliases with command alias name=command.
For example there is one defined for you alias e.=explorer .
All aliases will be saved in /config/aliases file

All 40 comments

You can create your aliases in the config/aliases folder or with the alias command.
There was also a small part about aliases in the readme:

Aliases

You can define simple aliases with command alias name=command.
For example there is one defined for you alias e.=explorer .
All aliases will be saved in /config/aliases file

Perfect! Thank you very much

To add some to answer above, current cmder (I don't know since when though) , once you have 'config/aliases' file created, on new console window launch automatically converts 'config/aliases' file to 'user-aliases.cmd', that works now in cmder.

If I use the alias command it works but only for the given session. If I restart cmder it is not working anymore.

@adam-arold, aliases need to be stored in config file to be persisted.

I have my aliases in the config/aliases file and they don't work from Cmder. This is how this file looks like:

gcb="./gradlew clean build --parallel"
gfb="./gradlew assemble --parallel"

What could be the problem?

@adam-arold Do you have a %cmder_root%configuser-aliases.and file? Never versions of cmder 1.3.2+, I think, store aliases in this file.

@adam-arold The alias command run in 'cmder' shell based on cmd.exe should write the alias to the file I mentioned in my last post preserving it for future sessions.

If using a 'bash' shell aliases created using the alias command are not saved unless you manually add them to '%cmder_root%/config/user-aliases.sh'

Since your aliases contain / and you say aliases are not preserved across sessions I assume you are using a bash shell.

I have the user-aliases.sh file and the aliases are in it but they don't work.

@adam-arold. File content?

Should look something like:

alias aliasname='cmd args'
alias aliasname2='cmd2 args2'
ga=git add .
gc=git commit -am
gpm=git push origin
gpl=git pull origin

is this possible?

gpm myrepo
gc "something"

For some reason the alias command did not add the alias prefix to the entries in the user-aliases.sh so I ended up adding them by hand. Now it works, thanks!

@adam-arold All is working as expected. The alias command in bash sets an alias for the running session only. To make it permanent and cmder portable you add it manually to the file I told you about. If you are not worked about it being portable the bash way would be to manually add it to the ~/.bashrc file.

I have the user-aliases.cmd file and my aliases are in there. However, I cannot use any of the aliases in Cmder. Not even the default ones like e..

@xelra what version of cmder? If not latest, download the latest and follow the upgrade procedure in the readme.md.

@daxgames Thanks that fixed it. For some reason I was under the impression that Cmder was updating automatically.

@justinlazaro-ubidy did you find solution ?

Most examples/snippets I read included quotes when setting aliases.
That did not work for me. Solution:

Don't

alias gcm='git checkout master'

Do

alias gcm=git checkout master

How about passing the arguments on to the aliased command?

alias gd=git diff

Use it like:

gd --staged

@maxpower9000 the "don't" is syntax for linux/Unix

The "do" is syntax for 'cmder' command alias.bat

@jakoandersen is that a question? If so, Cmder aliases in cmd based shells are based on doskey. See the doskey macro docs details on how to do advanced aliases.

I'm using Cmder Version 180528

In \cmder\vendor\, there is a file called user-aliases.cmd.example, it contains the following:

;= @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 ;= Add aliases below here e.=explorer . gl=git log --oneline --all --graph --decorate $* ls=ls --show-control-chars -F --color $* pwd=cd clear=cls gg=cls history=cat "%CMDER_ROOT%\config\.history" unalias=alias /d $1 vi=vim $* cmderr=cd /d "%CMDER_ROOT%"
I duplicated this file and rename the duplicated file to user-aliases.cmd.

That is, I now have a \cmder\vendor\user-aliases.cmd

I add ll=ls -al to the last line of the file. Save it.

But in Cmder, I still cannot use the command ll. What am I doing wrong?

The *.example it's supposed to be copied to the config folder and named what you named it on first launch if it doesn't already exist. If that didn't happen there's probably a bug in the init.bat. if you copy it there manually you should start having some default aliases

@daxgames Thanks for the tips.

Instead of \cmder\vendor\user-aliases.cmd, which does not work.

Now I have \cmder\config\user-aliases.cmd, which is working, thanks you.

I have %cmder_root%configuser-aliases.cmd. It came pre-installed with Laragaon but none of the aliases in it work. vendorinit.bat does seem to be trying to load it.

When I do alias vi=vim on the command line, vi continues to not work.

The solution that seemed to have worked (cmder ^v1.3.6)

Open up the following in your text editor:
_CMDER_ROOT_/config/user-aliases.cmd

Extend the file by appending aliases you need:

;= @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
;= Add aliases below here
e.=explorer .
gl=git log --oneline --all --graph --decorate  $*
ls=ls --show-control-chars -F --color $*
pwd=cd
clear=cls
history=cat "%CMDER_ROOT%\config\.history"
unalias=alias /d $1
vi=vim $*
cmderr=cd /d "%CMDER_ROOT%"

ll=ls -la

Hope this helps you guys!

Kalpesh Panchal

https://github.com/cmderdev/cmder/issues/421#issuecomment-364017376
@justinlazaro-ubidy

Totally possible just use $*
e.g.
gpm=git push origin $*
gc=git commit -am $*

Not sure if I am being thick (most likely cause its late) but im trying to add alias k=kubectl
It is in the config file but i get error. Also the e. does not work either?

馃啒 Help 馃啒

image

--Edit
I just realised the user_aliased.cmd is for the command and I am running in PowerShell... so I used PowerShell Set-Alias which worked. Maybe will help another noob later 馃崪

How about passing the arguments on to the aliased command?

alias gd=git diff

Use it like:

gd --staged

This didn't work out for me.
I'd like to create an alias where I could pass the parameter manually.
alias r=php artisan migration:refresh
So when I run r --seed the console just count the r without the parameter --seed
Can someone help me with this?

I think there is a misunderstanding with what to put it in the aliases file.
if you put alias ll=ls -la it doesn't seem to work because of the preceding alias flag. It's already in the aliases file. Just put any command you want to create an alias to with a preferred name into cmder/config/user-aliases.cmd like this ll=ls -al save the file restart cmder.

Cmder cmd session aliases are based on doskey. Look there for syntax.

Also no need to restart cmder, just execute user_aliases.cmd if you edit it directly.

In case anyone still strugling with creating aliases for bash shell, adding them to %cmder_root%/config/user_profile.sh with this syntax alias la='ls -la' worked for me.

Hi @daxgames and everyone!

Having issues - I'm using Bash / Ubuntu distribution {WSL::bash}. Running cmder out of my downloads folder at the moment /mnt/c/users/Laptop/Downloads/cmder. I run that executable. Certain default aliases work - for example, clear=cls does clear my screen. however, changes to user-aliases.sh or user-aliases.cmd don't have any effect. If I switch clear to clear1, clear is still the working command.

It seems to be referencing a different user-aliases file tahtn what i'm changing. Thoughts?

I'm modding:
%CMDER_ROOT%/config/user-aliases.sh
%CMDER_ROOT%/config/user-aliases.cmd

Thanks in advance.

@bholmquist11 WSL Bash is technically an external *nix env according to cmder. You have two choices:

  1. Add aliases to your ~/.bashrc or ~/.bash_profile

    • _Note: These aliases are not portable and are specific to this machine_

  2. See this in the README.md.

Thanks @daxgames!

hey guys I just installed cmder on windows 7 and i am trying to make this command work, could you help me out!?

dhall-to-json` --pretty <<< '[ ./example.dhall, ./example.dhall ]'

it says that << can not be used here. I am in a cmd.exe tab

Found it in the _"Creating a macro"_ section in doskey

$1 through $9 | Represent any command-line information you want to specify when you run the macro. The special characters聽$1聽through聽$9are batch parameters that enable you to use different data on the command line each time you run the macro. The聽$1character in a聽doskey聽command is similar to the聽%1聽character in a batch program.
-- | --
$* | Represents all the command-line information that you want to specify when you type the macro name. The special character聽$* is a replaceable parameter that is similar to the batch parameters聽$1聽through聽$9, with one important difference: everything you type on the command line after the macro name is substituted for the聽$* in the macro.

@jakoandersen @Zontir this worked from me

alias g=git $*
# or 
alias gd=git diff $*

In case anyone still strugling with creating aliases for bash shell, adding them to %cmder_root%/config/user_profile.sh with this syntax alias la='ls -la' worked for me.

After quite a bit of searching this is the one that did it for me in cmder bash. Thank you! Duplicating the user-aliases file as user-aliases.sh did nothing.

Note for others - you still need to restart the active console to have your changes apply.

Didn't see anyone commenting about this option so here it is... If you're using bash, from git for windows for exemple, you can add your alias to the alias.sh file in "cmdervendorgit-for-windowsetcprofile.d" with this sintax:
E.g: alias dev='cd E:/Files/Projetos && code'

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Joe1992w picture Joe1992w  路  3Comments

edgariscoding picture edgariscoding  路  3Comments

sathishsoundharajan picture sathishsoundharajan  路  3Comments

danwellman picture danwellman  路  3Comments

brunowego picture brunowego  路  3Comments