Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac 环境配置 zsh git nvm node #10

Open
K-Kevin opened this issue Nov 14, 2019 · 2 comments
Open

Mac 环境配置 zsh git nvm node #10

K-Kevin opened this issue Nov 14, 2019 · 2 comments

Comments

@K-Kevin
Copy link
Owner

K-Kevin commented Nov 14, 2019

前几天突然想到每次打开终端,都要手动使用 nvm use 11 来编译打包,就捣鼓了下,然后环境就坏了,今天就加班搞一下吧~

先删除 node、nvm,然后开始

原来打算用 brew 安装 nvm 但是看了 nvm 官方 git 说明安装里不推荐,恰好看到可以用 zsh 插件安装,所以就用 on-my-zsh 安装

Homebrew installation is not supported. If you have issues with homebrew-installed nvm, please brew uninstall it, and install it using the instructions below, before filing an issue.

Note: If you're using zsh you can easily install nvm as a zsh plugin. Install zsh-nvm and run nvm upgrade to upgrade.

step1 安装 zsh-nvm 插件

进入 zsh-nvm 页面看到有 oh-my-zsh 支持,果断选择

As an Oh My ZSH! custom plugin

这里也说一下 on-my-zsh

step2 安装 Oh My ZSH!

查看当前环境shell

echo $SHELL

zsh 设置为默认shell

chsh -s /bin/zsh

下载 oh-my-zsh 并初始化 ~/.zshrc 文件

git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

zsh主题

通过如下命令可以查看可用的Theme

# ls ~/.oh-my-zsh/themes

这里看中一款 Agnoster主题

vim ~/.zshrc

ZSH_THEME="agnoster"
# agnoster 主题设置:只显示当前用户名
prompt_context() {
  if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
    prompt_segment black default "%(!.%{%F{yellow}%}.)$USER"
  fi
}
//设置完毕,运行
source ~/.zshrc

发现有乱码,又查了下,发现是缺少字体,导致箭头展示不了

那就再装字体 Powerline

进入 github 主页找到如下命令:

# clone
git clone https://github.com/powerline/fonts.git --depth=1
# install
cd fonts
./install.sh
# clean-up a bit
cd ..
rm -rf fonts

然后再修改终端字体(或者 iTerm2)

再重启终端,搞定,效果完美!

注意

安装了 on-my-zsh 之后,默认的启动就变成 .zshrc 了,但有些命令会注入到 .bash_profile .bashrc .profile 里,如果忘了改的话,可能会造成环境的一些问题,所以,最好让 .bash_profile .bashrc .profile 和 .zshrc 同时生效,编辑 .zshrc 在末尾添加上即可。

# add by me 2019年11月13日19:55:54
source ~/.bash_profile
source ~/.bashrc
source ~/.profile
关于 .zyx 文本

在 zyx 文本中我加入了一些自己的命令,比如 #shadowsocks proxy 代理方法,可以方便的使用 ip、proxy、unproxy

#shadowsocks proxy
alias proxy='export all_proxy=socks5://127.0.0.1:1080'
alias unproxy='unset all_proxy'
alias ip="curl cip.cc"

那么如何让 zyx 在终端启动后生效呢,只要在 .bash_profile 中加入 [ -r ~/.zyx ] && source ~/.zyx 即可

Step3 这里继续回到 Step1 安装 zsh-nvm 插件

滑到下面可以看到 oh-my-zsh 支持,所以我们选择这一项安装

1)Clone zsh-nvm into your custom plugins repo

git clone https://github.com/lukechilds/zsh-nvm ~/.oh-my-zsh/custom/plugins/zsh-nvm

2)Then load as a plugin in your .zshrc

//这个添加插件要加在 source $ZSH/oh-my-zsh.sh 之前
plugins+=(zsh-nvm)

Keep in mind that plugins need to be added before oh-my-zsh.sh is sourced.

3)运行 source ~/.zshrc 或者重启终端即可进行插件安装了

执行完毕运行 nvm --version 即可知道安装成功了

Step4 安装 node

nvm install node # "node" is an alias for the latest version

nvm install v11.4.0 # or 10.10.0, 8.9.1, etc

Git 重装

VSCode 插件 GitLens 提示 Git 需要 >= 2.7.2,故升级一下 Mac 自带的 git 版本

$ git --version
git version 2.6.3

$ which git
/usr/local/bin/git

Mac 系统自带了 git,要不要先删除或者备份在安装呢,也许会冲突,不过冲突也可以修改环境路径解决,就先安装看看

brew install git

执行完了可以看到报错

Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/git
Target /usr/local/bin/git
already exists. You may want to remove it:
  rm '/usr/local/bin/git'

To force the link and overwrite all conflicting files:
  brew link --overwrite git

To list all files that would be deleted:
  brew link --overwrite --dry-run git

Possible conflicting files are:

按照提示,我们执行如下命令:

brew link --overwrite git

ink 成功后,退出终端后,再次打开。然后查看 git 指向和版本信息

$ which git
/usr/local/bin/git

$ git --version
git version 2.24.0

下次更新只需:

brew update && brew upgrade

@EnD

@K-Kevin K-Kevin changed the title 重装 node Mac 环境配置 zsh git nvm node Nov 14, 2019
@foxundermoon
Copy link

大兄弟 用sourcecodepro+powerline 字体

image

@K-Kevin
Copy link
Owner Author

K-Kevin commented Feb 4, 2020

大兄弟 用sourcecodepro+powerline 字体

image

这个看起来也不错👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants