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

How do you create an alias? #421

Closed
notflip opened this issue Mar 13, 2015 · 44 comments
Closed

How do you create an alias? #421

notflip opened this issue Mar 13, 2015 · 44 comments

Comments

@notflip
Copy link

notflip commented Mar 13, 2015

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

@r3Fuze
Copy link

r3Fuze commented Mar 13, 2015

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

@notflip
Copy link
Author

notflip commented Mar 13, 2015

Perfect! Thank you very much

@MartiUK MartiUK closed this as completed Mar 13, 2015
@power-media
Copy link

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.

@adam-arold
Copy link

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

@power-media
Copy link

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

@adam-arold
Copy link

adam-arold commented Feb 2, 2018

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?

@daxgames
Copy link
Member

daxgames commented Feb 3, 2018

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

@daxgames
Copy link
Member

daxgames commented Feb 3, 2018

@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.

@adam-arold
Copy link

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

@daxgames
Copy link
Member

daxgames commented Feb 4, 2018

@adam-arold. File content?

Should look something like:

alias aliasname='cmd args'
alias aliasname2='cmd2 args2'

@justinlazaro-ubidy
Copy link

ga=git add .
gc=git commit -am
gpm=git push origin
gpl=git pull origin

is this possible?

gpm myrepo
gc "something"

@adam-arold
Copy link

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!

@daxgames
Copy link
Member

daxgames commented Feb 8, 2018

@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.

@xelra
Copy link

xelra commented Feb 12, 2018

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..

@daxgames
Copy link
Member

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

@xelra
Copy link

xelra commented Feb 12, 2018

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

@developandbehappy
Copy link

@justinlazaro-ubidy did you find solution ?

@maxpower9000
Copy link

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

@jakoandersen
Copy link

How about passing the arguments on to the aliased command?

alias gd=git diff

Use it like:

gd --staged

@daxgames
Copy link
Member

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

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

@daxgames
Copy link
Member

@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.

@johnyluyte
Copy link

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?

@daxgames
Copy link
Member

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

@johnyluyte
Copy link

@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.

@Stanzilla
Copy link
Member

Stanzilla commented Jun 26, 2018

@theyak
Copy link

theyak commented Jul 28, 2018

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

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

@panchalkalpesh
Copy link

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

@rakismelange
Copy link

rakismelange commented Sep 3, 2018

#421 (comment)
@justinlazaro-ubidy

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

@p10tyr
Copy link

p10tyr commented Nov 22, 2018

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 🍜

@mreduar
Copy link

mreduar commented Nov 24, 2018

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?

@dalwar23
Copy link

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.

@daxgames
Copy link
Member

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.

@veex-ua
Copy link

veex-ua commented Dec 26, 2018

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.

@bholmquist11
Copy link

bholmquist11 commented Jan 31, 2019

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.

@daxgames
Copy link
Member

@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.

@bholmquist11
Copy link

Thanks @daxgames!

@3nigm4
Copy link

3nigm4 commented Apr 9, 2019

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

@mshaaban0
Copy link

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 $*

@ryan-mccartney
Copy link

ryan-mccartney commented Oct 16, 2019

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.

@andrehgdias
Copy link

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 "cmder\vendor\git-for-windows\etc\profile.d" with this sintax:
E.g: alias dev='cd E:/Files/Projetos && code'

@abhijit-hota
Copy link

abhijit-hota commented Mar 9, 2021

Is there any way to pass default arguments?

I have the alias ngk=ngrok http $* and I have to pass the arguments (here, the port) as ngk 3000. Can I set some defaults such that when I just call ngk then it starts as ngk 3000?

P.S. I could make a separate alias but just wanted to know.

@daxgames
Copy link
Member

daxgames commented Mar 9, 2021

@abhijit-hota you sould set an environment variable in %CMDER_ROOT%\config\user_profile.cmd and add that to the alias or you could create a separate alias.

@chrisant996
Copy link
Contributor

Is there any way to pass default arguments?

I have the alias ngk=ngrok http $* and I have to pass the arguments (here, the port) as ngk 3000. Can I set some defaults such that when I just call ngk then it starts as ngk 3000?

P.S. I could make a separate alias but just wanted to know.

These are doskey aliases. See doskey /? for help, and also a lot of information and samples are available via internet searches.

Doskey aliases don't have default values for arguments. A .cmd script could be written to check for a missing argument and provide a default value. A doskey alias can't do that on its own, though.

@abhijit-hota
Copy link

@chrisant996 Thanks for clarifying!

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

No branches or pull requests