ohmyzsh整理

手动安装

github

https://github.com/ohmyzsh/ohmyzsh

1 克隆仓库

1
2
3
git clone https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh
或者
git clone git@github.com:ohmyzsh/ohmyzsh.git ~/.oh-my-zsh

2 将原来的~/.zshrc备份

1
cp ~/.zshrc ~/.zshrc.bak

3 用新的zsh配置文件

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

4 使得zsh变成默认的shell

1
2
3
nano .bashrc
在第一行添加
zsh

5 配置文件

zsh的配置文件存在当前用户目录中的.zshrc文件,如果你发现切换了shell之后,以前的配置的环境变量不生效了,可以打开 .zshrc文件,找到:

1
2
# User configuration
source ~/.bash_profile

指定配置的环境变量文件,之后运行:

1
source .zshrc

设置主题

设置固定主题

  • 安装完毕后,我们就可以使用了,先来简单配置一下,Oh My Zsh 提供了很多主题风格,我们可以根据自己的喜好,设置主题风格
1
2
3
4
5
6
7
open ~/.zshrc

# 找到 ZSH_THEME
# robbyrussell 是默认的主题
ZSH_THEME="robbyrussell"

# ZSH_THEME="样式名称"
  • 保存这个文件文件,重新打开终端。

设置随机主题

  • 我们还可以随机设置主题:
  • 步骤同上
1
ZSH_THEME="random"
  • 每次打开终端主题是随机的。
  • 终端输出:
1
[oh-my-zsh] Random theme '/Users/xxxx/.oh-my-zsh/themes/zhann.zsh-theme' loaded...
  • 其中 zhann.zsh-theme 是主题的名称, 有喜欢的童鞋可以记录保留.

查看主题名称

  • Oh My Zsh 默认自带了一些默认主题,存放在 ~/.oh-my-zsh/themes 目录中。我们可以查看这些主题
  • 终端输入:
1
cd ~/.oh-my-zsh/themes && ls

卸载 Oh My Zsh

  • 终端输入 :
1
2
uninstall_oh_my_zsh
Are you sure you want to remove Oh My Zsh? [y/N] Y
  • 终端提示信息:
1
2
3
4
5
6
Removing ~/.oh-my-zsh
Looking for original zsh config...
Found ~/.zshrc.pre-oh-my-zsh -- Restoring to ~/.zshrc
Found ~/.zshrc -- Renaming to ~/.zshrc.omz-uninstalled-20170820200007
Your original zsh config was restored. Please restart your session.
Thanks for trying out Oh My Zsh. It's been uninstalled.

插件

manjaro自带插件

自己下载的插件放在/home/kiylx/.oh-my-zsh/custom/plugins/

1
2
3
4
5
6
7
8
9
位置/usr/share/zsh/plugins/
一共三个
zsh-autosuggestions
zsh-history-substring-search
zsh-syntax-highlighting

ps
1.其中zsh-history-substring-search是ohmyzsh自带的,只是名称不同,是history-substring-search
2.zsh-syntax-highligting必须排最后一个

git

这个是装好oh-my-zsh就默认已经开启的

查看所有的git命令alias

1
~/.oh-my-zsh/plugins/git/git.plugin.zsh

z

这个是oh-my-zsh默认就装好的,需要自己开启。还有一个autojump的插件和z功能差不多,autojump需要单独装,

如果z插件历史记录太多,并且有一些不是自己想要的,可以删除

1
z -x 不要的路径

auto-suggestions

1
git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

zsh-syntax-highligting

1
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
## git open 插件
$ git open
# opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/tree/CURRENT_BRANCH

$ git open someremote
# opens https://github.com/PROVIDED_REMOTE_USER/CURRENT_REPO/tree/CURRENT_BRANCH

$ git open someremote somebranch
# opens https://github.com/PROVIDED_REMOTE_USER/CURRENT_REPO/tree/PROVIDED_BRANCH

$ git open --issue
# If branches use naming convention of issues/#123,
# opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/issues/123

$ git open --print
# prints https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/tree/CURRENT_BRANCH

$ git open --suffix pulls
# opens https://github.com/TRACKED_REMOTE_USER/CURRENT_REPO/pulls


thefuck修正命令

github

  • 安装thefuck 使用python的pip
1
pip install thefuck
  • 配置

    .bash_profile, .bashrc, .zshrc or 其他启动脚本文件中添加

    1
    2
    3
    4
    eval $(thefuck --alias)
    # You can use whatever you want as an alias, like for Mondays:
    # 你可以使用其他名称替代默认的别名,比如:
    eval $(thefuck --alias FUCK)

    让配置立即生效,需要重启终端,,或者,输入source ~/.bashrc (或者你的shell配置文件名称 .zshrc).

修改~/.zshrc文件

1
2
3
4
5
6
7
8
9
10
11
12
13
例子
plugins=(
git
pip
extract
z
wd
auto-suggestions
zsh-syntax-highligting
auto-jumplast-working-dir
)

ZSH_THEME="robbyrussell"

如果想要启用某个插件,装好之后直接修改
plugins = (插件A 插件B 插件C)
git
这个是装好oh-my-zsh就默认已经开启的
查看所有的git命令alias
~/.oh-my-zsh/plugins/git/git.plugin.zsh
z
这个是oh-my-zsh默认就装好的,需要自己开启。还有一个autojump的插件和z功能差不多,autojump需要单独装,
如果z插件历史记录太多,并且有一些不是自己想要的,可以删除
z -x 不要的路径


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!