Useful tips for Cmder - Windows command line replacement

mareksamec

mareksamec

Posted on December 25, 2019

Useful tips for Cmder - Windows command line replacement

Do you think the Windows command line aka CMD would use some more features? Or what's worse, you are used to Linux command line and now you have to work under Windows? Don't lose hope, Cmder can help you out!

There are plenty of good intro articles about Cmder so I will jump right to some of the features that I like the most because they significantly boost my productivity under the Windows environment.

This article will cover the following:

  1. How to reload (source your Cmder config file aka something like .bashrc reload)
  2. How to use command aliases + tips
  3. Using fzf fuzzy search*

Reloading (sourcing) Cmder config files (aliases, profile etc):

This is similar to sourcing a .bashrc file after you edit it. The easy way this is to run the init.bat which is usually located in the vendor folder which can be found in the Cmder root folder. The profile files will be reloaded during the Cmder init. The default location of the profile files is in the config folder. For CMD it is the user_profile.cmd file. Cmder creates windows variable %CMDER_ROOT% which references the Cmder root. You should be able to reload the init script with this command:



%CMDER_ROOT%\vendor\init.bat


Enter fullscreen mode Exit fullscreen mode

In case this would not work for some reason, you can call the script by using its absolute path. Let's say your Cmder is installed in:
C:\Cmder\

Then you can simply call:



 C:\Cmder\vendor\init.bat


Enter fullscreen mode Exit fullscreen mode

It is also very useful to set up an alias for this, do it quickly. The user alias config is usually stored in this path:
%CMDER_ROOT%\config\user_aliases.cmd

Open it in your favorite text editor and add this line:
init=%CMDER_ROOT%\vendor\init.bat

Save the file and restart the Cmder, or call init.bat as shown above. Now, whenever you type "init" in the Cmder command line. All the configs should be reloaded. Keep in mind that if you have two instances (tabs) with Cmder open, the config will be reloaded only in the window where you called the init from.

Alt Text

More alias tips

Alias file works similar to Linux bash aliases but the syntax is a bit different. Simple aliases can be assigned like this:



lt=ls -lstr --color=auto


Enter fullscreen mode Exit fullscreen mode

For commands that include paths (especially when some of the folder\file names have spaces in them) you need to use double quotes like this:



help=cat "%CMDER_ROOT%\config\hotkeys-marek.txt"
gowork=cd "C:\Users\marek\Documents\Work"


Enter fullscreen mode Exit fullscreen mode

The second alias above is a simple cd to my work folder. For the cd command to work properly you need to use double-quotes. When you want to launch some file using let's say Adobe Acrobat which is installed in the Program Files you can do it like this:



fieldman="C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" "C:
    \Users\marek\Documents\Documentation\manuals\field-manual.pdf"


Enter fullscreen mode Exit fullscreen mode

Fast searching with fzf

Yes, fzf can work in Cmder too. You can use it for fast fuzzy command line searches. If you don't know fzf, check the project git here: https://github.com/junegunn/fzf . Windows binaries can be found in the project releases page here: https://github.com/junegunn/fzf-bin/releases.

There are two ways to install the fzf. A simple way is just to copy fzf.exe to the Cmder "bin" folder. You can find this folder in the Cmder root directory e.g. C:\Cmder\bin\ . Every binary in that folder will be automatically added to the Cmder PATH variable. Alternatively, you can download it somewhere else and add the line below to your user_profile.cmd file. Let's say you have cloned the fzf to the Apps directory in your Documents (it is assumed that you have folder fzf there which contains file fzf.exe):



set "PATH=%USERPROFILE%\Documents\Apps\fzf;%PATH%"


Enter fullscreen mode Exit fullscreen mode

For fzf to work the windows TERM variable must not be set. It can be done by simply adding the following line to your profile file:



set TERM=


Enter fullscreen mode Exit fullscreen mode

Keep in mind that unsetting the TERM variable can cause some issues, for instance, if you connect to a remote Linux server via Cmder built-in ssh.

I hope these tips were useful, feel free to add more down in the comments. Stay tuned for more productivity-related articles for both Linux and Windows!

💖 💪 🙅 🚩
mareksamec
mareksamec

Posted on December 25, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related