0%

OMZ配置

mac 安装 Iterm2

1
brew cask install iterm2

查看系统内置shell

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

得到:

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

设置 zsh 为默认shell

1
chsh -s /bin/zsh

安装 oh-my-zsh

1
2
3
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh

cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

修改配色主题

1
2
3
sudo nano ~/.zshrc

主题字段在 ZSH_THEME

使配置生效

1
source ~/.zshrc

语法高亮

1
2
3
4
5
6
7
8
9
10
11
# 下载高亮插件
cd ~/.oh-my-zsh/custom/plugins
git clone git://github.com/zsh-users/zsh-syntax-highlighting.git

# 配置
plugins=(
zsh-syntax-highlighting
)

# 配置生效
source ~/.zshrc

自定义一个命令例子

1
sh /User/minnie/demo/write_blog.sh    # 很繁琐
1,修改系统变量
1
2
3
4
5
6
7
8
9
# 编辑 ~/.bashrc 文件
# User/Minnie/demo 是我的脚本存储目录

export PATH="User/Minnie/demo:$PATH"


# 执行 source ~/.bashrc 使设置生效, 我们就可以这样执行脚本

sh write_blog.sh
2,添加shebang声明
1
2
3
4
5
6
7
8
# 编辑脚本文件, 首行添加声明

#!/bin/bash


# 现在我们可以这样执行脚本

write_blog.sh
3,去除后缀名
1
2
3
4
5
6
7
# 后缀名也是没有意义的

mv write_blog.sh write_blog

# 此时, 命令简化为

write_blog
4,添加alias声明
1
2
3
4
5
6
7
8
# 再次编辑 ~/.bashrc 文件
# 添加 alias 命令

alias wb="write_blog"

# 执行 _source ~/.bashrc_ 使设置生效, 最终成果

wb
问题集锦

为什么不把脚本直接命名为wb, 而是使用alias

1
防止忘记了它的功能.

提示权限拒绝

1
chmod +x write_blog

提示找不到文件

1
shebang声明的路径不对
栗子

自己的写博客脚本bk.sh

1
2
3
4
5
6
7
#!/bin/bash

cd /Users/minnie/hexo/blog
hexo new $1
code ~/hexo/blog/source/_posts/

exit

发布博客脚本fb.sh

1
2
3
4
5
6
7
8
#!/bin/bash

cd /Users/minnie/hexo/blog
hexo clean
hexo g
hexo d

exit