Skip to content

Instantly share code, notes, and snippets.

@bendog
Last active March 17, 2025 02:49
Show Gist options
  • Save bendog/b55df6d90385e7dd475b12fbb0b1024f to your computer and use it in GitHub Desktop.
Save bendog/b55df6d90385e7dd475b12fbb0b1024f to your computer and use it in GitHub Desktop.
ZSH setup

setting up zsh

install HomeBrew for Mac

go to https://brew.sh

Note: Be sure to run the commands which brew tells you to run at the end of your brew install!

install and setup zsh

echo $SHELL

if this is zsh go to the next stage, if not check zsh is installed

which zsh

if zsh is found

go to install oh-my-zsh

if zsh is not found, install with brew following the steps below

brew install zsh

to set zsh as your shell use chsh

chsh -s `which zsh`

close and reopen the terminal

install and setup oh-my-zsh

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

install nerd fonts

I use the example of Meslo Nerd Font, feel free to install one you prefer.

Examples can be found here https://www.nerdfonts.com/font-downloads

brew search nerd-font 
# select your fond from that list and install
brew install --cask font-meslo-lg-nerd-font

Note: You may need to restart your mac for these fonts to show up

WARNING: In your Mac Terminal app, make sure you use a nerd font as your font of choice before you continue

install PowerLevel10k

https://github.com/romkatv/powerlevel10k#oh-my-zsh

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

Now, edit the ZSH_THEME in ~/.zshrc file into :

ZSH_THEME="powerlevel10k/powerlevel10k"

then run

source ~/.zshrc

if for some reason you need to re-run your config, you can use this command.

p10k configure

additional zsh tools

Download zsh-autosuggestions :

git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions 

Download zsh-syntax-higlighting :

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting

Edit ~/.zshrc file, find plugins=(git) replace plugins=(git) with :

plugins=(
  # autoswitch_virtualenv
  aws
  git
  zsh-autosuggestions 
  zsh-syntax-highlighting
  )

Reopen your terminal, now you should be able to use the auto suggestions and syntax highlighting.

Setup Python

commands for installing python

brew install python
brew install pyenv
brew install uv poetry

confirm uv and poetry

$ uv --version
uv 0.6.4 (Homebrew 2025-03-03)

$ which uv 
/opt/homebrew/bin/uv

$ poetry --version
Poetry (version 2.1.1)

$ which poetry
/opt/homebrew/bin/poetry

add pyenv settings to ~/.zprofile

cat <<'EOF' >> ~/.zprofile
# PyEnv settings
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
# end of PyEnv settings
EOF

then run source on that file

source ~/.zprofile

update zsh plugins

edit ~/.zshrc and add pyenv and pipenv to the plugins

plugins=(
  # autoswitch_virtualenv
  aws
  git
  pyenv
  uv
  zsh-autosuggestions 
  zsh-syntax-highlighting
  )

Aliases

Do these in a new terminal window

install fancy helper tools for aliases

brew install lsd eza

enable .aliases file

add this line to ~/.zshrc under the aliases section

if [ -f ~/.aliases ]; then
  source $HOME/.aliases
fi

add the aliases to the .aliases file

edit the ~/.aliases file with code ~/.aliases and add these lines

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi
# some more ls aliases
alias ls="lsd"
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias tree='eza --tree --long'

# mac DNS flush
alias flushdnscache='sudo killall -HUP mDNSResponder; sleep 1; echo "macOS DNS Cache Reset"'

alias randompw='openssl rand -base64 8 |md5 |head -c32;echo'

alias tf='terraform'


function ports() {
    netstat -Watnlv | grep LISTEN | awk '{"ps -o comm= -p " $9 | getline procname;colred="\033[01;31m";colclr="\033[0m"; print colred "proto: " colclr $1 colred " | addr.port: " colclr $4 colred " | pid: " colclr $9 colred " | name: " colclr procname;  }' | column -t -s "|"
}

whoseport() {
  lsof -i ":$1" | grep LISTEN
}

function docker_rm_images() {
    docker rmi $2 $(docker image ls | grep $1 | awk '{print $3}'  )  
}

PROJECT_DIR="$HOME/Projects"

function project() {
    local sub_dir="$1"
    local dir="$PROJECT_DIR/${sub_dir}"
    echo "$dir"
    if [[ ! -e "$dir" ]]
    then
        # if dir doesn't exist prompt to create one 
        echo "Doesn't exist, create a new one? [y/N] "
        read confirm
        if [[ ! "$confirm" =~ ^[Yy] ]]
        then
            echo "exit"
            [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
        else
            echo "creating ${dir}"
            mkdir -p "$dir";
        fi
    fi
    cd "$dir"
}

# Git Tools

alias gs='git status'

# git remote rename
function git_remote_rename() {
    local remote="$1"
    local oldname="$2"
    local newname="$3"
    echo "$remote:$oldname -> $remote:$newname"
    if git ls-remote --heads "$remote" \
        | cut -f2 \
        | sed 's:refs/heads/::' \
        | grep -q ^"$newname"$; then
        echo "Error: $newname already exists"
        exit 1
    fi
    git push "${remote}" "${remote}/${oldname}:refs/heads/${newname}" ":${oldname}"
}

function git_remote_bulk_rename() {
    # usage: git_remote_bulk_rename origin CR feature/
    # result: origin:CR-2135 -> origin:feature/CR-2135
    local remote="$1"
    local prefix = "$2"
    local newprefix = "$3"
    echo "${remote}:${prefix}... -> ${remote}:${newprefix}${prefix}..."
    git ls-remote --heads origin \
        | cut -f2 | sed 's:refs/heads/::' \
        | grep ^"${prefix}.*"$ \
        | while read line ; do \
            git_remote_rename "${remote}" "${line}" "${newprefix}${line}" ; \
        done
}

alias git-prune='git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d'

Setup Git

install new git tools

brew install difftastic

ignore all .DS_Store files

echo ".DS_Store" >> ~/.gitignore
git config --global core.excludesFile ~/.gitignore

add git lg alias for better git log

cat <<'EOF' >> ~/.gitconfig
[alias]
    lg = lg1
    lg1 = lg1-specific --all
    lg2 = lg2-specific --all
    lg3 = lg3-specific --all

    lg1-specific = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)'
    lg2-specific = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(auto)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)'
    lg3-specific = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset) %C(bold cyan)(committed: %cD)%C(reset) %C(auto)%d%C(reset)%n''          %C(white)%s%C(reset)%n''          %C(dim white)- %an <%ae> %C(reset) %C(dim white)(committer: %cn <%ce>)%C(reset)' 
[diff]
    external = difft
EOF

Extra tools from homebrew

some extra tooling which would be good from homebrew

brew install aws-cdk aws-sam-cli awscli bat black cmake \
diceware eksctl gh glab httpie iredis isort jq k9s kubernetes-cli \
make openssl pgcli pillow pipx pre-commit rename ruff telnet \
terraform terraform-docs tflint tfsec thefuck trivy vite watch yarn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment