Bashisms
Last update:
Reading time: less than a minute
Some random details on setting up modern bash
on macOS.
Setting up Bash on macOS
-
Install a modern version of
bash
withbrew
$ brew install bash
-
Add
bash
binary to/etc/shells
$ echo "$(brew --prefix)/bin/bash" | sudo tee -a /etc/shells
- Change shell
$ chsh -s "$(brew --prefix)/bin/bash"
- Update hostname
sudo scutil --set HostName "macbook"
Aliases, Functions, Etc.
Some aliases I use regularly
- write - switch to blog directory, build html, and launch simple python web server
alias write='cd ./wcameronbowen.com && soupault && python3 -m http.server --directory build'
- awsl - login to awscli with iam identity center
awsl () {
aws sso login --profile $1
export AWS_PROFILE=$1
}
-
vim - I got used to using
vim
and then switched toneovim
alias vim='nvim'
- random hex - handy random hex strings
alias hexr='hexdump -vn4 -e'\''4/4 "%08X" 1 "\n"'\'' /dev/urandom'
- short dig - dig, but shorter
alias digs='dig +short'
- go back - go back to the previous directory
alias b='cd -'
- pyvenv - switch to python virtual environment or create one
pyvenv () {
if [ -d ./venv ]; then
source venv/bin/activate
elif [ -d ./env ]; then
source env/bin/activate
else
python3 -m venv venv && source venv/bin/activate
fi
}
-
de - shorter than typing
deactivate
when in python virtual environment
alias de='deactivate'
- myip - get my public ip
alias myip='curl -4s ipconfig.io'
-
bash prompt -
time | hostname | working wirectory | git branch | new line
export PS1='$(exitcode)\e[1m\A \e[0m\h\e[0m [\w]$(__git_ps1 " %s")\e[0m\n\$ '
Hope these help you too!