Francisco Villamil

Associate Professor
Department of Social Sciences
Universidad Carlos III de Madrid
francisco.villamil@uc3m.es

               

About
Publications
Teaching
Data & Code
Media

Setting up a new macOS environment

This is my own guide to set up a new mac computer. It covers the basics for code development (shell, git, R, Latex, code editor, etc) and some other useful applications for academic research.

Still TO-DO: R stuff (gcc, spatial)


Basics

Install XCode:

xcode-select -—install

Install Homebrew, and follow instructions in installation:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Annoying system settings


Shell and iTerm2

Install iTerm2, and oh-my-zsh:

brew install --cask iterm2
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

In older versions installing zsh might be necessary. Also, if you get an error like /Users/../.zshrc:source:75: no such file or directory: /Users/../.oh-my-zsh/oh-my-zsh.sh, uninstall and install oh-my-zsh again.

Install Powerlevel10k theme, close iTerm2, open again and go through configuration wizard:

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/powerlevel10k
echo 'source ~/powerlevel10k/powerlevel10k.zsh-theme' >>~/.zshrc

NOTE:


Git

Install git via homebrew and check that version has changed been updated:

git --version
brew install git
git --version

If version doesn’t change, try:

export PATH=/usr/local/bin:$PATH
git --version

Add cached credentials to log in locally (see this guide):

brew install --cask git-credential-manager

Just clone any private repository to set it up. Maybe useful to do this afterwards:

git config --global user.name "Fran Villamil"
git config --global user.email francisco.villamil@uc3m.es

Extras

Also install Github CLI (gh)

brew install gh

Get configurations from configfiles:

Clone configfiles repository and create symlinks for terminal and git:

cd
git clone https://github.com/franvillamil/configfiles
rm ~/.zshrc && ln -s ~/configfiles/.zshrc ~/.zshrc
rm ~/.p10k.zsh && ln -s ~/configfiles/.p10k.zsh ~/.p10k.zsh
ln -s ~/configfiles/.aliases ~/.oh-my-zsh/custom/aliases.zsh
rm ~/.gitconfig && ln -s configfiles/.gitconfig  ~/.gitconfig

Note: aliases go in a separate file (.aliases, pointed by a symlink in .oh-my-zsh/custom/), see this thread.

Get p4merge (optional):

brew install --cask p4v

The configuration for git should already be in configfiles, but just in case, it is:

[diff]
    tool = p4mergetool
    renames = copies
    mnemonicprefix = true
[difftool "p4mergetool"]
    cmd = /Applications/p4merge.app/Contents/MacOS/p4merge "$LOCAL" "$REMOTE"
    keepBackup = false
    keepTemporaries = false
    trustExitCode = false
    prompt = false

R installation

Still TO-DO:

ln -s ~/configfiles/.Rprofile ~/.Rprofile
ln -s ~/configfiles/.Renviron ~/.Renviron

gcc stuff for compilations in R (in case it’s needed)

NOTE: check this post before. Looks like macOS Ventura comes with gcc and g++ 14, maybe it is enough to point to their location (by default in /usr/bin/) in a new Makevars file? Instead to download it through Homebrew (see also this post). But if I do want to do that, follow:

brew install gcc

And then add this to Makevars, but first check version of gcc and directories etc (perhaps need to create it: cd && mkdir .R && touch .R/Makevars):

CC = gcc-12
CXX = g++-12
FLIBS = -L/opt/homebrew/lib/gcc/12/gcc/aarch64-apple-darwin20/12 -L/opt/homebrew/lib/gcc/12 -lgfortran -lquadmath -lm

Extra libraries to use in R

Code editor

I use Sublime Text with the following packages installed:

Configuration is saved in a (private) git repository, which also enables syncing. In a new computer, just install Package Control and then clone the repository into the following folder, in a new folder called User:

cd Library/Application\ Support/Sublime\ Text/Packages

I also have the following aliases defined in .zshrc, to manage the settings folder (access, update, and upload) and open both files and current directories with Sublime Text:

