Mac 终端窗口配置 oh-my-zsh

查看当前环境

检查当前使用的shell

Mac 默认使用 bash,当然也可以使用如下命令查看已安装的 shell

bogon:~ himonkey$ echo $SHELL
/bin/bash

查看已经安装的shell

bogon:~ himonkey$ cat /etc/shells 
# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

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

查看当前zsh的版本号

bogon:~ himonkey$ zsh --version
zsh 5.3 (x86_64-apple-darwin18.0)

查看当前最新的zsh版本号,使用homebrew,可以看到当前最新是5.7.1

bogon:~ himonkey$ brew info zsh
zsh: stable 5.7.1 (bottled), HEAD
UNIX shell (command interpreter)
https://www.zsh.org/
Not installed
From: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git/Formula/zsh.rb
==> Dependencies
Required: ncurses ✘, pcre ✘
==> Options
--HEAD
	Install HEAD version
==> Analytics
install: 41,546 (30 days), 122,176 (90 days), 572,107 (365 days)
install_on_request: 39,529 (30 days), 117,505 (90 days), 538,051 (365 days)
build_error: 0 (30 days)

brew 安装最新 zsh

原系统的 zsh 不动它,使用 brew 安装最新的 zsh 。

bogon:~ himonkey$ brew install zsh
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/cask-versions and homebrew/cask).

==> Installing dependencies for zsh: ncurses and pcre
==> Installing zsh dependency: ncurses
==> Downloading https://homebrew.bintray.com/bottles/ncurses-6.1.mojave.bottle.t
==> Downloading from https://akamai.bintray.com/01/01e031f6bb1513edcb26d78a15dc5
######################################################################## 100.0%
==> Pouring ncurses-6.1.mojave.bottle.tar.gz
==> Caveats
ncurses is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have ncurses first in your PATH run:
  echo 'export PATH="/usr/local/opt/ncurses/bin:$PATH"' >> ~/.bash_profile

For compilers to find ncurses you may need to set:
  export LDFLAGS="-L/usr/local/opt/ncurses/lib"
  export CPPFLAGS="-I/usr/local/opt/ncurses/include"

==> Summary
🍺  /usr/local/Cellar/ncurses/6.1: 3,869 files, 8.3MB
==> Installing zsh dependency: pcre
==> Downloading https://homebrew.bintray.com/bottles/pcre-8.43.mojave.bottle.tar
==> Downloading from https://akamai.bintray.com/08/08e7414a7641d1e184c936537ff67
######################################################################## 100.0%
==> Pouring pcre-8.43.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/pcre/8.43: 204 files, 5.5MB
==> Installing zsh
==> Downloading https://homebrew.bintray.com/bottles/zsh-5.7.1.mojave.bottle.tar
==> Downloading from https://akamai.bintray.com/79/793d87f67e64a5e01dfdea890af21
######################################################################## 100.0%
==> Pouring zsh-5.7.1.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/zsh/5.7.1: 1,515 files, 13.3MB
==> Caveats
==> ncurses
ncurses is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have ncurses first in your PATH run:
  echo 'export PATH="/usr/local/opt/ncurses/bin:$PATH"' >> ~/.bash_profile

For compilers to find ncurses you may need to set:
  export LDFLAGS="-L/usr/local/opt/ncurses/lib"
  export CPPFLAGS="-I/usr/local/opt/ncurses/include"

再次运行 zsh --version 查看到的 zsh 版本仍为 5.3 ,我们可以查看一下 /etc/shells 文件中的 zsh 仍为 上述查看的那样,我们需要把 brew 安装的 zsh 添加到 shells 文件中。

# 查看 brew 安装到 zsh 的位置
bogon:~ himonkey$ brew list zsh
/usr/local/Cellar/zsh/5.7.1/bin/zsh
/usr/local/Cellar/zsh/5.7.1/bin/zsh-5.7.1
/usr/local/Cellar/zsh/5.7.1/lib/zsh/ (36 files)
/usr/local/Cellar/zsh/5.7.1/share/info/ (8 files)
/usr/local/Cellar/zsh/5.7.1/share/man/ (17 files)
/usr/local/Cellar/zsh/5.7.1/share/zsh/ (1446 files)

brew 安装到文件的位置

  1. 通过brew install安装应用最先是放在/usr/local/Cellar/目录下。

  2. 有些应用会自动创建软链接放在/usr/bin或者/usr/sbin,同时也会将整个文件夹放在/usr/local

所以在 /etc/shells 文件中添加 /usr/local/Cellar/zsh/5.7.1/bin/zsh-5.7.1 还是 /usr/local/bin/zsh-5.7.1 都是一样的。下面也验证了这一点。

bogon:~ himonkey$ ls -al /usr/local/bin
total 0
drwxrwxr-x  19 himonkey  admin  608 11 11 10:36 .
drwxr-xr-x  15 root      wheel  480 11  1 16:24 ..
lrwxr-xr-x   1 himonkey  admin   28 11  1 16:30 brew -> /usr/local/Homebrew/bin/brew
......
lrwxr-xr-x   1 himonkey  admin   27 11 11 10:36 zsh -> ../Cellar/zsh/5.7.1/bin/zsh
lrwxr-xr-x   1 himonkey  admin   33 11 11 10:36 zsh-5.7.1 -> ../Cellar/zsh/5.7.1/bin/zsh-5.7.1

添加最新zsh

使用 vim 这 /bin/zsh 前按 a 键在当前光标位置输入。 注释掉 /bin/zsh

bogon:~ himonkey$ sudo vim /etc/shells 
Password:

# List of acceptable shells for chpass(1).
# Ftpd will not allow users to connect who are not using
# one of these shells.

/bin/bash
/bin/csh
/bin/ksh
/bin/sh
/bin/tcsh
# /bin/zsh
/usr/local/Cellar/zsh/5.7.1/bin/zsh-5.7.1
~                                                                               
~                                                                               
~                                                                               
~                                                                               
:wq                                                                             

重启终端就可以用 zsh --version 查看到当前 zsh 版本换为 5.7 的。

将当前 bash 终端切换为 zsh, 使用 chsh -s 路径 然后输入密码,重启就行了。切换回 bash 也一样操作。

bogon:~ himonkey$ zsh --version
zsh 5.7.1 (x86_64-apple-darwin18.2.0)
bogon:~ himonkey$ chsh -s /usr/local/Cellar/zsh/5.7.1/bin/zsh-5.7.1
Changing shell for himonkey.
Password for himonkey: ****

重启终端就切换到 zsh 了。显示信息如下,
它会提醒你这是配置函数 你的主目录(也就是 ~ 目录)没有配置文件。

屏幕快照 2019-11-11 下午1.09.31

This is the Z Shell configuration function for new users,
zsh-newuser-install.
这是新用户的Z Shell配置函数,zsh-newuser-install。
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~). This function can help you with a few settings that should
make your use of the shell easier.
您看到这条消息是因为您没有zsh启动文件(目录~中的.zshenv、.zprofile、.zshrc、.zlogin文件)。这个函数可以帮助您进行一些设置,使您更容易地使用shell。
You can:
你可以:
(q) Quit and do nothing. The function will be run again next time.
(q)退出,什么都不做。该函数将在下一次再次运行。
(0) Exit, creating the file ~/.zshrc containing just a comment.
That will prevent this function being run again.
(0)退出,创建文件~/。只包含注释的zshrc。这将阻止该函数再次运行。
(1) Continue to the main menu.
(1)继续进入主菜单。
--- Type one of the keys in parentheses ---

按 1 进入主菜单

请选择以下选项之一:
(1)配置历史设置,即命令行记住和保存的外壳。
(2)配置新的补全系统。
(3)配置键在编辑命令行时的行为方式。(推荐)
(4)选择一些更常见的shell选项。这些是简单的“开”或“关”开关控制外壳的功能。
(0)退出,创建一个空白~/.zshrc中。
(a)中止所有设置,从零开始。注意,这将覆盖任何设置从zsh-newuser-install已经在启动文件。但是,它不会改变您的任何其他设置。
(q)退出不干别的。该函数将在下一次再次运行。
——在括号中键入一个键——

直接输入一个 0 会在 ~ 目录下生成一个空的 .zshrc 配置文件。

安装 oh-my-zsh 配置主题和插件

安装 oh-my-zsh

可以看一下 ~ 目录下是否有 .oh-my-zsh 文件,当然是没有。开始安装后

