Skip to content

Instantly share code, notes, and snippets.

@d8vjork
Last active February 25, 2022 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d8vjork/2f34286e24c522ce5b47c5999bfa3549 to your computer and use it in GitHub Desktop.
Save d8vjork/2f34286e24c522ce5b47c5999bfa3549 to your computer and use it in GitHub Desktop.
Bonjour (First Mac installation tailored by me @d8vjork)

Summary

  1. First installations
  2. How to use FNM: Node version manager
  3. How to use Antigen: Zsh themes and plugins manager
  4. As part of your daily routine
  5. Credits

First installations

Install Homebrew: https://brew.sh/

Note: Homebrew installer also installs the XCode Console Tools for you, so sit back and relax.

Then run this command on your Terminal:

brew install php fnm gh composer htop telnet wakeonlan wget antigen coreutils nmap qcachegrind

This will install a couple of very useful tools for your web development (as always with Homebrew, on their latest versions).

And this other stuff:

brew install --cask docker ksdiff iterm2

Now you have installed a couple of visual (GUI) apps like Docker for work with containers, iterm2 to work with multiple splitted terminals, etc.

How to use FNM: Node version manager

How to use Antigen: Zsh themes and plugins manager

In my personal Mac I've used Spaceship ZSH for quite a while ago now, and I'm very use to it (also it looks great!)

Terminal setup

First, here is my .zshrc:

nano ~/.zshrc

source ~/.commonrc

# OSX antigen file
source /usr/local/Cellar/antigen/2.2.3/share/antigen/antigen.zsh

# Load the oh-my-zsh's library.
antigen use oh-my-zsh

# Load the theme
antigen theme denysdovhan/spaceship-prompt

# Bundles from the default repo (robbyrussell's oh-my-zsh).
antigen bundle git
antigen bundle heroku
antigen bundle pip
antigen bundle lein
antigen bundle command-not-found
antigen bundle common-aliases
antigen bundle compleat
antigen bundle git-extras
antigen bundle git-flow
antigen bundle npm
antigen bundle web-search
antigen bundle z
antigen bundle zsh-users/zsh-syntax-highlighting
antigen bundle zsh-users/zsh-history-substring-search ./zsh-history-substring-search.zsh
antigen bundle zsh-users/zsh-completions
antigen bundle jessarcher/zsh-artisan

# Syntax highlighting bundle.
antigen bundle zsh-users/zsh-syntax-highlighting

# Tell Antigen that you're done.
antigen apply

# Setup zsh-autosuggestions
source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh

# Tell Antigen that you're done.
antigen apply

# Setup zsh-autosuggestions
source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh

# Tell to Zsh that dotted files are included on wildcards (*)
setopt dotglob

# Spaceship zsh theme config
export SPACESHIP_EXEC_TIME_SHOW=false

# Editor for Artisan autocompletion plugin
ARTISAN_OPEN_ON_MAKE_EDITOR=code

# Last exec time functions (in ms)
function preexec() {
  timer=$(($(gdate +%s%0N)/1000000))
}

function precmd() {
  if [ $timer ]; then
    now=$(($(gdate +%s%0N)/1000000))
    elapsed=$(($now-$timer))

    export RPROMPT="%F{cyan}${elapsed}ms %{$reset_color%}"
    unset timer
  fi
}

As you can see, there's some shared files between Zsh and Bash, the reason behind this is that sometimes some apps or CLIs they want to stick to my Bash terminal, and if I wanna use some tools like PHP I won't probably have access to them (the ones we installed with Brew)

Anyway, here they are:

nano ~/.commonrc

# Bash-alike PATH attachments
export PATH="${PATH}:${HOME}/bin"
export PATH="${PATH}:${HOME}/.composer/vendor/bin"
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"

# fnm
eval "$(fnm env)"

# Some useful envvars
export COMPOSER_MEMORY_LIMIT=-1
export DBGP_IDEKEY="VSCODE"

export PATH="/usr/local/opt/icu4c/bin:$PATH"
export PATH="/usr/local/opt/icu4c/sbin:$PATH"
export PKG_CONFIG_PATH=/usr/lib/pkgconfig
export LIBXML_CFLAGS=-I/usr/local/opt/libxml2/include
export LIBXML_LIBS=-L/usr/local/opt/libxml2/lib
export GUILE_LOAD_PATH="/usr/local/share/guile/site/3.0"
export GUILE_LOAD_COMPILED_PATH="/usr/local/lib/guile/3.0/site-ccache"
export GUILE_SYSTEM_EXTENSIONS_PATH="/usr/local/lib/guile/3.0/extensions"
export GUILE_TLS_CERTIFICATE_DIRECTORY="/usr/local/etc/gnutls/"
export PATH="/usr/local/sbin:$PATH"
export PHP_CS_FIXER_IGNORE_ENV=true

# Load custom aliases
[[ -s "$HOME/.bash_aliases" ]] && source "$HOME/.bash_aliases"

nano ~/.bashrc

source ~/.commonrc

# Shell prompt.
# username@hostname:path$
PS1="\[\e]0;\u@\h: \w\a\]\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ "

# Remove ZSH default warning when using Bash on macOS.
export BASH_SILENCE_DEPRECATION_WARNING=1

# Tell to Bash to copy/move/etc dotted files
shopt -s dotglob

nano ~/.bash_aliases

alias ..="cd .."
alias cd..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ~="cd ~" # `cd` is probably faster to type though
alias -- -="cd -"

alias gitclean='git branch --merged | egrep -v "(^\*|master|develop)" | xargs git branch -d && git remote prune origin'
alias dockerclean='docker stop $(docker ps -aq) && docker rm $(docker ps -a -q) -f'
alias dockerwash='docker rmi $(docker images -q)'
alias dockerstop='docker stop $(docker ps -a -q)'
alias dockerkill='docker kill $(docker ps -q)'
alias dockerprune='docker system prune --all --force --volumes'
alias dockerreset='docker stop $(docker container ls -a -q) && docker system prune -a -f --volumes'
alias gs='git status'
alias gl='git log'
alias gaa='git add .'
alias gc='git commit -m '
alias ls='ls -GFh'
alias gg='lazygit'
alias lzd='lazydocker'
alias edit='ox'
alias vapor='php vendor/bin/vapor'
alias sail='bash vendor/bin/sail'
alias artisan='php artisan'
alias art='php artisan'

function tinker() {
  if [ -z "$1" ]
    then
       while true; do php artisan tinker; done
    else
       php artisan tinker --execute="dd($1);"
  fi
}

Restart your terminal and this is how it should look like:

image

And on a project with git/php/docker/etc:

image

Explaining all of those settings

As part of your daily routine

Update some brew stuff that you previously install:

brew update; brew outdated

What this will do is update references (what's called formulae in Homebrew), and list all the formulae that got outdated (of your installed stuff)

Then you upgrade those you need with this:

brew upgrade php composer fnm

Also to run brew doctor if you've any other problems with Brew or the packages you installed with it.

Remember to JUST upgrade the stuff you really need, that's why I just wrote down here those 3 as an example.

Also remember to reinstall all the extensions and config on your php.ini

Credits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment