一起养成写作习惯!这是我参与「掘金日新计划 · 4 月更文挑战」的第1天,点击查看活动详情。
最近,购入了一个mac,于是把配置自己“称手”开发环境记录了下来,或许别人也需要。
mac安装brew
Installeer Homebrew
以下不需要科学上网即可安装,期间需要输入两次开机密码。
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
复制代码
iTerm2 绚丽终端
要使终端变得花里胡哨且使用上足够方便,这里力荐iTerm2,只需要对它进行稍微的配置,即集颜值与效率于一身。并可通过vim ~/.zshrc
配置文件,配置并集成更多的插件与功能,下面配置几个常用插件,因此可预先
在 .zshrc
中对plugins进行设置plugins=( git zsh-autosuggestion autojump zsh-syntax-highlighting)
,下面是安装与指引。
Oh-My-Zsh配置
Oh My Zsh是一款社区驱动的命令行工具,它基于zsh命令行,提供了主题配置,插件机制,大大提高了可玩(用)性。提升使用效率还能使人愉快hhh
Oh My Zsh is a delightful, open source, community-driven framework for managing your Zsh configuration. It comes bundled with thousands of helpful functions, helpers, plugins, themes, and a few things that make you shout
安装
// GitHub,需要科学上网
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
// 国内镜像,无需科学上网
sh -c "$(curl -fsSL https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh)"
复制代码
默认的主题就很好看了,如果你想更改主题vim ~/.zshrc
对ZSH_THEME
进行配置,这玩意还可以设置各自花里胡哨的背景图,以及coding时的动效什么的,感兴趣的朋友细品。
zsh-syntax-highlighting语法高亮
对于不怎么熟悉Linux命令的孩子可太需要了,它会高亮正确的命令!
安装:brew install zsh-syntax-highlighting
使用:请务必根据安装时输出的信息对.zshrc
进行设置
配置:根据以上打印,在.zshrc键入配置,并通过命令行source ~/.zshrc
应用配置
autojump 配置
用了它之后,在文件系统可以反复横跳,而不需要傻愣愣的一直cd cd cd
实现目录间快速跳转,想去哪个目录直接 j + 目录名(甚至不用输全),不用在频繁的 cd 了
安装:brew install autojump
使用:请务必根据安装时输出的信息对.zshrc
进行设置
zsh-autosuggestions 输入建议
帮助输入而不需要每次都得键入完整的单词,此插件会给输入建议,并补全。
安装:
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
volta-管理node版本
Volta is a hassle-free way to manage your JavaScript command-line tools.
curl https://get.volta.sh | bash
// install node
volta install node
// pin command allows you to choose your Node engine for a project
// pin可以单独为一个项目使用的node版本
volta pin node@12.20
// 检查node版本
node -v
npm -v
复制代码
SSH Key设置-配置多个账号
公司与个人的邮箱不一致,需要生成各自配套的SSH Key,以便在Git操作时区分是哪个账号。
生成 SSH Key
个人
sh-keygen -t rsa -C "439661734@qq.com"
按下回车键后填写SSH Key
相关信息。个人则取名为id_rsa_personal
公司
sh-keygen -t rsa -C "[company]@qq.com"
按下回车键后填写SSH Key
相关信息。个人则取名为id_rsa_company
生成的公钥与私钥文件可能与.ssh同级目录,把它们拖进.ssh目录里面就可以了,如下:
使用SSH Key
把.pub
里的内容添加Github,则可以获得操作Github的权限。
复制Key
Github是个人账号则复制id_rsa_personal.pub
内容,执行命令pbcopy < ~/.ssh/id_rsa_personal.pub
。
设置Key
登录 GitHub 账号,点击 Settings->SSH and GPG keys>New SSH Key 进行添加
公司的账号基本同上,复制pbcopy < ~/.ssh/id_rsa_company.pub
,到此个人Key与公司Key在本地生成后,都添加到对应客户端上了。下面通过config文件做区分,并进行测试吧。
测试Key
cd ~/.ssh
:进入到 .ssh
文件中
touch config
:创建config
文件
vim config
: 修改config文件
如果个人与公司使用的都是Github,则可以设置如下:
# personal
Host personal.github.com
HostName github.com
User Jin
IdentityFile ~/.ssh/id_rsa_personal
# company
Host company.github.com
HostName github.com
User Jin
IdentityFile ~/.ssh/id_rsa_company
复制代码
如果个人用的是Github 和 其他,则设置如下:
# personal
Host github.com
HostName github.com
User Jin
IdentityFile ~/.ssh/id_rsa_personal
# company
Host bitbucket.org # 这个名字可任意设置
HostName bitbucket.org
User Jin
IdentityFile ~/.ssh/id_rsa_company
复制代码
在本地 SSH Agent 中添加 Key
ssh-add -K ~/.ssh/id_rsa_personal
ssh-add -K ~/.ssh/id_rsa_company
复制代码
执行测试:
// 个人与公司使用的都是Github
ssh -T git@personal.github.com
ssh -T git@company.github.com
// 其他
ssh -T git@github.com
ssh -T git@bitbucket.org
复制代码
如果连接成功则会有提示:
常用Vscode插件
javascript console utils
快捷键直接生成console.log,不需要手敲了,debug的好工具
JavaScript (ES6) code snippets
es6代码块,语法提示
vscode-icons
识别文件生成易于辨识的icon,找文件好找些
GitLens
增强Git功能,在vscode中可视化的操作Git,可以看到每一行代码的相关git历史,创建人等
最后, 有其他好用的工具与插件,欢迎留言~ (本人前端)