Contents

tool:mac电脑常用配置

终端

iterm2

homebrew

一、brew 安装脚本 (自动选择软件源)

1
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

二、brew 卸载脚本

1
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)"

三、常用命令

  • 安装软件:brew install xxx
  • 卸载软件:brew uninstall xxx
  • 搜索软件:brew search xxx
  • 更新软件:brew upgrade xxx
  • 查看列表:brew list
  • 更新brew:brew update
  • 清理所有包的旧版本:brew cleanup
  • 清理指定包的旧版本:brew cleanup $FORMULA
  • 查看可清理的旧版本包,不执行实际操作:brew cleanup -n

brew 替换源

1
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

git

配置

1
2
3
4
git config --global user.name "zhangyuhu"
git config --global user.email "zhangyuhu@didiglobal.com"
ssh-keygen -C 'zhangyuhu@didiglobal.com' -t rsa
cat ~/.ssh/id_rsa.pub

OS 升级后 id_rsa 不可用(需要输入密码)

苹果mac升级系统后,默认不支持rsa方式加密git通讯,所以如果要继续使用这个pub文件加密的方式,则要手动添加cofig配置文件来支持,需要在 ~/.ssh/config文件中新增如下内容:

1
2
3
Host *
    PubkeyAcceptedKeyTypes +ssh-rsa
    HostKeyAlgorithms +ssh-rsa

mac快捷键

通用

Command是Mac里最重要的修饰键,在大多数情况下相当于Windows下的Ctrl。 所以以下最基本操作很好理解:

  • Command + Z 撤销
  • Command + X 剪切
  • Command + C 拷贝(Copy)
  • Command + V 粘贴
  • Command + A 全选(All)
  • Command + S 保存(Save)
  • Command + F 查找(Find)

Mac系统设置git命令自动补全

  1. brew install bash-completion

  2. brew info bash-completion

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
DIDI-FVFDH0A8P3Y1:bash_completion.d didi$ brew info bash-completion
bash-completion: stable 1.3 (bottled)
Programmable completion for Bash 3.2
https://salsa.debian.org/debian/bash-completion
Conflicts with:
  bash-completion@2 (because each are different versions of the same formula)
/usr/local/Cellar/bash-completion/1.3_3 (189 files, 608.3KB) *
  Poured from bottle on 2021-09-15 at 00:40:57
From: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git/Formula/bash-completion.rb
==> Caveats
Add the following line to your ~/.bash_profile:
  [[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Analytics
install: 8,329 (30 days), 25,293 (90 days), 111,168 (365 days)
install-on-request: 7,394 (30 days), 22,291 (90 days), 98,980 (365 days)
build-error: 0 (30 days)
  1. git –version
1
git version 2.30.1 (Apple Git-130)
1
curl https://raw.githubusercontent.com/git/git/v2.30.1/contrib/completion/git-completion.bash -o  /usr/local/etc/bash_completion.d/git-completion.bash
  1. brew unlink bash-completion
  2. brew link bash-completion

mac 使用 zsh

ZSH

查看安装的 shell

1
2
3
4
5
6
7
8
cat /etc/shells

/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh

使用 brew 更新 zsh

1
2
3
4
5
6
brew install zsh

==> Downloading https://homebrew.bintray.com/bottles/zsh-5.5.1.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring zsh-5.5.1.high_sierra.bottle.tar.gz
/usr/local/Cellar/zsh/5.5.1: 1,444 files, 12MB

切换为 zsh

1
chsh -s /bin/zsh

重启终端即可使用 zsh

oh-my-zsh

下载安装脚本

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

配置主题

1
2
ZSH_THEME="bira"
source ~/.zshrc

插件

  • 自动补全插件
1
2
3
4
mkdir ~/.oh-my-zsh/custom/plugins/incr
cd ~/.oh-my-zsh/custom/plugins/incr
wget -O incr.plugin.zsh http://mimosa-pudica.net/src/incr-0.2.zsh
# wget -O ~/.oh-my-zsh/plugins/incr/incr.plugin.zsh http://mimosa-pudica.net/src/incr-0.2.zsh

incr 下载后,还需要在 ~/.zshrc 中添加:

1
2
3
4
5
plugins=(
  zsh-autosuggestions
  git
  incr
)

在 ~/.zshrc 文件末尾添加:

1
source ~/.oh-my-zsh/custom/plugins/incr/incr*.zsh

zsh-syntax-highlighting

官网

作用 平常用的lscd 等命令输入正确会绿色高亮显示,输入错误会显示其他的颜色。

安装

克隆项目

1
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

~/.zshrc 中配置

1
plugins=(其他的插件 zsh-syntax-highlighting)

使配置生效

1
source ~/.zshrc

常用插件:

zsh oh-my-zsh 插件推荐

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
autoload -Uz vcs_info

precmd() {
    vcs_info
}

zstyle ':vcs_info:git:*' formats '%b'
zstyle ':vcs_info:*' enable git

# 定义颜色和样式的转义序列
red_bold="\e[1;31m"
reset="\e[0m"

setopt prompt_subst
PROMPT='$(tput setaf 3)%* $(tput sgr0)$(tput setaf 2)%n@%m$(tput sgr0):$(tput bold)$(tput setaf 4)%2~$(tput sgr0)$(if [[ -n "${vcs_info_msg_0_}" ]]; then echo "${red_bold}(${vcs_info_msg_0_})${reset}"; fi) %# $(tput sgr0)'