Dealing with PATH, Bash Profiles, Git config in Windows

This post serves as a convenience for me and possibly others (probably not because nobody develops on windows) on how to manage working within Git Bash and Command Line in general within Windows 10. It can be a real pain in the neck to develop on Windows. (Updated for 11 in 2023!)

I primarily use Windows because my life is between software and business.

XKCD #763

Git Bash Notes

Windows PATH Tips/Instructions:

  • Control Panel > System > Advanced > Environment Variables
  • Edit Path to add a folder or System Variable
    • Add a folder: Point the resource you need by adding a folder path without the .exe
    • Add a System Variable: First point the directory and assign a variable name by adding to the System Variables. Next append the name of the variable to the Path ( ex. %JAVA%; ).
  • Windows Environment Variable added without restarting (ha): https://serverfault.com/questions/8855/how-do-you-add-a-windows-environment-variable-without-rebooting
    Or you know, just fucking reboot
  • Add things for convenience like c:/eclipse/ and then simply type eclipse to open the IDE

.bash_profile Examples:

https://www.tldp.org/LDP/abs/html/sample-bashrc.html

# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# Suppress message about using zsh
export BASH_SILENCE_DEPRECATION_WARNING=1
# ————————————
# MOTD (Message of the Day)
# What you see when Terminal opens
# ————————————
echo "—————————-"
echo "Loaded ~/.bash_profile"
echo ""
echo "To edit run: configedit"
echo "To refresh run: configrefresh"
echo "All aliases: alias"
echo "—————————-"
# ————————————
# Configure prompt
# Includes special handling for git repos
# ————————————
# Regular Colors
Black='\[\033[0;30m\]'
Red='\[\033[0;31m\]'
Green='\[\033[0;32m\]'
Yellow='\[\033[0;33m\]'
Blue='\[\033[0;34m\]'
Purple='\[\033[0;35m\]'
Cyan='\[\033[0;36m\]'
White='\[\033[0;37m\]'
Light_Gray='\[\033[0;37m\]'
# Reset colors
NONE='\[\033[0;0m\]'
# When in a git repo, this method is used to determine the current branch
function parse_git_branch {
git branch 2>/dev/null | grep '^*' | sed 's_^..__' | sed 's_\(.*\)_(\1)_'
}
# When in a git repo, this method is used to determine if there are changes
# Changes will be indicated in the prompt by a *
function git_dirty {
if [[ -n $(git status -s –ignore-submodules=dirty 2> /dev/null) ]]; then
echo "*"
else
echo ""
fi
}
# Design the prompt
export PS1="$Purple\w$NONE \$(parse_git_branch)$Red \$(git_dirty) $NONE\$ "
# \w shows the current path
# List of other placeholders you can use:
# http://www.gnu.org/software/bash/manual/bash.html#Controlling-the-Prompt
# ————————————
# ALIASES
# ————————————
# Edit .bash_profile
alias configedit='code ~/.bash_profile'
# Force terminal to recognize changes to .bash_profile
alias configrefresh='source ~/.bash_profile'
# Ideal directory listing
alias ll="ls -laFG"
# Ask before removing files
alias rm='rm -i'
# Add your own aliases here…
view raw .bash_profile hosted with ❤ by GitHub

My .bash_profile:

# go to the root directory of my development environment on startup
cd 'C:\dev'

# set aliases for commonly used applications
alias np='start notepad++'
alias c='code .'
alias dock='docker-compose up'
alias dockb='docker-compose.exe run app --entrypoint run build:dev'
alias histg='history | grep'
alias g='git'

# save history and persist across multiple bash windows
export HISTCONTROL=ignoredups:erasedups
shopt -s histappend
export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a; history -c; history -r"

SSH – I no longer use this (2023) as I now run the service via Windows:


# ssh things
env=~/.ssh/agent.env

agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }

agent_start () {
(umask 077; ssh-agent >| "$env")
. "$env" >| /dev/null ; }

agent_load_env

# optional SSH key handling
# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
# agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)

if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
agent_start
ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
ssh-add
fi

unset env

My .gitconfig

[color "diff"]
meta = yellow bold
[alias]
st = status
ch = checkout
co = commit
s = status
p = pull
d = diff