Skip to content

Instantly share code, notes, and snippets.

@danielcarr
Last active January 3, 2023 10:45
Show Gist options
  • Save danielcarr/282ab2771b964efb88ecf5113f960f82 to your computer and use it in GitHub Desktop.
Save danielcarr/282ab2771b964efb88ecf5113f960f82 to your computer and use it in GitHub Desktop.
Mac bash profile
# This file would be identical to .profile and isn't needed in addition, it just makes the gist more findable
# .profile is called if bash will be invoked with the name `sh`, so it's more portable
# The same or a similar file might also be named .bashrc (for a non-login interactive shell invocation)
# See the section INVOCATION of `man bash` for the technical nuances of when to use which filename
alias python=python3
# Setup Homebrew Environment
eval `/opt/homebrew/bin/brew shellenv`
# SET PROMPT
# \[ \] escapes the colour codes so that they don't get counted in the prompt length
# and the prompt works correctly with history etc
# \e = escape character to start a colour code (= \033)
# [2 = dimmed
# \u = username
# [0;37 = normal, white
# [93 = bright yellow
# $(`command -v __git_ps1 >/dev/null` && __git_ps1 ) if git-prompt is available, inserts the git status when in a git repository
# [2;36 = dim cyan / teal
# [%s] = the git status (eg the branch), surrounded by brackets
# [0 = normal (it seems to be necessary to unset the colours so that setting them to white works)
# \w = directory
# [1;97 = bold, bright white
# [0 = normal
# see man bash#PROMPTING for more
# The user remains (but dimmed) to not forget when I'm in sudo,
# the directory is highlighted so I don't accidentally run commands in the wrong project directory
# (eg pulling a git branch and then wondering why there's nothing new)
# The git status information is shown in a distinguishable but unintrusive colour
# (the git-prompt script may also set colours and other information)
export PS1='\[\e[2m\]\u\[\e[0;37m\]@\[\e[93m\]\w$(`command -v __git_ps1 >/dev/null` && __git_ps1 "\[\e[2;36m\] [%s]\[\e[0m\]")\[\e[1;97m\]$\[\e[0m\] '
#! /usr/bin/env sh
# Add personal scripts to path
export PATH="~/.local/bin/:${PATH}"
# Load all configuration files
for config in "${HOME}"/.bashrc.d/*.bash ; do
. "$config"
done
unset -v config
To get git completion and git branch information in the prompt, download the following files into the .bashrc.d/ directory:
https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment