mrbone / mrbone.github.io

0 stars 0 forks source link

重装 mac 的基本配置 #102

Closed mrbone closed 6 years ago

mrbone commented 6 years ago

创建此卡的目的

记录必需的基本软件和配置

简单的描述

验收点

可以基本进入开发状态

mrbone commented 6 years ago

mac 重装必装软件

homebrew

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

如果提示安装失败则需要检查是否安装了 commandline-tool

xcode-select --install

接下来安装

nvm 需要添加 export 到 bashrc/zshrc 中。

export NVM_DIR="$HOME/.nvm"
  . "/usr/local/opt/nvm/nvm.sh"
brew install yarn --without-node

排错

安装完之后需要使用 brew doctor 排查是否有错误。

ShadowsocksX-NG

配置热键

oh-my-zsh

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

要使用 oh-my-zsh 需要安装 zsh,并且将 zsh 配置成 $SHELL 变量

chsh -s $(which zsh)

插件

auto-suggestions

$ git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

~/.zshrc 中开启 plugins

plugins=(
  git
  z
  yarn
  zsh-autosuggestions
)

zsh-syntax-highlighting

brew install zsh-syntax-highlighting

~/.zshrc 中添加

# zsh-highlight-syntax
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

themes

agnoster

  1. install powerline-fonts
    1. document
    2. install python by brew install python 如果已经有 python (默认都有)则需要安装 pip
    3. sudo easy_install pip 如果安装了 python,则 easy_install 自动就有了
    4. pip install --user powerline-status
    5. 直接 git clone https://github.com/powerline/fonts.git --depth=1
    6. 执行目录下的 install.sh
    7. 在 iterm2 中输入 echo "\ue0b0 \u00b1 \ue0a0 \u27a6 \u2718 \u26a1 \u2699" 测试输出是否正常
  2. iterm2 -> Preference -> profile -> color - presets -> solarized Dark
  3. iterm2 -> Preference -> profile -> Roboto Mono Medium for Powerline 并且将字体大小调整为 14。
  4. 更改 ~/.zshrc 下的 themeagnoster
  5. ~/.zshrc 添加 export DEFAULT_USER=$(whoami) 隐藏掉样式前面的 user@machine 占位
  6. ~/.oh-my-zsh/themes/agnoster.zsh-theme 替换为如下代码。
# vim:ft=zsh ts=2 sw=2 sts=2
#
# agnoster's Theme - https://gist.github.com/3712874
# A Powerline-inspired theme for ZSH
#
# # README
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://github.com/Lokaltog/powerline-fonts).
# Make sure you have a recent version: the code points that Powerline
# uses changed in 2012, and older versions will display incorrectly,
# in confusing ways.
#
# In addition, I recommend the
# [Solarized theme](https://github.com/altercation/solarized/) and, if you're
# using it on Mac OS X, [iTerm 2](http://www.iterm2.com/) over Terminal.app -
# it has significantly better color fidelity.
#
# # Goals
#
# The aim of this theme is to only show you *relevant* information. Like most
# prompts, it will only show git information when in a git working directory.
# However, it goes a step further: everything from the current user and
# hostname to whether the last call exited with an error to whether background
# jobs are running in this shell will all be displayed automatically when
# appropriate.

### Segment drawing
# A few utility functions to make it easy and re-usable to draw segmented prompts

CURRENT_BG='NONE'

# Special Powerline characters

() {
  local LC_ALL="" LC_CTYPE="en_US.UTF-8"
  # NOTE: This segment separator character is correct.  In 2012, Powerline changed
  # the code points they use for their special characters. This is the new code point.
  # If this is not working for you, you probably have an old version of the
  # Powerline-patched fonts installed. Download and install the new version.
  # Do not submit PRs to change this unless you have reviewed the Powerline code point
  # history and have new information.
  # This is defined using a Unicode escape sequence so it is unambiguously readable, regardless of
  # what font the user is viewing this source code in. Do not replace the
  # escape sequence with a single literal character.
  # Do not change this! Do not make it '\u2b80'; that is the old, wrong code point.
  SEGMENT_SEPARATOR=$'\ue0b0'
}

# Begin a segment
# Takes two arguments, background and foreground. Both can be omitted,
# rendering default background/foreground.
prompt_segment() {
  local bg fg
  [[ -n $1 ]] && bg="%K{$1}" || bg="%k"
  [[ -n $2 ]] && fg="%F{$2}" || fg="%f"
  if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
    echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
  else
    echo -n "%{$bg%}%{$fg%} "
  fi
  CURRENT_BG=$1
  [[ -n $3 ]] && echo -n $3
}

# End the prompt, closing any open segments
prompt_end() {
  if [[ -n $CURRENT_BG ]]; then
    echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
  else
    echo -n "%{%k%}"
  fi
  echo -n "%{%f%}"
  CURRENT_BG=''
}

### Prompt components
# Each component will draw itself, and hide itself if no information needs to be shown

# Context: user@hostname (who am I and where am I)
prompt_context() {
  if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
    prompt_segment black default "%(!.%{%F{yellow}%}.)$USER@%m"
  fi
}

# Git: branch/detached head, dirty status
prompt_git() {

  local PL_BRANCH_CHAR
  () {
    local LC_ALL="" LC_CTYPE="en_US.UTF-8"
    PL_BRANCH_CHAR=$'\ue0a0'         # 
  }
  local ref dirty mode repo_path
  repo_path=$(git rev-parse --git-dir 2>/dev/null)

  if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
    dirty=$(parse_git_dirty)
    ref=$(git symbolic-ref HEAD 2> /dev/null) || ref="➦ $(git rev-parse --short HEAD 2> /dev/null)"
    if [[ -n $dirty ]]; then
      prompt_segment yellow black
    else
      prompt_segment green black
    fi

    if [[ -e "${repo_path}/BISECT_LOG" ]]; then
      mode=" <B>"
    elif [[ -e "${repo_path}/MERGE_HEAD" ]]; then
      mode=" >M<"
    elif [[ -e "${repo_path}/rebase" || -e "${repo_path}/rebase-apply" || -e "${repo_path}/rebase-merge" || -e "${repo_path}/../.dotest" ]]; then
      mode=" >R>"
    fi

    setopt promptsubst
    autoload -Uz vcs_info

    zstyle ':vcs_info:*' enable git
    zstyle ':vcs_info:*' get-revision true
    zstyle ':vcs_info:*' check-for-changes true
    zstyle ':vcs_info:*' stagedstr '✚'
    zstyle ':vcs_info:*' unstagedstr '●'
    zstyle ':vcs_info:*' formats ' %u%c'
    zstyle ':vcs_info:*' actionformats ' %u%c'
    vcs_info
    echo -n "${ref/refs\/heads\//$PL_BRANCH_CHAR }${vcs_info_msg_0_%% }${mode}"
  fi
}

prompt_hg() {
  local rev status
  if $(hg id >/dev/null 2>&1); then
    if $(hg prompt >/dev/null 2>&1); then
      if [[ $(hg prompt "{status|unknown}") = "?" ]]; then
        # if files are not added
        prompt_segment red white
        st='±'
      elif [[ -n $(hg prompt "{status|modified}") ]]; then
        # if any modification
        prompt_segment yellow black
        st='±'
      else
        # if working copy is clean
        prompt_segment green black
      fi
      echo -n $(hg prompt "☿ {rev}@{branch}") $st
    else
      st=""
      rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g')
      branch=$(hg id -b 2>/dev/null)
      if `hg st | grep -q "^\?"`; then
        prompt_segment red black
        st='±'
      elif `hg st | grep -q "^[MA]"`; then
        prompt_segment yellow black
        st='±'
      else
        prompt_segment green black
      fi
      echo -n "☿ $rev@$branch" $st
    fi
  fi
}

# Dir: current working directory
prompt_dir() {
  prompt_segment blue black '%~'
}

# Virtualenv: current working virtualenv
prompt_virtualenv() {
  local virtualenv_path="$VIRTUAL_ENV"
  if [[ -n $virtualenv_path && -n $VIRTUAL_ENV_DISABLE_PROMPT ]]; then
    prompt_segment blue black "(`basename $virtualenv_path`)"
  fi
}

