---
# System prepended metadata

title: Mac Setup 
tags: [bash, mac, cli]

---

# Mac Setup 

###### tags: `mac` `bash` `cli`

[TOC]

## Terminal & Shells

### bash

#### .bash_profile

create and write contents of .bash_profile to personalize bash terminal sessions

```bash
touch ~/.bash_profile
open ~/.bash_profile
```

```bash
# ~/.bash_profile
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
export PS1="\[\e[35m\]\u\[\e[97m\]@\[\e[96m\]\h\[\e[33;15m\]\w\[\e[97m\]\n\$ \[\e[m\]"

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

if [ -f ~/.bash_utils ]; then
    . ~/.bash_utils
fi
```

#### .bash_aliases

#### .bash_utils

### zsh

## Homebrew

#### get brew
```bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
```

#### search brew
```bash
brew search git
brew search --casks wireshark
brew info wireshark # info on the formula/cask
brew home wireshark # opens web page
```

#### installed formulas
```bash
brew list
brew list --casks

# non dependencies
brew leaves
```

#### troubleshoot
```bash
brew doctor
```

## Development tools & environments

### Miniconda

#### install & setup
```bash
brew install miniconda
conda init bash
```

#### manage environments
```bash
# create
conda create --name titanic python=3
conda activate titanic

# list environments
conda info --envs

# delete
conda remove --name titanic --all
````

### Python

```bash
# get current bin location and version
which python
python --version
````

#### execute a script
```bash
# suppose we have ~/Code/titanic/main.py
cd ~/Code
python -m titanic.main
```

#### install packages
```bash
pip install pandas
conda install pandas
# => installs in .../envs/titanic/.../site-packages/pandas
```

### Poetry
```bash
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
```

### Docker
```bash
brew install docker docker-machine
brew cask install virtualbox
# -> need password
# -> possibly need to address System Preference setting

docker-machine create --driver virtualbox default
````

Add this to bash_profile / zshrc:
```bash
eval "$(docker-machine env default)"
````

test if it works
```bash
docker run hello-world
```

start
```bash
docker-machine stop default
docker run --rm -d -t -i --name nginx -p 8090:80 -v /Users/simon/myproject:/myvol nginx:stable-alpine
```

stop
```bash
docker-machine stop default
```

## Editors

### VS Code
```bash
brew cask install visual-studio-code
```

#### Setup command line tool
Once in VS, open the Command Palette (⇧ + ⌘ + `P`) and type 'shell command' to find the Shell Command: Install 'code' command in PATH command.

```bash
# get commands
code -h
```


### Sublime
```bash
brew cask install sublime-text
```

#### Setup command line tool
```bash
# create symlink to the actual tool in a 
# non-sudo location which is also in $PATH
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

# get commands
subl -h
```

Sublime shortcuts (on selection) :
⌘ + `d`
⌘ + ⇧ + `l`
⌘ + ⇧ + `/` toggle commentary for selected lines
