文章前言
永远把别人对你的批评记在心里,别人的表扬,就把它忘了。Hello 大家好~!我是南宫墨言QAQ
本文主要是记录自己在使用MacBook过程中使用的一些边界工具,特地记录下与诸位分享,也欢迎各位在自身使用MacBook中一些较好的工具在评论区与大家一起分享
观看到文章最后的话,如果觉得不错,可以点个关注或者点个赞哦!感谢~❤️
文章主体
感谢各位观者的耐心观看,MacBook 使用正片即将开始,且听南宫墨言QAQ娓娓道来
Homebrew
Homebrew是一款MacOS
平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。简单的一条指令,就可以实现包管理,而不用你关心各种依赖和文件路径的情况,十分方便快捷。 通常用于Mac
系统,也可以安装在Linux
系统

安装
输入命令
bash
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

选择安装源

执行脚本并在提示下输入开机密码

开始执行

安装成功,选择今后brew install时的国内镜像

查看Homebrew版本

恭喜你,到此,Homebrew正式安装完成
卸载
bash
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)"
常用指令
- 更新 Homebrew :
brew update
- 查看已安装软件包 :
brew list
- 查看已过时软件包 :
brew outdated
- 搜索软件包 :
brew search
软件包名称 - 安装软件包 :
brew install
软件包名称 - 更新软件包 :
brew upgrade
软件包名称 - 查看软件包信息 :
brew info
软件包名称 - 卸载软件包 :
brew uninstall
软件包名称 - 安装cask软件 :
brew install --cask
软件包名称
iTerm2
iTerm2 是 Terminal
的替代品,也是 iTerm
的后继者。它适用于装有 macOS 10.14
或更高版本的 Mac
。 iTerm2 将终端带入现代,具有您从未意识到您一直想要的功能。
安装
brew install iterm2

安装成功后打开iTerm2终端

配置
恢复上次窗口
Preferences → General → Startup 下可能有个刺眼的黄色警告

消灭它后可以在打开时恢复上次关闭时的窗口状态

设置字体

设置后效果

设置背景图
贴一张背景图,有需要的自取

设置
设置后效果

iTerm2简单设置到此结束==结束,后面将会搭配oh-my-zsh进行更加细致的配置
Oh My Zsh
不搭配oh-my-zsh的 iTerm 是没有灵魂的。oh-my-zsh 是一个令人愉快的开源社区框架,用于管理 Zsh 配置。它捆绑了数以千计的有用功能、助手、插件、主题和一些让你大呼过瘾的东西...
安装
bash
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
安装成功

配置
主题配置
powerlevel10k 是一款极其有质感的主题(以下简称 p10k
),开箱即用,有很棒的逐步设置向导,它可以美化命令行界面,并提供各种实用功能,如显示当前目录、Git 分支信息等。
主题安装
- 执行 官文 中的安装命令即可完成安装:
bash
git clone --depth=1 <https://github.com/romkatv/powerlevel10k.git> ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

- 在 ~/.zshrc 文件中设置主题为 powerlevel10k
ini
# 主题
ZSH_THEME="powerlevel10k/powerlevel10k"
保存后记得执行source ~/.zshrc刷新配置
执行 zsh
命令,它会提示你进行初始化,会帮你下载所需的字体

下载中....

当前阶段效果如下:

语法高亮
语法高亮插件,让命令行更加易读易懂。
- 安装
bash
arch -arm64 brew install zsh-syntax-highlighting

- 在 ~/.zshrc 文件中设置语法高亮
bash
# 语法高亮
source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
- 效果如下:

自动补全
自动补全插件,根据历史命令和当前输入内容,自动推荐可能的命令。
- 安装
bash
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions

- 在 ~/.zshrc 文件中设置自动补全
ini
plugins=(
# other plugins...
# 自动补全
zsh-autosuggestions
)
- 效果如下:

autojump
快速跳转到常用目录的插件,可以加快命令行操作的速度。
- 安装
bash
arch -arm64 brew install autojump

- 在 ~/.zshrc 文件中设置目录跳转提示
ini
plugins=(
# other plugins...
# 目录跳转提示
autojump
)
- 效果如下:

FiraCode
- 安装
bash
brew tap homebrew/cask-fonts

css
brew install --cask font-fira-code

Git
Git 是一个免费的开源 分布式版本控制系统,旨在快速高效地处理从小到大的项目。
Git易于学习,占用 空间小,性能快如闪电。它凭借廉价的本地分支、方便的暂存区域和 多个工作流程等功能,超越了 Subversion、CVS、Perforce 和 ClearCase 等 SCM 工具。
安装
brew install git

配置
由于使用个人电脑开发难免会遇到同时开发个人和公司项目,个人开发用github
,在公司需要使用公司gitlab
的账号,这时候就要区分一下用户,所以下面介绍的是配置多个Git账号的情况:
生成ssh-key
1.进入.ssh文件夹,这是密钥文件存放的路径
bash
cd ~/.ssh/
2.生成 ssh-key
perl
ssh-keygen -t rsa -C "xxx@xxx.com"
注:xxx@xxx.com为你github账号的邮箱,期间修改密钥文件的名称即可,后面的一路回车