# Status:
# - was there an error
# - am I root
# - are there background jobs?
prompt_status() {
  local symbols
  symbols=()
  [[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}✘"
  [[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡"
  [[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}⚙"

  [[ -n "$symbols" ]] && prompt_segment black default "$symbols"
}

prompt_newline() {
  if [[ -n $CURRENT_BG ]]; then
    echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR
%{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
  else
    echo -n " %{%k%}"
  fi

  echo -n " %{%f%}"
  CURRENT_BG=''
}

## Main prompt
build_prompt() {
  RETVAL=$?
  prompt_status
  prompt_virtualenv
  prompt_context
  prompt_dir
  prompt_git
  prompt_hg
  prompt_newline
  prompt_end
}

PROMPT='%{%f%b%k%}$(build_prompt)'

powerlevel9k

同样需要安装 Powerline fonts

git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k

修改 ~/.zshrc

ZSH_THEME="powerlevel9k/powerlevel9k"

#powerlevel9k
POWERLEVEL9K_PROMPT_ADD_NEWLINE=true
POWERLEVEL9K_PROMPT_ON_NEWLINE=true

POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir rbenv vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status root_indicator background_jobs history time)

alias

# folder
alias cdwk="cd /Users/mrbone/Workspace"
alias cdsl="cd /Users/mrbone/Workspace/github/self-learning"
alias cdsw="cd /Users/mrbone/Workspace/github/self-written"
alias qksl="code /Users/mrbone/Workspace/github/self-learning"
alias qksw="code /Users/mrbone/Workspace/github/self-written"

iterm2

config

cursor

后记: 还是换回 box 了。

iTerm2 → Preferences → Profiles → Text
→ Cursor : ✓ Vertical Bar 
→ Blinking cursor: ✓ ON

color preset

font

14pt Meslo LG M DZ Regular for powerline

Text Edit

iTerm → Preferences → Profiles → Keys → Load Preset… → Natural Text Editing

在 finder 中打开 iterm

  1. Run Automator, select new Application
  2. Select Utilities -> Double click ‘Run AppleScript’
  3. Paste script:
on run {input, parameters}
    tell application "Finder"
        set dir_path to quoted form of (POSIX path of (folder of the front window as alias))
    end tell
    CD_to(dir_path)
end run

on CD_to(theDir)
    tell application "iTerm"
        activate
        set win to (create window with default profile)
        set sesh to (current session of win)
        tell sesh to write text "cd " & theDir & ";clear"
    end tell
end CD_to
  1. 保存为 'iTermOpenScript.app'。
  2. 打开 finder 进入到 Application 目录,把 iTermOpenScript.app 拖到标题栏,同时按住 options + command 能够调整图标在标题栏的位置。
  3. ....

vs-code

配置

snippets

{
    // Place your snippets for javascriptreact here. Each snippet is defined under a snippet name and has a prefix, body and 
    // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
    // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
    // same ids are connected.
    // Example:
    "Print to console": {
        "prefix": "lg",
        "body": [
            "console.log('$1');",
        ],
        "description": "Log output to console"
    },
    "Import Module": {
        "prefix": "imp",
        "body": [
            "import ${0:module} from '$1';"
        ],
        "description": "import a dependency"
    },
    "Arrow function": {
        "prefix": "a>",
        "body": [
            "($1) => {",
            "  $0",
            "}"
        ],
        "description": "Insert an arrow function"
    },
    "New React PureComponent": {
        "prefix": "react:pure",
        "body": [
            "import React from 'react';",
            "",
            "class ${1:ComponentName} extends React.PureComponent {",
            "  render(){",
            "    return $0",
            "  }",
            "}",
            "export default ${1:ComponentName};"
        ],
        "description": "Quickly create a fresh new react PureComponent"
    },
    "New React Component": {
        "prefix": "react:normal",
        "body": [
            "import React from 'react';",
            "",
            "class ${1:ComponentName} extends React.Component {",
            "  render(){",
            "    return $0",
            "  }",
            "}",
            "export default ${1:ComponentName};"
        ],
        "description": "Quickly create a fresh new react Component"
    },
    "New React Stateless Component": {
        "prefix": "react:statelss",
        "body": [
            "import React from 'react';",
            "",
            "const ${1:ComponentName} = () => {",
            "  return ($0)",
            "};",
            "export default ${1:ComponentName};"
        ],
        "description": "Quickly create a fresh new react Component"
    },
    "Create React elemnt": {
        "prefix": "react:element",
        "body":[
            "<${1:ComponentName}>",
            "  $0",
            "</${1:ComponentName}>"
        ],
        "description": "create a react element with double close"
    },
    "Create React elemnt with single close tag": {
        "prefix": "react:element-single",
        "body":[
            "<${0:ComponentName} />",
        ],
        "description": "create a react element with single close tag"
    },
    "Deconstruct component props or state": {
        "prefix": "const:react",
        "body":[
            "const { $0 } = this.${1:props};",
        ],
        "description": "deconstruct component props or state"
    }
}
{
    // Place your snippets for javascript here. Each snippet is defined under a snippet name and has a prefix, body and 
    // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
    // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
    // same ids are connected.
    // Example:
    "Print to console": {
        "prefix": "lg",
        "body": [
            "console.log($1);",
        ],
        "description": "Log output to console"
    },
    "Arrow function": {
        "prefix": "a>",
        "body": [
            "($1) => {",
            "  $0",
            "}"
        ],
        "description": "Insert an arrow function"
    },
    "Import Module": {
        "prefix": "imp",
        "body": [
            "import ${0:module} from '$1';"
        ],
        "description": "import a dependency"
    },
    "New React PureComponent": {
        "prefix": "react:pure",
        "body": [
            "import React from 'react';",
            "",
            "class ${1:ComponentName} extends React.PureComponent {",
            "  render(){",
            "    return $0",
            "  }",
            "}",
            "export default ${1:ComponentName};"
        ],
        "description": "Quickly create a fresh new react PureComponent"
    },
    "New React Component": {
        "prefix": "react:normal",
        "body": [
            "import React from 'react';",
            "",
            "class ${1:ComponentName} extends React.Component {",
            "  render(){",
            "    return $0",
            "  }",
            "}",
            "export default ${1:ComponentName};"
        ],
        "description": "Quickly create a fresh new react Component"
    },
    "New React Stateless Component": {
        "prefix": "react:statelss",
        "body": [
            "import React from 'react';",
            "const ${1:ComponentName} = () => {",
            "  return ($0)",
            "};",
            "export default ${1:ComponentName};"
        ],
        "description": "Quickly create a fresh new react Component"
    },
    "Create React elemnt": {
        "prefix": "react:element",
        "body":[
            "<${0:ComponentName}>",
            "",
            "</${0:ComponentName}>"
        ],
        "description": "create a react element with double close"
    },
    "Create React elemnt with single close tag": {
        "prefix": "react:element-single",
        "body":[
            "<${0:ComponentName} />",
        ],
        "description": "create a react element with single close tag"
    }
}

User Settings

{
    "workbench.iconTheme": "vscode-icons",
    "explorer.confirmDragAndDrop": false,
    "explorer.confirmDelete": false,
    "vsicons.projectDetection.autoReload": true,
    "javascript.implicitProjectConfig.experimentalDecorators": true,
    "editor.tabSize": 2,
    "window.title": "${activeEditorMedium}",
    "relativePath.removeExtension": true,
    "explorer.autoReveal": true
}

插件

alfred 3

Cerebro (替代 alfred)

插件

Rime输入法—鼠须管

在 Rime (/Users/cbxu/Library/Rime) 目录下新建 default.custom.yaml 文件,添加配置:

patch:
  "menu/page_size": 9

对应程序关闭中文输入: 新建 squirrel.custom.yaml,对应程序的 name 在 app content 中的 Info.plist Identifier 字段中查看

patch:
  app_options/com.microsoft.VSCode:
    ascii_mode: true
  app_options/com.jetbrains.WebStorm:
    ascii_mode: true
  app_options/com.google.Chrome:
    ascii_mode: true
  app_options/com.cerebroapp.Cerebro:
    ascii_mode: true
  app_options/com.googlecode.iterm2:
    ascii_mode: true
  app_options/com.youdao.YoudaoDict:
    ascii_mode: true
  app_options/com.runningwithcrayons.Alfred-3:
    ascii_mode: true

motivation 屏保

release

iPaste/Alfred3/Paste2

第一个免费版只能保存 3 个历史记录。

Spectacle

https://www.spectacleapp.com/

ssh-key generation

ssh-keygen -t rsa -C "your.email@example.com" -b 4096

部分快捷键

Cmd+Shift+3:全屏截图;截取整个屏幕,保存截图至桌面文件夹。Cmd+Shift+4:区域截图;鼠标光标变成带坐标的小十字,通过拖拽截取特定区域,保存截图至桌面文件夹。Cmd+Shift+4 - 单击空格键 - 鼠标单击指定窗口:窗口截图;出现小十字光标后对指定窗口按空格键,鼠标光标变成照相机,鼠标单击截取指定窗口,保存截图至桌面文件夹。进阶快捷键Cmd+Shift+4 - 按住空格键拖动鼠标:区域截图;选取区域范围后,按住空格键并拖到鼠标可移动选取范围,释放按键后保存截图至桌面文件夹。Cmd+Shift+4 - 按住Shift - 上下/左右移动鼠标:区域截图;选取区域范围后,按住 Shift 并上下/左右移动鼠标即可固定选取范围宽度/高度改变高度/宽度,释放按键后保存截图至桌面文件夹。Cmd+Shift+4 - 按住Shift和Option: 区域截图;选取区域范围后,按住 Shift 和 Option 键在上一快捷键功能的基础上自由切换高度宽度,释放按键后保存截图至桌面文件夹。Cmd+Shift+4 - 按住Option: 区域截图;选取区域范围后,按住 Option 键可按比例缩放选取范围,释放按键后保存截图至桌面文件夹。PS:以上介绍的快捷键配合按住 Control 键即可将截图文件保存在剪切板,以供调用。

蓝牙音频格式

查看当前蓝牙状态

sudo defaults read bluetoothaudiod

开启 aptx

sudo defaults write bluetoothaudiod "Enable AptX codec" -bool true

开启 aac

sudo defaults write bluetoothaudiod "Enable AAC codec" -bool true

资料

https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt

https://github.com/bhilburn/powerlevel9k/wiki/Show-Off-Your-Config

https://medium.com/@Clovis_app/configuration-of-a-beautiful-efficient-terminal-and-prompt-on-osx-in-7-minutes-827c29391961