简介
使用命令cat /etc/shells可以查看mac系统下拥有的shell,大概有以下几种。
/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
本篇关于mac系统下自带的zsh,其他Linux系统的安装zsh命令如下
yum install zsh
apt-get install zsh
使用zsh作为shell的原因主要是看上了他的高亮颜色显示和可以拓展的插件。
配置
mac下的默认shell是bash,需要用chsh -s /bin/zsh切换成zsh
(思考,写专门为mac的shell脚本的时候,开头也可以改成#!/bin/zsh了)
Github有个名为ohmyzsh的项目,地址:https://github.com/ohmyzsh/ohmyzsh
一句话安装
wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh
插件
命令自动补全
先下载zsh-autosuggestions插件
cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/zsh-users/zsh-autosuggestions
再编辑~/.zshrc
找到plugins,添加上这个插件的名称即可
plugins=(git
zsh-autosuggestions)
根据官方的演示,使用下面这条命令也可以
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
这样子在输入命令的时候,后面就会有浅色的提示,如果真好猜对了,摁方向键→即可

提示插件
cd ~/.oh-my-zsh/custom/plugins/
wget http://mimosa-pudica.net/src/incr-0.2.zsh
source incr-0.2.zsh
在命令的下方给出提示

命令
目录操作
d
会给出跳转的提示,一般是最近访问过的文件夹,直接输入数字即可跳转。如下图所示。

| Alias | Command |
|---|---|
| alias | list all aliases |
| .. | cd .. |
| … | cd ../.. |
| / | cd / |
| ~ | cd ~ |
| cd +n | switch to directory number n |
| - | cd - |
| 1 | cd - |
| 2 | cd -2 |
| 3 | cd -3 |
| md | mkdir -p |
| rd | rmdir |
| d | dirs -v (lists last used directories) |
Git操作
| Alias | Command |
|---|---|
| g | git |
| ga | git add |
| gcmsg | git commit -m |
| gco | git checkout |
| gf | git fetch |
| gfo | git fetch origin |
| gl | git pull |
| glo | git log –oneline –decorate –color |
| glog | git log –oneline –decorate –color –graph |
| gm | git merge |
| gp | git push |
| gst | git status |