0%

Setup a New Laptop Environment

Setup a New Laptop

I always want to have the same work environment/setup on my desktop/laptop. Here’s just a quick notes for what I usually need on my work station.

Homebrew (MacOS only)

1
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

(Optional) Install GPG package.

1
brew install gnupg

More info: https://docs.brew.sh

SSH

Generate New SSH Keys

  • Open terminal
  • Generate a new SSH key
    1
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Different Keys for Different Servers

  • Create ~/.ssh/config file and add necessary info:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    Host github.com
    User jocodoma
    IdentityFile ~/.ssh/github_rsa_jocodoma

    Host gitlab.com
    User joseph
    IdentityFile ~/.ssh/gitlab_rsa_joseph

    Host git-codecommit.*.amazonaws.com
    User XXXXXXXXXXXXXXXXXXXX
    IdentityFile ~/.ssh/codecommit_rsa

Different Keys for the Same Server

Git Settings

  1. Get config files.

    1
    2
    cd ~/Documents/
    git clone git@github.com:jocodoma/config.git
  2. (For bash only) Setup git scripts, including auto completion of git command.

    ~/.bash_profile
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    ### My Settings ###
    # colors!
    white="\[\033[0;37m\]"
    green="\[\033[0;32m\]"
    yellow="\[\033[0;33m\]"
    blue="\[\033[0;34m\]"
    purple="\[\033[0;35m\]"
    cyan="\[\033[0;36m\]"
    reset="\[\033[0m\]"

    # Git completion
    source ~/Documents/config/gitConfig/git-completion.bash

    # Change command prompt
    source ~/Documents/config/gitConfig/git-prompt.sh
    export GIT_PS1_SHOWDIRTYSTATE=1
    # '\u' adds the name of the current user to the prompt
    # '\$(__git_ps1)' adds git-related stuff
    # '\W' adds the name of the current directory
    #export PS1="$purple\u$white\$(__git_ps1)$green \W $ $reset"
    export PS1="$purple\u $yellow(@_@) $cyan\@$white\$(__git_ps1)$green \W # $reset"

    # sublime text 3 alias
    #alias subl="/Applications/Sublime\\ Text.app/Contents/SharedSupport/bin/subl"

    # GPG for MacOS
    #export GPG_TTY=$(tty)
  3. Git Configuration.

    ~/.gitconfig
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    [user]
    name = Joseph Chen
    email = jocodoma@gmail.com
    [core]
    autocrlf = input
    # editor = atom -n -w
    editor = code -n -w
    excludesfile = /Users/jocodoma/.gitignore_global
    [color]
    ui = auto
    [color "status"]
    added = yellow bold
    changed = red bold
    untracked = cyan bold
    [color "diff"]
    meta = white bold
    frag = magenta bold
    old = red bold
    new = yellow bold
    [color "branch"]
    current = white bold
    local = yellow bold
    remote = cyan bold
    [push]
    default = upstream
    [merge]
    conflictstyle = diff3

    In case of having difftool/mergetool installed.

    ~/.gitconfig
    1
    2
    3
    4
    5
    6
    [difftool "sourcetree"]
    cmd = opendiff \"$LOCAL\" \"$REMOTE\"
    path =
    [mergetool "sourcetree"]
    cmd = /Applications/Sourcetree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
    trustExitCode = true
  4. [Optional] Setup GPG for each repository and submodule.
    For more details, please see Managing Commit Signature Verification.

    {GIT_REPO}/.git/config
    1
    2
    3
    4
    5
    6
    [user]
    signingKey = 1F4057EA9C51670B
    name = Joseph Chen
    email = jocodoma@gmail.com
    [commit]
    gpgsign = true

Install the Xcode Command Line Tools (MacOS only)

1
xcode-select --install

Use the following command to confirm the installation:

1
xcode-select -p

Terminator (Linux only)

Ubuntu

1
2
sudo apt-get update
sudo apt-get install terminator

Atom Settings

VSCode Settings

Sync

Install code Command to PATH

  • Open Visual Studio Code
  • Press Command + Shift + P or F1
  • Type Shell in command palette
  • Select: Shell Command: Install code command in PATH
  • Now, issue the following command on terminal should get vscode up and running:
    1
    $ code

ZSH (For MacOS Catalina and after)

Auto Suggestions Plugin