alias stfolder="cd ~/Library/Application\ Support/Sublime\ Text/Packages/User"
alias updatest="cd ~/Library/Application\ Support/Sublime\ Text/Packages/User && gitfs && git pull"
alias uploadst="cd ~/Library/Application\ Support/Sublime\ Text/Packages/User && gitfs && gitacp"
alias subl='open -a "Sublime Text" "$@"'
alias openfs='open ${PWD} -a "Sublime Text"'

Alternatively, to make the subl command work:

sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

Note: SendCode settings are not stored in /Packages/User/ but directly in Packages (why?), so they do not sync. It’s possible that for code to be sent to the right app, you need to change SendCode (OSX).sublime-settings, e.g.:

    "r" : {
        "prog": "r",
        // turn bracketed_paste_mode on if radian or readline 7.0 is in use
        "bracketed_paste_mode": false
    },

Latex

brew install –cask mactex eval “$(/usr/libexec/path_helper)”

NOTE: I’m not sure it’s the best idea to install it through homebrew, see this post.

Also, install bibtex-tidy (see this) (needs npm):

npm install -g bibtex-tidy

Other software

brew install pandoc
brew install pandoc-crossref
brew install --cask skim
brew install --cask brave-browser
brew install --cask dropbox
brew install --cask quicksilver
brew install --cask spectacle
brew install --cask modern-csv
brew install --cask spotify
brew install --cask autofirma
brew install --cask adobe-acrobat-reader
brew install --cask firefox
brew install --cask gimp
brew install --cask protonvpn
brew install --cask selfcontrol
brew install --cask skype
brew install --cask zoom
brew install --cask zotero
brew install --cask calibre
brew install --cask obsidian
brew install --cask google-drive
brew install node
brew install --cask notunes
brew install gpsbabel
brew install pdftk-java
brew install --cask alt-tab
brew install --cask karabiner-elements
brew install bluesnooze
brew install fzf
brew install autojump
brew install fd
brew install tree
brew install ripgrep
brew install rga
brew install poppler ffmpeg
brew install lsd
brew install bat
brew install --cask rectangle

Set ups to consider:

    # Set up fzf key bindings and fuzzy completion
    source <(fzf --zsh)

    _fzf_compgen_path() {
      command fd --hidden --follow --exclude .git --exclude node_modules . "$1"
    }

    _fzf_compgen_dir() {
      command fd --type d --hidden --follow --exclude .git --exclude node_modules . "$1"
    }
* And run: `export FZF_DEFAULT_COMMAND='fd --type f'`

Other apps:

Quick configurations

Spectacle:

Quicksilver:

Others:


Zotero configuration

General preferences

Better BibTex

Attanger


{{ authors max="1" case="lower" }}


{{ authors max="1" suffix="_" case="snake" }}{{ year suffix="_" }}{{ title truncate="100" case="snake" }}


Extras

Add python to PATH

Python3 should be installed by now in homebrew. Maybe check:

where python3

To check the versions installed, try ls /opt/homebrew/opt/. Also useful to check brew info python. (See this).

Now add it to the PATH (careful with version):

echo 'export PATH=/opt/homebrew/opt/python@3.11/libexec/bin:$PATH' >> ~/.zprofile
source ~/.zprofile

File type defaults

Install duti:

brew install duti

If you need to check the code for an application, assign it manually and then check the defaults with duti:

duti -x sh

And then change some defaults. First, csv files with Modern CSV:

duti -s net.galliumdigital.Modern-CSV .csv all

Skim for pdf:

duti -s net.sourceforge.skim-app.skim .pdf all

All plain text (txt, R, Markdown, shell, Latex) with Sublime Text:

duti -s com.sublimetext.4 .txt all
duti -s com.sublimetext.4 .md all
duti -s com.sublimetext.4 .R all
duti -s com.sublimetext.4 .tex all
duti -s com.sublimetext.4 .sh all
duti -s com.sublimetext.4 .zsh all

Keyboard shortcuts


References