All Posts

Setting up my new Mac PC

1. Configuration Directories

Update ~/.zprofile to setup XDG variables for Configure directories to ~/.config, data to ~/.local, and cache to ~/.cache

# Use ~/.zprofile to set the PATH and EDITOR environment variable
# Config Paths
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_DATA_HOME="$HOME/.local/share"
export XDG_STATE_HOME="$HOME/.local/state"
export XDG_CACHE_HOME="$HOME/.cache” ```

## 2. Git and Developer Tools

```sh
git --version # this will install the dev tools

Configure the git at ~/.gitconfig with following content

[user]
    name = Sudhir Mitharwal
    email = <email@example.com>
[github]
    user = sudkumar
[init]
    # templatedir = ~/.dotfiles/git/templates
[alias]
    # list all aliases
    la = "!git config -l | grep alias | cut -c 7-"
    delete-merged-branches = "!f() { git checkout --quiet master && git branch --merged | grep --invert-match '\\*' | xargs -n 1 git branch --delete; git checkout --quiet @{-1}; }; f"
    diff = diff --ignore-space-at-eol -b -w --ignore-blank-lines
    cnv = commit --no-verify
    pnv = push --no-verify
    co = checkout
    cob = checkout -b
    s = status --short
    ss  = status
    br = branch -v
    addnw = "!sh -c 'git diff -U0 -w --no-color \"$@\" | git apply --cached --ignore-whitespace --unidiff-zero -'"

    # rebase commands
    cont = rebase --continue
    conf = "!git s | grep ^U"

    l = log --graph --pretty=format:'%Cred%h%Creset %C(bold blue)%an%C(reset) - %s - %Creset %C(yellow)%d%Creset %Cgreen(%cr)%Creset' --abbrev-commit --date=relative

    # show what I did today
    day = "!sh -c 'git log --reverse --no-merges --branches=* --date=local --after=\"yesterday 11:59PM\" --author=\"git config --get user.name\"'"

    # show the committers in the last 100 commits, sorted by who has commited the most
    review = "!git log --no-merges --pretty=%an | head -n 100 | sort | uniq -c | sort -nr"

    # order files by number of commits, ascending
    # Written by Corey Haines
    # Scriptified by Gary Bernhardt
    # Show churn for a time range:
    #   $ git churn --since='1 month ago'
    churn = "!f() { git log --all -M -C --name-only --format='format:' \"$@\" | sort | grep -v '^$' | uniq -c | sort | awk 'BEGIN {print \"count\tfile\"} {print $1 \"\t\" $2}' | sort -g; }; f"

    # show all deleted files in the repo
    deleted = "!git log --diff-filter=D --summary | grep delete"

    # create an empty commit
    empty = commit --allow-empty

    # current branch
    cbr = rev-parse --abbrev-ref HEAD

    # submodule shortcuts
    si = submodule init
    su = submodule update
    sub = "!git submodule sync && git submodule update"

    # show number of commits per contributer, sorted
    count = shortlog -sn

    undo = reset --soft HEAD~1
    amend = commit -a --amend

    cleanup = "!git remote prune origin && git gc && git clean -df && git stash clear"

    # rebase the current branch with changes from upstream remote
    update = !git fetch upstream && git rebase upstream/git rev-parse --abbrev-ref HEAD

    # tag aliases
    # show the last tag
    lt = describe --tags --abbrev=0

    # assume aliases
    assume = update-index --assume-unchanged
    unassume = update-index --no-assume-unchanged
    assumed = "!git ls-files -v | grep ^h | cut -c 3-"
    unassumeall = "!git assumed | xargs git update-index --no-assume-unchanged"

    # clean up all
    forget = "!git fetch -p && git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -D"

    # show the most recently touched branches
    recent = "!git for-each-ref --sort='-committerdate' --format='%(color:red)%(refname)%(color:reset)%09%(committerdate)' refs/heads | sed -e 's-refs/heads/--' | less -XFR"
    latest = "!git for-each-ref --sort='-committerdate' --format='%(color:red)%(refname)%(color:reset)%09%(committerdate)' refs/remotes | sed -e 's-refs/remotes/origin/--' | less -XFR"

    # grep commands

    # 'diff grep'
    dg = "!sh -c 'git ls-files -m | grep $1 | xargs git diff' -"
    # diff grep changes between two commits
    dgc = "!sh -c 'git ls-files | grep $1 | xargs git diff $2 $3 -- ' -"
    # 'checkout grep'
    cg = "!sh -c 'git ls-files -m | grep $1 | xargs git checkout ' -"
    # add grep
    ag = "!sh -c 'git ls-files -m -o --exclude-standard | grep $1 | xargs git add --all' -"
    # add all
    aa = !git ls-files -d | xargs git rm && git ls-files -m -o --exclude-standard | xargs git add
    # remove grep - Remove found files that are NOT under version control
    rg = "!sh -c 'git ls-files --others --exclude-standard | grep $1 | xargs rm' -"

    # Kaleidoscope commands
    dkal = difftool -y -t Kaleidoscope
    mkal = mergetool -y -t Kaleidoscope
    remotes = remote -v

    # check out a local copy of a PR. https://gist.github.com/gnarf/5406589
    pr = "!f() { git fetch -fu ${2:-origin} refs/pull/$1/head:pr/$1 && git checkout pr/$1; }; f"
    pr-clean = "!git for-each-ref refs/heads/pr/* --format='%(refname)' | while read ref ; do branch=${ref#refs/heads/} ; git branch -D $branch ; done"
[color]
    diff = auto
    status = auto
    branch = auto
    interactive = auto
    ui = auto
[color "branch"]
    current = green bold
    local = green
    remote = red bold
[color "diff"]
    # from diff-so-fancy
    # https://github.com/so-fancy/diff-so-fancy#improved-colors-for-the-highlighted-bits
    meta = yellow bold
    frag = magenta bold
    commit = yellow bold
    old = red bold
    new = green bold
    whitespace = red reverse

[color "status"]
    added = green bold
    changed = yellow bold
    untracked = red
[color "sh"]
    branch = yellow
[push]
    # push will only do the current branch, not all branches
    default = current
[branch]
    # set up 'git pull' to rebase instead of merge
    # autosetuprebase = always
[diff]
    renames = copies
    mnemonicprefix = true
    compactionHeuristic = true
[difftool]
    prompt = false
[apply]
    # do not warn about missing whitespace at EOF
    whitespace = nowarn
[core]
    pager = less -FXRS -x2
    editor = vim
    whitespace = cr-at-eol
[rerere]
    enabled = true
[gitsh]
    defaultCommand = s
[grep]
    extendRegexp = true
    lineNumber = true
[credential]
	helper = osxkeychain
[difftool "Kaleidoscope"]
    cmd = ksdiff --partial-changeset --relative-path \"$MERGED\" -- \"$LOCAL\" \"$REMOTE\"
[mergetool "Kaleidoscope"]
    cmd = ksdiff --merge --output \"$MERGED\" --base \"$BASE\" -- \"$LOCAL\" --snapshot \"$REMOTE\" --snapshot
    trustexitcode = true
[rebase]
    instructionFormat = "[%an - %ar] %s"
    autoStash = true
[pager]
    diff = "diff-so-fancy | less --tabs=4 -RFX"
    show = "diff-so-fancy | less --tabs=4 -RFX"
[pull]
	rebase = false

3. Antigen: Zsh Plugin Manager

curl -L git.io/antigen > ~/.config/antigen.zsh

Add the following content to ~/.zshrc

# Use ~/.zshrc for aliases and a custom prompt, tweaking the appearance and behavior of the terminal.
# Antigen: The plugin manager for zsh.

if [[ -a ~/.config/antigen.zsh ]]; then
  source ~/.config/antigen.zsh

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

  # Bundles from the default repo (robbyrussell's oh-my-zsh).
  antigen bundle git
  antigen bundle command-not-found

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

  # Load the theme.
  antigen theme robbyrussell

  # Tell Antigen that you're done.
  antigen apply
fi

4. Package Manager: Homebrew

Visit https://brew.sh and install the Homebrew. After installation, add the bin directory in the path as mentioned in the last step after installation.

Install the following packages as well

brew install diff-so-fancy

5. Tmux

  1. Install tmux brew install tmux
  2. Create a config directory for tmux at ~/.config/tmux and create a tmux.conf file in it with the following content:
set-environment -g DOTFILES "$DOTFILES"
# For true RGB color
set-option -sa terminal-overrides ',screen-256color:RGB'


# enable vi mode
setw -g mode-keys vi

# more settings to make copy-mode more vim-like
unbind [
bind Escape copy-mode
bind P paste-buffer
bind -T copy-mode-vi 'v' send-keys -X begin-selection
bind -T copy-mode-vi 'y' send-keys -X copy-pipe-and-cancel "tmux save-buffer - | reattach-to-user-namespace pbcopy"

# Buffers to/from Mac clipboard, yay tmux book from pragprog
bind C-c run "tmux save-buffer - | reattach-to-user-namespace pbcopy"
bind C-v run "tmux set-buffer $(reattach-to-user-namespace pbpaste); tmux paste-buffer"

# Rather than constraining window size to the maximum size of any client
# connected to the session, constrain window size to the maximum size of any
# client connected to that window. Much more reasonable.
setw -g aggressive-resize on

# don't rename windows automatically
set-option -g allow-rename off

# Enable mouse mode (tmux 2.1 and above)
set -g mouse on

#### key bindings

# reload config file
bind r source-file ~/.config/tmux/tmux.conf \; display "Config Reloaded!"
# split panes using | and -
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
unbind '"'
unbind %

bind -r H resize-pane -L 10
bind -r J resize-pane -D 10
bind -r K resize-pane -U 10
bind -r L resize-pane -R 10

#####################
# List of plugins #
####################

set -g @plugin 'tmux-plugins/tpm'
# basic configuration
set -g @plugin 'tmux-plugins/tmux-sensible'
# keep me alive accross shutdowns
set -g @plugin 'tmux-plugins/tmux-resurrect'
# vim tmux navigator with C-[hjkl]
set -g @plugin 'christoomey/vim-tmux-navigator'
# copy to clipboard
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @yank_action 'copy-pipe-no-clear'

bind -T copy-mode    C-c send -X copy-pipe-no-clear "xsel -i --clipboard"
bind -T copy-mode-vi C-c send -X copy-pipe-no-clear "xsel -i --clipboard"


if "test ! -d ~/.config/tmux/plugins/tpm" \
   "run 'git clone https://github.com/tmux-plugins/tpm ~/.config/tmux/plugins/tpm && ~/.config/tmux/plugins/tpm/bin/install_plugins'"

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.config/tmux/plugins/tpm/tpm'
  1. Start tmux and source the config file with tmux source ~/.config/tmux/tmux.conf

5.1 Teamocil

Allows us to easily create setup multiple windows and panes in Tmux

  1. Install teamocil sudo gem install teamocil
    1. Add compctl -g '~/.teamocil/*(:t:r)' teamocil for zsh auto completion
  2. Make config dir for teamocil ~/.teamocil and add setup file sembark.yml
name: Sembark
windows:
  - name: App UI
    root: ~/Documents/workspace/sembark/app/
    layout: main-vertical
    focus: true
    panes:
      - nvim
      - commands:
        - npm start
        focus: true
      - git status
  - name: APIs
    root: ~/Documents/workspace/sembark/apis/
    layout: main-vertical
    panes:
      - echo "nvim"
      - git status
      - commands:
        - php artisan serve
        focus: true
  - name: WWW
    root: ~/Documents/workspace/sembark/www/
    layout: main-vertical
    panes:
      - echo "nvim"
      - commands:
        - echo "npm run dev"
        focus: true

6. Terminal: Alacritty

  1. Download and install alacritty https://alacritty.org
  2. Configure using ~/.config/alacritty/alacritty.toml
[window]
startup_mode = "Fullscreen"

[font.normal]
family = "JetBrainsMono Nerd Font"
style = "Light"

[font.bold]
family = "JetBrainsMono Nerd Font"
style = "Bold"

[font.italic]
family = "JetBrainsMono Nerd Font"
style = "Italic"

[font]
size = 16.0

[font.offset]
x = 1
y = 14

7. Text Editor: NeoVim

  1. Install neovim brew install neovim

  2. Install the LazyVim deps http://www.lazyvim.org

    1. Install NerdFont using brew install —cask font-jetbrains-mono-nerd-font
    2. Install other deps using brew install ripgrep fd wget
  3. Install LazyVim http://www.lazyvim.org/installation

  4. Start the neovim nvim and let the lazyvim install the deps

  5. Enable LazyVim extras :LazyExras

    • coding.mini-comment
    • coding.mini-surround
    • coding.yanky
    • formatting.prettier
    • lang.json
    • lang.markdown
    • lang.typescript
    • linting.eslint
    • test.core
    • ui.mini-animate
    • util.dot
    • util.mini-hipatterns
  6. Update existing configuration and install some other plugins

return {
  -- for typescript, LazyVim also includes extra specs to properly setup lspconfig,
  -- treesitter, mason and typescript.nvim. So instead of the above, you can use:
  { import = "lazyvim.plugins.extras.lang.typescript" },
  -- use mini.starter instead of alpha
  { import = "lazyvim.plugins.extras.ui.mini-starter" },

  -- add any tools you want to have installed below
  {
    "williamboman/mason.nvim",
    opts = {
      ensure_installed = {
        "stylua",
        "shellcheck",
        "shfmt",
        "typescript-language-server",
        "eslint-lsp",
      },
    },
  },

  -- add jsonls and schemastore packages, and setup treesitter for json, json5 and jsonc
  { import = "lazyvim.plugins.extras.lang.json" },
  {
    "nvim-treesitter/nvim-treesitter",
    opts = {
      ensure_installed = {
        "html",
        "css",
        "javascript",
        "json",
        "lua",
        "markdown",
        "markdown_inline",
        "regex",
        "tsx",
        "typescript",
        "vim",
        "yaml",
        "php",
      },
    },
  },
  {
    "stevearc/conform.nvim",
    opts = {
      formatters_by_ft = {
        php = { "prettier" },
      },
    },
  },
  {
    "christoomey/vim-tmux-navigator",
    cmd = {
      "TmuxNavigateLeft",
      "TmuxNavigateDown",
      "TmuxNavigateUp",
      "TmuxNavigateRight",
      "TmuxNavigatePrevious",
    },
    keys = {
      { "<c-h>", "<cmd><C-U>TmuxNavigateLeft<cr>" },
      { "<c-j>", "<cmd><C-U>TmuxNavigateDown<cr>" },
      { "<c-k>", "<cmd><C-U>TmuxNavigateUp<cr>" },
      { "<c-l>", "<cmd><C-U>TmuxNavigateRight<cr>" },
      { "<c-\\>", "<cmd><C-U>TmuxNavigatePrevious<cr>" },
    },
  },
  { "olimorris/neotest-phpunit" },
  { "marilari88/neotest-vitest" },
  {
    "nvim-neotest/neotest",
    opts = { adapters = { "neotest-phpunit", "neotest-vitest" } },
  },
  { "tpope/vim-fugitive" },
}

8. NVM and NodeJs

Install node version manager from https://github.com/nvm-sh/nvm and setup the alias in the profile, as mentioned in the installation instructions. Then install the node using nvm install —lts.

9. PHP and Composer

Install php brew install php[@version] and link it with brew link php[@version]. Then install the composer https://getcomposer.org/download/ and move the executable composer to /usr/local/bin/

10. SQL and Redis

  1. Install DBngin from https://dbngin.com for database setup.
  2. Install TablePlus from https://tableplus.com to interact with database using UIs.

11. Add Shell Alias

Append the following to ~/.zshrc.

# Detect which ls flavor is in use
if ls --color > /dev/null 2>&1; then # GNU ls
    colorflag="--color"
else # macOS ls
    colorflag="-G"
fi

# use nvim, but don't make me think about it
alias vim="nvim"

# listing aliases
alias l="ls -lah ${colorflag}"
alias la="ls -AF ${colorflag}"
alias ll="ls -lFh ${colorflag}"
alias lld="ls -l | grep ^d"

######### Helpers
alias grep='grep --color=auto'
# disk free, in Gigabytes, not bytes
alias df='df -h'
# calculate disk usage for a folder
alias du='du -h -c'
# ips
alias ips="ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'"
# remove broken symlinks
alias clsym="find -L . -name . -o -type d -prune -o -type l -exec rm {} +"
# File size
alias fs="stat -f \"%z bytes\""

# tmux aliases
alias ta='tmux attach'
alias tls='tmux ls'
alias tat='tmux attach -t'
alias tns='tmux new-session -s'

12. GitHub SSH

  1. Setup GitHub ssh using docs
  2. Create a ~/.ssh directory
  3. Generate the keys
  4. Create a ~/.ssh/config file and setup the authentication
Host github.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_ed25519
  1. Add the public keys (id_ed25519.pub) to GitHub