cmder icon indicating copy to clipboard operation
cmder copied to clipboard

How do you create an alias?

Open notflip opened this issue 11 years ago • 48 comments

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

notflip avatar Mar 13 '15 09:03 notflip

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?

johnyluyte avatar Jun 25 '18 03:06 johnyluyte

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 avatar Jun 25 '18 23:06 daxgames

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

johnyluyte avatar Jun 26 '18 02:06 johnyluyte

Does that look wrong? https://github.com/cmderdev/cmder/blob/master/vendor/init.bat#L253

Stanzilla avatar Jun 26 '18 10:06 Stanzilla

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.

theyak avatar Jul 28 '18 16:07 theyak

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

panchalkalpesh avatar Aug 21 '18 20:08 panchalkalpesh

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

rakismelange avatar Sep 03 '18 01:09 rakismelange

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 🍜

p10tyr avatar Nov 22 '18 21:11 p10tyr

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?

mreduar avatar Nov 24 '18 04:11 mreduar

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.

dalwar23 avatar Nov 28 '18 08:11 dalwar23

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.

daxgames avatar Nov 28 '18 13:11 daxgames

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.

veex-ua avatar Dec 26 '18 15:12 veex-ua

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 avatar Jan 31 '19 15:01 bholmquist11

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

daxgames avatar Jan 31 '19 18:01 daxgames

Thanks @daxgames!

bholmquist11 avatar Feb 02 '19 01:02 bholmquist11

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

3nigm4 avatar Apr 09 '19 09:04 3nigm4

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

mshaaban0 avatar Jun 06 '19 21:06 mshaaban0

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.

ryan-mccartney avatar Oct 16 '19 23:10 ryan-mccartney

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'

andrehgdias avatar Aug 07 '20 11:08 andrehgdias

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.

abhijit-hota avatar Mar 09 '21 04:03 abhijit-hota