美文网首页
mac iterm2配置

mac iterm2配置

作者: 时光机音乐 | 来源:发表于2019-03-11 20:02 被阅读0次

ZSH

ZSH介绍

Zsh 兼容 Bash,据传说 99% 的 Bash 操作 和 Zsh 是相同的

zsh具有强大的可定制的特点,但是却配置起来十分的麻烦。

Zsh 官网:http://www.zsh.org/

ZSH安装

通常系统默认安装的shell是Bash。

查看系统支持的shell

cat /etc/shells

查询系统默的shell

echo $SHELL

或者

 echo $0

CentOS 安装:sudo yum install -y zsh

Ubuntu 安装:sudo apt-get install -y zsh

再检查下系统的 shell:cat /etc/shells,你会发现多了一个:/bin/zsh

切换为新安装的zsh,然后再查看默认的shell是不是改过来了。

chsh -s /bin/zsh

Zsh 的配置文件位置:用户名/.zshrc

配置环境变量

改为zsh之后,之前bash下的在/etc/profile里配置的java环境变量,已经不能识别了。

经查看文档,发现zsh其实并不使用/etc/profile文件,而是使用/etc/下面的zshenv、zprofile、zshrc、zlogin文件,并以这个顺序进行加载。

应该还有用户目录下的.zshrc 。即 如/Users/kevin/.zshrc 

类似于Bash的.bash_profile

解决办法:vim ~/.zshrc,在该配置文件里面增加一行:source /etc/profile,然后刷新 zsh 的配置:source ~/.zshrc

配置别名

编辑文件:vim ~/.zshrc,在文件加入下面格式的命令

aliascls='clear'

aliasll='ls -l'

aliasla='ls -a'

aliasgrep="grep --color=auto"

使用 Zsh 扩展集合:oh-my-zsh

oh-my-zsh 帮我们整理了一些常用的 Zsh 扩展功能和主题:https://github.com/robbyrussell/oh-my-zsh

我们无需自己去捣搞 Zsh,直接用 oh-my-zsh 就足够了,如果你想继续深造的话那再去弄。

安装oh-my-zsh

使用 crul 安装:

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

或使用wget:

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

插件

安装oh-my-zsh 时,自带安装了很多插件。

ls -l ~/.oh-my-zsh/plugins |grep "^d"|wc -l  可以统计安装的插件数量。

插件推荐:

wd

简单地讲就是给指定目录映射一个全局的名字,以后方便直接跳转到这个目录,比如:

编辑配置文件,添加上 wd 的名字:vim /root/.zshrc

我常去目录:/opt/setups,每次进入该目录下都需要这样:cd /opt/setups

现在用 wd 给他映射一个快捷方式:cd /opt/setups ; wd add setups

以后我在任何目录下只要运行:wd setups就自动跑到 /opt/setups 目录下了

插件官网:https://github.com/mfaerevaag/wd

autojump

这个插件会记录你常去的那些目录,然后做一下权重记录,你可以用这个命令看到你的习惯:j --stat,如果这个里面有你的记录,那你就只要敲最后一个文件夹名字即可进入,比如我个人习惯的 program:j program,就可以直接到:/usr/program

插件官网:https://github.com/wting/autojump

官网插件下载地址:https://github.com/wting/autojump/downloads

插件下载:wget https://github.com/downloads/wting/autojump/autojump_v21.1.2.tar.gz

解压:tar zxvf autojump_v21.1.2.tar.gz

进入解压后目录并安装:cd autojump_v21.1.2/ ; ./install.sh

再执行下这个:source /etc/profile.d/autojump.sh

编辑配置文件,添加上 autojump 的名字:vim /root/.zshrc

zsh-syntax-highlighting

这个插件会对终端命令高亮显示,比如正确的拼写会是绿色标识,否则是红色,另外对于一些shell输出语句也会有高亮显示,算是不错的辅助插件

插件官网:https://github.com/zsh-users/zsh-syntax-highlighting

安装,复制该命令:'git clonehttps://github.com/zsh-users/zsh-syntax-highlighting.git${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting'

编辑:vim ~/.zshrc,找到这一行,后括号里面的后面添加:plugins=( 前面的一些插件名称 zsh-syntax-highlighting)

刷新下配置:source ~/.zshrc

主题

捣搞主题和插件思路一样

oh-my-zsh 的主题列表介绍(还是太长了):https://github.com/robbyrussell/oh-my-zsh/wiki/Themes

我们看下安装 oh-my-zsh 的时候,自带有多少个:ls -l ~/.oh-my-zsh/themes |grep "theme"|wc -l

我个人品味地推荐的是(排名有先后):

ys

agnoster

avit

blinks

编辑配置文件:vim /root/.zshrc,找到下图的地方,怎么安装,原作者注释写得很清楚了,如果你没特别的喜欢那就选择随机吧。

配色方案

我使用的是solarized配色方案,

将solarized.zip解压缩后,请在 iTerm 里按command+,(逗号)快捷键,打开Preferences(选项)对话框

Preferences -> Profiles -> Colors -> Color Presets -> Import

导入iterm2-colors-solarized目录下的两个.itermcolors文件,修改配色方案

Preferences -> Profiles -> Colors -> Color Presets

选择Solarized Dark。

Dracula 也是非常不错的配色方案。见  https://draculatheme.com/iterm/

iterm2的快捷键

相关文章

网友评论

      本文标题:mac iterm2配置

      本文链接:https://www.haomeiwen.com/subject/ezkipqtx.html