Add Aliases
One of the first hacks I performed was to add an alias so that when I type “code” in the terminal VS Code opens.
# Navigate to the home directory and open the .bashrc file cd ~ nano .bashrc # Scroll down to the bottom or a section that includes information about alias and add an alias to the location where VS Code is installed on your machine alias code='/mnt/c/Program\ Files\ \(x86\)/Microsoft\ VS\ Code/Code.exe' # Exit and save the file. Then source the file. Ctrl + X y source ~/.bashrc
You can now type “code” to launch VS Code or type “code {path/to/filename} to open a specific file in VS Code from the terminal. Note that you should only do this with files stored in the Windows operating system – in other words, files in the /mnt/c/ directory.
You can add aliases as shortcuts for other tools, or for other commands you commonly execute.
Customize Git Behavior
Enable Auto-completion for Git – Download the git-completion.bash file from the official git source and move the file to your home directory. Add the following lines to your .bashrc file
# Enable tab completion for git source ~/git-completion.bash
Exit and save the file. Then source the file as you did when setting the alias above.
Customize Git Configuration – These are a few other git settings that can be helpful
git config --global push.default upstream git config --global merge.conflictstyle diff3
Customize the prompt
Download the git-prompt.sh file from the official git source and move the file to your home directory. Add the following lines to your .bashrc file
# Set variables for colors green="\[\033[1;32m\]" blue="\[\033[1;34m\]" purple="\[\033[1;35m\]" reset="\[\033[0m\]" # Change command prompt source ~/git-prompt.sh export GIT_PS1_SHOWDIRTYSTATE=1 # '\u' adds the name of the current user to the prompt # '\$(__git_ps1)' adds git branch and status indicator # '\W' adds the name of the current directory export PS1="$purple\u$green\$(__git_ps1)$blue \W $ $reset"
Exit and save the file. Then source the file.
Resources
- Microsoft documentation: Running Windows Tools from WSL
- Article on How to Customize the Bash Prompt
- Article on Changing the Color of the Bash Prompt
Note for Mac users: you can replace references to .bashrc with .bash_profile to make the above settings work on a Mac. Also see these instructions for launching VS Code from the terminal.