Powerlevel9k Theme for ZSH

  • Install Powerlevel9k
    1
    2
    brew tap sambadevi/powerlevel9k
    brew install powerlevel9k
  • Install a Powerlevel Fonts - Sauce Code Pro Nerd Font Complete Mono
  • My theme settings:
    ~/.zsh/p9k_config
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    zsh_wifi_signal(){
    local output=$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I)
    local airport=$(echo $output | grep 'AirPort' | awk -F': ' '{print $2}')

    if [ "$airport" = "Off" ]; then
    local color='%F{black}'
    echo -n "%{$color%}Wifi Off"
    else
    local ssid=$(echo $output | grep ' SSID' | awk -F': ' '{print $2}')
    local speed=$(echo $output | grep 'lastTxRate' | awk -F': ' '{print $2}')
    local color='%F{black}'

    [[ $speed -gt 100 ]] && color='%F{black}'
    [[ $speed -lt 50 ]] && color='%F{red}'

    echo -n "%{$color%}$speed Mbps \uf1eb%{%f%}" # removed char not in my PowerLine font
    fi
    }

    POWERLEVEL9K_MODE='nerdfont-complete'
    ZSH_THEME='powerlevel9k/powerlevel9k'

    ## prompt - general
    POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
    POWERLEVEL9K_PROMPT_ON_NEWLINE=true
    POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX="%F{blue}\u256D\u2500%F{white}"
    POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="%F{blue}\u2570\uf460%F{lightgreen} "

    ## prompt - left
    POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(root_indicator dir dir_writable_joined vcs)
    # POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(os_icon battery ram time newline dir_joined)
    POWERLEVEL9K_LEFT_SEGMENT_SEPARATOR=''
    POWERLEVEL9K_LEFT_SUBSEGMENT_SEPARATOR=''
    POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS=' '

    ## prompt - right
    POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(command_execution_time status os_icon battery ram background_jobs_joined time_joined)
    # POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(command_execution_time status os_icon battery ip custom_wifi_signal ram load background_jobs_joined time_joined)
    POWERLEVEL9K_RIGHT_SEGMENT_SEPARATOR=''
    POWERLEVEL9K_RIGHT_SUBSEGMENT_SEPARATOR=''
    POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS=' '

    ## status
    POWERLEVEL9K_STATUS_CROSS=true
    # POWERLEVEL9K_STATUS_VERBOSE=true
    POWERLEVEL9K_STATUS_OK_BACKGROUND='clear'
    POWERLEVEL9K_STATUS_OK_FOREGROUND='green'
    POWERLEVEL9K_STATUS_ERROR_BACKGROUND='clear'
    POWERLEVEL9K_STATUS_ERROR_FOREGROUND='red'

    ## os_icon custom
    POWERLEVEL9K_OS_ICON_BACKGROUND='clear'
    POWERLEVEL9K_OS_ICON_FOREGROUND='white'

    ## directory
    POWERLEVEL9K_SHORTEN_DELIMITER='...'
    POWERLEVEL9K_SHORTEN_DIR_LENGTH=3
    POWERLEVEL9K_SHORTEN_STRATEGY='truncate_beginning'
    # POWERLEVEL9K_SHORTEN_STRATEGY='truncate_middle'
    # POWERLEVEL9K_SHORTEN_STRATEGY='truncate_to_first_and_last'
    POWERLEVEL9K_DIR_HOME_BACKGROUND='clear'
    POWERLEVEL9K_DIR_HOME_FOREGROUND='blue'
    POWERLEVEL9K_DIR_HOME_SUBFOLDER_BACKGROUND='clear'
    POWERLEVEL9K_DIR_HOME_SUBFOLDER_FOREGROUND='blue'
    POWERLEVEL9K_DIR_WRITABLE_FORBIDDEN_BACKGROUND='clear'
    POWERLEVEL9K_DIR_WRITABLE_FORBIDDEN_FOREGROUND='red'
    POWERLEVEL9K_DIR_DEFAULT_BACKGROUND='clear'
    POWERLEVEL9K_DIR_DEFAULT_FOREGROUND='white'

    ## time
    # POWERLEVEL9K_TIME_FORMAT='%D{%d.%m.%y %H:%M:%S}'
    # POWERLEVEL9K_TIME_FORMAT='%D{%H:%M \uf43a %d/%m/%y \uf073}'
    POWERLEVEL9K_TIME_FORMAT='%D{%H:%M}'
    POWERLEVEL9K_TIME_BACKGROUND="clear"
    POWERLEVEL9K_TIME_FOREGROUND="tan"

    ## network
    POWERLEVEL9K_IP_BACKGROUND='clear'
    POWERLEVEL9K_IP_FOREGROUND='cyan1'
    POWERLEVEL9K_CUSTOM_WIFI_SIGNAL='zsh_wifi_signal'
    POWERLEVEL9K_CUSTOM_WIFI_SIGNAL_BACKGROUND="white"
    POWERLEVEL9K_CUSTOM_WIFI_SIGNAL_FOREGROUND="cyan1"

    ## ram
    POWERLEVEL9K_RAM_BACKGROUND='clear'
    POWERLEVEL9K_RAM_FOREGROUND='purple'
    POWERLEVEL9K_RAM_ELEMENTS=(ram_free)

    ## load
    POWERLEVEL9K_LOAD_CRITICAL_BACKGROUND='clear'
    POWERLEVEL9K_LOAD_CRITICAL_FOREGROUND='lightred'
    POWERLEVEL9K_LOAD_CRITICAL_VISUAL_IDENTIFIER_COLOR='lightred'
    POWERLEVEL9K_LOAD_WARNING_BACKGROUND='clear'
    POWERLEVEL9K_LOAD_WARNING_FOREGROUND='lightyellow'
    POWERLEVEL9K_LOAD_WARNING_VISUAL_IDENTIFIER_COLOR='lightyellow'
    POWERLEVEL9K_LOAD_NORMAL_BACKGROUND='clear'
    POWERLEVEL9K_LOAD_NORMAL_FOREGROUND='lightgreen'
    POWERLEVEL9K_LOAD_NORMAL_VISUAL_IDENTIFIER_COLOR='lightgreen'

    ## battery
    POWERLEVEL9K_BATTERY_DISCONNECTED_BACKGROUND='clear'
    POWERLEVEL9K_BATTERY_DISCONNECTED_FOREGROUND='darkorange'
    POWERLEVEL9K_BATTERY_CHARGING_BACKGROUND='clear'
    POWERLEVEL9K_BATTERY_CHARGING_FOREGROUND='yellow'
    # POWERLEVEL9K_BATTERY_CHARGING_VISUAL_IDENTIFIER_COLOR="yellow"
    POWERLEVEL9K_BATTERY_CHARGED_BACKGROUND='clear'
    POWERLEVEL9K_BATTERY_CHARGED_FOREGROUND='green'
    # POWERLEVEL9K_BATTERY_CHARGED_VISUAL_IDENTIFIER_COLOR="green"
    POWERLEVEL9K_BATTERY_LOW_BACKGROUND='none'
    POWERLEVEL9K_BATTERY_LOW_FOREGROUND='red'
    POWERLEVEL9K_BATTERY_LOW_THRESHOLD='10'
    # POWERLEVEL9K_BATTERY_ICON="\uf1e6 "
    # POWERLEVEL9K_BATTERY_ICON="\U1f50b "
    # POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND=(darkred orange4 yellow4 yellow4 darkgreen darkgreen green clear)
    POWERLEVEL9K_BATTERY_VERBOSE=true
    POWERLEVEL9K_BATTERY_STAGES=''

    ## vcs
    POWERLEVEL9K_SHOW_CHANGESET=true
    POWERLEVEL9K_CHANGESET_HASH_LENGTH=6
    POWERLEVEL9K_VCS_CLEAN_BACKGROUND='clear'
    POWERLEVEL9K_VCS_CLEAN_FOREGROUND='white'
    POWERLEVEL9K_VCS_MODIFIED_BACKGROUND="clear"
    POWERLEVEL9K_VCS_MODIFIED_FOREGROUND="yellow"
    POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND="clear"
    POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND="grey"
    POWERLEVEL9K_VCS_UNTRACKED_ICON='?'
    POWERLEVEL9K_VCS_GIT_HOOKS=(vcs-detect-changes git-untracked git-aheadbehind git-remotebranch git-tagname)

    ## background_jobs
    POWERLEVEL9K_BACKGROUND_JOBS_BACKGROUND='clear'
    POWERLEVEL9K_BACKGROUND_JOBS_FOREGROUND='yellow'

    ## root_indicator
    POWERLEVEL9K_ROOT_INDICATOR_BACKGROUND="red"
    POWERLEVEL9K_ROOT_INDICATOR_FOREGROUND="white"

    ## execution_time
    POWERLEVEL9K_COMMAND_EXECUTION_TIME_BACKGROUND='clear'
    POWERLEVEL9K_COMMAND_EXECUTION_TIME_FOREGROUND='magenta'
    ~/.p9k
    1
    2
    3
    4
    5
    ## prompt - left
    POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(root_indicator dir dir_writable_joined vcs)

    ## prompt - right
    POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(command_execution_time status os_icon battery ram background_jobs_joined time_joined)
    ~/.p9k2
    1
    2
    3
    4
    5
    ## prompt - left
    POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(root_indicator dir dir_writable_joined vcs)

    ## prompt - right
    POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(command_execution_time status os_icon battery ip custom_wifi_signal ram load background_jobs_joined time_joined)
  • My top level zsh settings:
    ~/.zprofile
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    DEFAULT_USER=`whoami`

    ## zsh auto suggestions settings
    source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh

    ## zsh theme
    source ~/.zsh/p9k_config
    source /usr/local/opt/powerlevel9k/powerlevel9k.zsh-theme

    export PATH=$HOME/bin:/usr/local/bin:$PATH
  • References:
    https://github.com/Powerlevel9k/powerlevel9k/
    https://github.com/ryanoasis/nerd-fonts

iTerm2 Settings (MacOS only)