bogon% ls -al
total 56
drwxr-xr-x+ 23 himonkey  staff    736 11 11 17:08 .
drwxr-xr-x   5 root      admin    160 10 22 18:13 ..
-r--------   1 himonkey  staff      9 10 22 18:13 .CFUserTextEncoding
-rw-r--r--@  1 himonkey  staff  10244 11 11 16:42 .DS_Store
drwx------  19 himonkey  staff    608 11 11 16:54 .Trash
drwxr-xr-x   3 himonkey  staff     96 11  3 12:54 .android
-rw-------   1 himonkey  staff    660 11 11 12:48 .bash_history
drwx------  42 himonkey  staff   1344 11 11 12:48 .bash_sessions
drwxr-xr-x   3 himonkey  staff     96 11  1 19:09 .oracle_jre_usage
drwxr-xr-x   3 himonkey  staff     96 11  1 19:09 .vim
-rw-------   1 himonkey  staff   3627 11 11 17:08 .viminfo
-rw-r--r--   1 himonkey  staff     31 11 11 16:55 .zshrc
drwx------@  4 himonkey  staff    128 11  8 21:19 Applications
drwx------+  4 himonkey  staff    128 11 11 16:54 Desktop
drwx------+  4 himonkey  staff    128 10 25 01:11 Documents
drwx------+  5 himonkey  staff    160 11  8 22:31 Downloads
drwx------+ 64 himonkey  staff   2048 11  2 12:42 Library
drwx------+  3 himonkey  staff     96 10 22 18:13 Movies
drwx------+  6 himonkey  staff    192 11  8 21:15 Music
drwx------+  6 himonkey  staff    192 11  8 21:48 Pictures
drwxr-xr-x+  5 himonkey  staff    160 10 23 19:53 Public
drwxr-xr-x   6 himonkey  staff    192 10 23 22:13 tool
drwxr-xr-x   6 himonkey  staff    192 10 23 22:13 work

使用命令安装
curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
有安装当然有卸载

bogon% curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0
100  8109  100  8109    0     0   4200      0  0:00:01  0:00:01 --:--:--  4200
Cloning Oh My Zsh...
正克隆到 '/Users/himonkey/.oh-my-zsh'...
remote: Enumerating objects: 1102, done.
remote: Counting objects: 100% (1102/1102), done.
remote: Compressing objects: 100% (1054/1054), done.
remote: Total 1102 (delta 23), reused 882 (delta 19), pack-reused 0
接收对象中: 100% (1102/1102), 721.26 KiB | 435.00 KiB/s, 完成.
处理 delta 中: 100% (23/23), 完成.

Looking for an existing zsh config...
Found ~/.zshrc. Backing up to /Users/himonkey/.zshrc.pre-oh-my-zsh
Using the Oh My Zsh template file and adding it to ~/.zshrc.

         __                                     __
  ____  / /_     ____ ___  __  __   ____  _____/ /_
 / __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \
/ /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / /
\____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/
                        /____/                       ....is now installed!


Please look over the ~/.zshrc file to select plugins, themes, and options.

p.s. Follow us on https://twitter.com/ohmyzsh

p.p.s. Get stickers, shirts, and coffee mugs at https://shop.planetargon.com/collections/oh-my-zsh

Run zsh to try it out.
bogon% ls
Applications	Downloads	Music		tool
Desktop		Library		Pictures	work
Documents	Movies		Public
bogon% ls -al
total 64
drwxr-xr-x+ 25 himonkey  staff    800 11 11 20:25 .
drwxr-xr-x   5 root      admin    160 10 22 18:13 ..
-r--------   1 himonkey  staff      9 10 22 18:13 .CFUserTextEncoding
-rw-r--r--@  1 himonkey  staff  10244 11 11 16:42 .DS_Store
drwx------  19 himonkey  staff    608 11 11 16:54 .Trash
drwxr-xr-x   3 himonkey  staff     96 11  3 12:54 .android
-rw-------   1 himonkey  staff    660 11 11 12:48 .bash_history
drwx------  42 himonkey  staff   1344 11 11 12:48 .bash_sessions
drwxr-xr-x  19 himonkey  staff    608 11 11 20:25 .oh-my-zsh
drwxr-xr-x   3 himonkey  staff     96 11  1 19:09 .oracle_jre_usage
drwxr-xr-x   3 himonkey  staff     96 11  1 19:09 .vim
-rw-------   1 himonkey  staff   3627 11 11 17:08 .viminfo
-rw-r--r--   1 himonkey  staff   3570 11 11 20:25 .zshrc
-rw-r--r--   1 himonkey  staff     31 11 11 16:55 .zshrc.pre-oh-my-zsh
drwx------@  4 himonkey  staff    128 11  8 21:19 Applications
drwx------+  4 himonkey  staff    128 11 11 16:54 Desktop
drwx------+  4 himonkey  staff    128 10 25 01:11 Documents
drwx------+  5 himonkey  staff    160 11  8 22:31 Downloads
drwx------+ 64 himonkey  staff   2048 11  2 12:42 Library
drwx------+  3 himonkey  staff     96 10 22 18:13 Movies
drwx------+  6 himonkey  staff    192 11  8 21:15 Music
drwx------+  6 himonkey  staff    192 11  8 21:48 Pictures
drwxr-xr-x+  5 himonkey  staff    160 10 23 19:53 Public
drwxr-xr-x   6 himonkey  staff    192 10 23 22:13 tool
drwxr-xr-x   6 himonkey  staff    192 10 23 22:13 work

这时候重启终端再看 .zshrc 文件中有了如下内容。其实就是上面安装了 oh-my-zsh 的时候,脚本帮我们把原来存在的 .zshrc 文件备份成 .zshrc.pre-oh-my-zsh 将自己的配置文件更改成 .zshrc.
刚好我原来的 .zshrc 文件是空的,那就把备份的 .zshrc.pre-oh-my-zsh 给删掉。
bogon% vi .zshrc

➜  ~ vi .zshrc 
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="/Users/himonkey/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="robbyrussell"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.

即使上面的不小心误修改了,不用担心可以找到 ~/.oh-my-zsh/templates 下的 zshrc.zsh-template 这个文件和上面一致。

开始各种造。

安装各种插件
我想安装的:

  • Powerline 状态行插件
  • 主题 powerlevel10k
  • 语法高亮和语法自动建议插件
  • colorls 是一个 ruby gem,可使用颜色和超棒的字体图标美化终端

主题 powerlevel10k

设置方法:vim ~/.zshrc, 找到ZSH_THEME=“”,这句话,在双引号里面写上cloud就可以啦!

如果你在里面写的是random,每次开启终端的主题将是随机的!

当然你也可以自己找主题,oh-my-zsh里面带有主题了,主题都在以下这个文件夹里,可以进去找自己喜欢的
~/.oh-my-zsh/themes

当然啦这里面没有我喜欢的,哈哈。我需要安装powerlevel10k。

主题的介绍
它的介绍是这样的,注意关键字:兼容 Powerlevel9k,10-100倍的性能提升!具体自己去看
https://github.com/romkatv/powerlevel10k

安装
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k

安装完成的主题放在 ~/.oh-my-zsh/custom/themes 文件夹下。

➜  themes git:(master) git clone --depth=1 https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k
正克隆到 '/Users/himonkey/.oh-my-zsh/custom/themes/powerlevel10k'...
remote: Enumerating objects: 38, done.
remote: Counting objects: 100% (38/38), done.
remote: Compressing objects: 100% (34/34), done.
remote: Total 38 (delta 3), reused 13 (delta 0), pack-reused 0
展开对象中: 100% (38/38), 完成.

修改主题的配置
vi ~/.zshrc
修改主题配置如下所示

ZSH_THEME="powerlevel10k/powerlevel10k"

重启终端,你会看到如下图
屏幕快照 2019-11-11 下午10.01.14

其实这是Powerlevel10k配置向导。您看到它是因为您没有定义任何Powerlevel10k配置选项。它将询问您几个问题并配置提示符。这看起来像钻石(旋转的正方形)吗?

如果你看到的和我一样也就是说你的字体不支持这么多符号,这就需要我门安装字体了。

然后一路设置下去 我们会看到

New config: ~/.p10k.zsh.
Backup of ~/.zshrc: $TMPDIR/.zshrc.eOlXszNdzA.

See ~/.zshrc changes:

  diff $TMPDIR/.zshrc.eOlXszNdzA ~/.zshrc
File feature requests and bug reports at
https://github.com/romkatv/powerlevel10k/issues.
  • 想重新配置该主题, 如果你不喜欢它。你可以随时直接输入 p10k configure 命令来运行 powerline10k 向导。即可重新配置并覆盖掉 ~/.p10k.zsh 文件。
  • 移除插件,这是GitHub上给的方法。可以看到改动还是很少的。实际却生成了一个 ~/.p10k.zsh 文件.
    This method of installation won't make anything slower or otherwise sub-par.
    比较了一下异同也就能知道, 该主题在 ~/.zshrc 中添加了两部分内容, 一个是前面 1 到 7 行和后面 107 到109 行。