3.查看密钥文件
此时.ssh
文件下会出现两个文件,一个是personal_id_rsa
和personal_id_rsa.hub
文件,一个为私钥一个为公钥

添加公钥到git账户
1.查看personal_id_rsa_github_pro.pub密钥内容
bash
cat personal_id_rsa_github_pro.pub

2.复制密钥内容,前往github.com/settings/ke... 添加SSH key


添加成功

添加到ssh-agent
因为默认只读取了id_rsa
,需要让SSH识别新的私钥,使用ssh-add
命令添加
javascript
ssh-add ~/.ssh/personal_id_rsa_github_pro

由于ssh-agent
并不是永久的,只是临时存储,在电脑重启后自然也就会重置,此时进行git操作会报错,所以每次重新启动电脑都需要添加ssh-agent
,解决办法就是在.zshrc
文件中加入命令,每次打开终端就会自动添加
javascript
ssh-add ~/.ssh/personal_id_rsa_github_pro
config添加多个ssh-key
在~/.ssh
下找到一个config
文件,如果没有就新建一个,添加以下配置。
perl
# github
Host git@github.com
HostName https://github.com
User git
IdentityFile ~/.ssh/personal_id_rsa_github_pro
测试一下,-T
后面为上面配置的Host

测试拉取项目

node版本
n 是一个 Node.js
版本管理工具,用于在同一台计算机上轻松安装、切换和管理不同版本的 Node.js
。通过使用 n
,可以方便地在不同的项目中使用不同的 Node.js 版本,以确保项目的兼容性和稳定性。
安装
bash
arch -arm64 brew instal n

相关指令
1.查看n版本
bash
n --version/-V

2.查看 node 远程版本
css
n lsr/ls-remote [--all] // 默认20个,--all展示所有

3.安装稳定版本
bash
n lts/stable

4.安装最新版本
bash
n latest/current

5.安装指定版本
bash
n [install/i] <version>

6.查看 n 管理的 node 版本
bash
n [ls/list/--all]

7.切换node版本
- 7.1.查看当前node版本

- 7.2.输入n查看全部的node版本

- 7.3.通过上下键选择,按回车后切换版本

LocalSend
LocalSend是将文件共享到附近设备的免费、开源、跨平台.只要设备连接同一个wifi就能快速进行文件共享,目前经常使用它进行手机和电脑间文件传输。有需要的小伙伴继续往下看,嘻嘻.

支持多个平台使用

Apifox
Apifox 是集 API 文档、API 调试、API Mock、API 自动化测试多项实用功能为一体的 API 管理平台,定位为 Postman + Swagger + Mock + JMeter
。旨在通过一套系统、一份数据,解决多个工具之间的数据同步问题。只需在 Apifox 中定义 API 文档;API 调试、API 数据 Mock、API 自动化测试等功能就可以直接使用,无需再次定义。API 文档和 API 开发调试流程在同一个工具内闭环,API 调试完成后即可确保与 API 文档定义完全一致。高效、及时、准确!

有兴趣的小伙伴可以了解下,嘻嘻。
switchhosts
SwitchHosts 是一个管理、切换多个 hosts 方案的工具。方便我们快速切换编辑hosts,有需要的小伙伴继续往下看,嘻嘻.
安装
brew install switchhosts

使用 Switch Hosts 加速 Github 访问
Github为什么会访问失败或者缓慢
国内网络访问 Github 速度过慢的原因有许多,但其中最直接和原因是其 CND 域名遭到 DNS 污染,导致我们无法连接使用 GitHub 的加速服务,因此访问速度缓慢。
简单理解:CDN「Content Delivery Network」,即内容分发网络,依靠部署在各地的边缘服务器,平衡中心服务器的负荷,就近提供用户所需内容,提高响应速度和命中率。DNS 污染,是指一些刻意或无意制造出来的数据包,把域名指向不正确的 IP 地址,阻碍了网络访问。
我们默认从目标网址的最近 CDN 节点获取内容,但当节点过远或 DNS 指向错误时,就会操成访问速度过慢或无法访问的问题。
修改Hosts文件可加速Github访问
- 修改本机 Hosts 文件,主动建立域名与 IP 的映射关系,访问到这些域名时直接使用 Hosts 指定的 IP,绕过 DNS 解析。
- 修改网络的 DNS 服务器,换到能够解析出合适 IP 的 DNS 服务器。
可使用ipaddress (opens new window)快速查找到github对应的ip,然后填写进hosts
显然第一种方案更加方便。因为 DNS 服务器储存的映射关系是动态更新的,无法直接控制。直接修改本机 Hosts 文件,锁定域名对应的 IP,更加有效方便。当然,Hosts 文件的作用就是绑定域名与 IP 的映射关系。
新的问题来了
Github对应的IP在不断的变化,如果采用修改Hosts的方法,就需要经常定期手动更新Hosts,非常的麻烦
使用Switch Hosts的自动更新hosts
添加一个新的hosts规则,选择远程
类型,在URL地址中填入,自动更新时间最好是选择一小时更新一次
bash
https://raw.githubusercontent.com/521xueweihan/GitHub520/main/hosts
