Configuring aliases in iTerm on Mac and Cmder on Windows in Parallels

Aliases are a handy way to quickly execute certain commands in the terminal on Mac and in the command prompt on Windows. I recently read this post about git aliases which nicely demonstrates what is possible, it focuses on git commands but it can be done for any type of command.

I develop both on Mac and Windows, the Windows running via Parallels. On Mac I use iTerm as terminal replacement and use fish as command line shell. The ultimate goal was to have the configuration files committed to a GIT repository, so they could be applied when changing or reinstalling computers without too much hassle. Let's start with configuring the aliases on Mac first.

Fish on Mac

Aliases for fish can be defined in the ~/.config/fish/config.fish file. If it does not exist you can create is. This is the content of my current configuration file:

# GIT aliases
alias gac="git add -A; and git commit -v"
alias gs="git status"

alias gp="git push"
alias gpo="git push origin"
alias gpom="git push origin master"

alias gl="git pull"
alias glo="git pull origin"
alias glom="git pull origin master"

alias gb="git branch"
alias gc="git checkout"

The configuration resides in the folder where the GIT repository is cloned. I'd rather not copy over the file to the fish configuration directory. That way I can easily commit files to the GIT repo whenever an alias is added. Let's create a symlink from the GIT repository to the correct folder. This way every time an alias is added in the repository, it is picked up by fish and can be used in the terminal.

ln -s ~/Projects/terminal-settings/fish/config.fish ~/.config/fish/config.fish

After restarting iterm, the aliases now work.

Cmder on Windows in Parallels

I run my Windows in Parallels and there I use Cmder, it can be a little slow but it's the best console emulator on Windows I've found. I'd like to use the same aliases as those that are defined in fish to execute commands. The syntax to define aliases is a bit different, this is their definition:

;= @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%"

;= GIT aliases

gac=git add -A && git commit -v
gs=git status

gp=git push
gpo=git push origin
gpom=git push origin master

gl=git pull
glo=git pull origin
glom=git pull origin master

gb=git branch
gc=git checkout

Cmder picks up the aliases from a file called user-aliases.cmd the first few lines are standard in this file. The newly defined GIT aliases start after the ;= GIT aliases comment line.

I'd rather not checkout the GIT repository again on Windows so I would like to use the shared folder from Mac in Windows and symlink the user-aliases.cmd file to the correct place on Windows. In order to do this you need to run a command prompt with administrator rights and execute the following command:

fsutil behavior set SymlinkEvaluation L2R:1

If you don't do this, linking the file from the network share in Windows will fail. When this has finished the file can be linked from Mac to the correct folder in Windows where Cmder resides. Cmder picks up the aliases from config\user-aliases.cmd relative to where the exe of Cmder is placed.

mklink "C:\tools\cmder\config\user-aliases.cmd" "Y:\Projects\terminal-settings\cmder\user-aliases.cmd"

After restarting Cmder, we can now use the aliases. I like this clean way of configuring aliases in both environments. If you're interested check out the repository with my terminal settings, keep in mind that it is work in progress.