❯ diff $TMPDIR/.zshrc.eOlXszNdzA ~/.zshrc
0a1,7
> # Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
> # Initialization code that may require console input (password prompts, [y/n]
> # confirmations, etc.) must go above this block, everything else may go below.
> if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
>   source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
> fi
> 
99a107,109
> 
> # To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
> [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh

所以 删除 ~/.zshrc 中添加了两部分内容、删除 ~/.p10k.zsh 文件、 删除 ~/.oh-my-zsh/custom/themes/powerlevel10k 文件夹

安装字体

安装完 powerlevel10k 后你可能会发现有乱码,这是因为你终端字体不支持那么多的字符,这就需要使用扩展字体了。
安装 powerline 字体有四种方式:
1: Install Powerline Fonts
2: Use a Programmer Font
3: Install Awesome-Powerline Fonts
4: Install Nerd-Fonts
Nerd 字体应该是支持字形最多的,所以不用多想,安装它就好了!
github 上也有详细的安装介绍文档:https://github.com/ryanoasis/nerd-fonts#font-installation

Nerd字体预览:https://app.programmingfonts.org/

安装字体第一种 homebrew

GitHub 上有详细的安装教程中可以使用 homebrew 安装,如果能已经添加过 homebrew/cask-fonts 仓库,那就下面代码中第一行就可以省略了,直接执行第二行的语句就行。

$ brew tap homebrew/cask-fonts  # you only have to do this once!
$ brew cask install font-inconsolata

当然 我是直接下载的 ttf 文件双击安装字体的。怎么安装字体都行,安装完事儿后 只需在 终端的偏好设置中选择安装的字体就行。
设置终端字体的步骤

安装字体的第二种方式 字体文件安装

访问 nerd 网站 https://www.nerdfonts.com/
按照图中所示 找到 hack 字体下载
字体下载步骤

下载下来的是一个 zip 文件,双击解压 就可以安装其中的字体,里面字体有重复的 我最终只安装了四个字体,其中也就 Hack Regular Nerd Font Complete Mono 字体完全适用。

安装 oh-my-zsh 插件

插件存储在 ~/.oh-my-zsh/plugins 文件夹中。要激活插件,你需要编辑 ~/.zshrc 文件。安装插件意味着你创建了一系列执行特定功能的别名或快捷方式。
安装插件也和安装 主题一样,大同小异不做过多解释。文件最好都放在 ~/.oh-my-zsh/custom/plugings/文件中。
都是使用 git 克隆过来。
然后在 ~/.zshrc 的插件列表中。
plugins=( [plugins...] zsh-syntax-highlighting zsh-autosuggestions )

  • 语法高亮插件 git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  • 和语法自动建议插件 git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

安装 colorls 彩色的文件夹和图标

colorls 是一个 ruby gem,可使用颜色和超棒的字体图标美化终端的 ls 命令。你可以访问官方网站以获取更多信息。

sudo gem install colorls

# sudo gem uninstall colorls

安装的截图

通过在shell配置文件中输入以下行 来启用 colorls 的选项启用制表符补完功能,只需在 shell 配置末尾(~/.bashrc 或者 ~/.zshrc)输入以下行:

source $(dirname $(gem which colorls))/tab_complete.sh

反正这个配置我是加不上, 也不知道有什么作用。反正我加了用下面指令

echo $(dirname $(gem which colorls))

会输出路径然后拼合起来得到路径。具体看我的配置文件中 source /Library/Ruby/Gems/2.3.0/gems/colorls-1.2.0/lib/tab_complete.sh
安装完成后的显示界面,带图标的文件夹

可以看到 ls 指令仍然是原来的样子,每次都需要输入 colorls 来完成。所以为防止每次输入 colorls,你可以在 ~/.bashrc 或 ~/.zshrc 中创建别名。

alias ll='colorls -lA --sd --gs --group-directories-first'
alias ls='colorls --group-directories-first'

tree 命令来查看当前目录下的目录树

没适应mac的finder, 但是觉得 Linux 的 tree 命令好用。
从网上找到了一个shell 命令打印 tree 结构的方法.

find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'

为了以后不用输入这么复杂的语句,使用 alias 指定别名的方法,在 ~/.bashrc 或 ~/.zshrc 中创建别名。

alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"

但我更喜欢 brew install tree 安装的 tree ,因为它支持的指令更多。

最后的最后

附上我的 .zshrc 的内容

# 启用Powerlevel10k即时提示.应该靠近~/.zshrc的顶部.
# 可能需要控制台输入的初始化代码(密码提示,[y/n]
# 确认书等)必须放在这一块上面,其他的都可以放在下面.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

# 如果你来自bash,你可能不得不改变你的 $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# 你的oh my zsh安装路径.
export ZSH="/Users/himonkey/.oh-my-zsh"

# 设置要加载的主题的名称---如果设置为"random",则将
# 每次加载oh my zsh时加载一个随机主题,在这种情况下,
# 要知道加载了哪个特定的主题,请运行: echo $RANDOM_THEME
# 参见https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="powerlevel10k/powerlevel10k"

# 设置随机加载时要从中选取的主题列表
# 在ZSH_THEME=random时设置此变量将导致ZSH加载
# 一个来自这个变量的主题,而不是查看 ~/.oh-my-zsh/themes/
# 如果设置为空数组,则此变量将无效.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )


# 取消对以下行的注释以使用区分大小写的完成方式.
# CASE_SENSITIVE="true"

# 取消对以下行的注释以使用不区分连字符的完成方式.
# 必须关闭区分大小写的完成. _ 和 - 可以互换.
# HYPHEN_INSENSITIVE="true"

# 取消注释以下行以禁用每两周一次的自动更新检查.
# DISABLE_AUTO_UPDATE="true"

# 取消对以下行的注释以自动更新而不提示.
# DISABLE_UPDATE_PROMPT="true"


# 取消对以下行的注释以更改自动更新的频率(以天为单位).
# export UPDATE_ZSH_DAYS=13

# 如果粘贴URL和其他文本时出错,请取消对以下行的注释.
# DISABLE_MAGIC_FUNCTIONS=true

# 取消注释以下行以禁用ls中的颜色.
# DISABLE_LS_COLORS="true"

# 取消注释以下行以禁用自动设置终端标题.
# DISABLE_AUTO_TITLE="true"

# 取消对以下行的注释以启用命令自动更正.
# ENABLE_CORRECTION="true"

# 取消注释以下行以在等待完成时显示红点.
# COMPLETION_WAITING_DOTS="true"

# 如果要禁用标记未跟踪的文件,请取消对以下行的注释
# 在VCS下是肮脏的.这将检查大型存储库的存储库状态
# 非常, 非常快.
# DISABLE_UNTRACKED_FILES_DIRTY="true"


# 如果要更改命令执行时间,请取消对以下行的注释
# 历史命令输出中显示的戳记.
# 您可以设置三种可选格式之一:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# 或者使用strftime函数格式规范设置自定义格式,
# 详情请参阅"man strftime".
# HIST_STAMPS="mm/dd/yyyy"

# 是否要使用 $ZSH/custom 之外的其他自定义文件夹?
# ZSH_CUSTOM=/path/to/new-custom-folder

# 您想加载哪些插件?
# 标准插件可以在 ~/.oh-my-zsh/plugins/* 中找到
# 自定义插件可以添加到  ~/.oh-my-zsh/custom/plugins/
# 示例格式: plugins=(rails git textmate ruby lighthouse)
# 明智地添加,因为太多的插件会减慢shell的启动速度.
plugins=(
 git
 zsh-syntax-highlighting
 zsh-autosuggestions
)

source $ZSH/oh-my-zsh.sh

# 用户配置

# export MANPATH="/usr/local/man:$MANPATH"

# 您可能需要手动设置语言环境
# export LANG=en_US.UTF-8

# 本地和远程会话的首选编辑器
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# 编译标志
# export ARCHFLAGS="-arch x86_64"

# 设置个人别名,覆盖 oh-my-zsh libs 提供的别名,
# 插件 plugins, 和主题 themes. Aliases 可以放在这里, 通过 oh-my-zsh
# 鼓励用户在 ZSH_CUSTOM 文件夹中定义别名.
#
# 要获得活动别名的完整列表,请运行"alias".
#
# 别名示例
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"

# 防止每次输入 "colorls" 所以为 colorls 的常用操作设置别名
alias ll='colorls -lA --sd --gs --group-directories-first'
alias ls='colorls --group-directories-first'
# 一个shell 命令打印 tree 结构的方法查看当前目录下的目录树结构
alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"

# 若要自定义提示,请运行 `p10k configure` 或编辑 ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh

# 为 colorls 的选项启用制表符补完功能,只需在 shell 配置末尾输入以下行
# source $(dirname ($gem which colorls))/tab_complete.sh
 source /Library/Ruby/Gems/2.3.0/gems/colorls-1.2.0/lib/tab_complete.sh
posted @ 2019-11-13 21:49  Monkey_Hi_猴子喂  阅读(8243)  评论(0编辑  收藏  举报