淘汰掉我的旧MBP换新后,欢天喜地打开Terminal,感觉有点不对,提示符什么时候变成了 %
。
查询了一些资料发现,原来在2019年WWDC期间,苹果推出了macOS Catalina,并且将zsh设置为操作系统默认shell。因为之前我的笔记本都是从EI Captin一路升级上来的,所以没体会到shell的变化,最近新换了笔记本后,才发现默认shell的变化。
苹果在其官网上,也提供了如何更改默认 Shell 的操作步骤。
shell 俗称壳,是用来与 kernel 内核做区分,作用是给计算机使用者提供操作界面,与计算机内核进行交互。它接收用户命令,对命令做解析,然后调用系统中的应用。
shell 有很多种,这里介绍几个常见的shell。
第一个 Unix Shell 是1979年底在V7 Unix(AT&T第7版)中引入的,以它的资助者 Stephen Bourne 命名。Bourne shell 是一个交互式命令解释器和命令变成语言。
Bourne Again Shell (bash)是GNU计划的一部分,用来替代 Bourne shell。现在大多数Linux发行版都适用bash作为默认的shell。
zsh 号称是「终极shell」,从这个称号看出来它的功能应该很强大。zsh的历史也很悠久,保罗·弗斯塔德(Paul Falstad)于1990年在普林斯顿大学求学时编写了Zsh的初版。
zsh具有以下主要功能:
% autoload -U compinit && compinit
% cp -<TAB>
-H -- follow symlinks on the command line in recursive mode
-L -- follow all symlinks in recursive mode
-P -- do not follow symlinks in recursive mode (default)
-R -- copy directories recursively
-X -- don't copy extended attributes or resource forks
-a -- archive mode, same as -RpP
-f -- force overwriting existing file
-i -- confirm before overwriting existing file
-n -- don't overwrite existing file
-p -- preserve timestamps, mode, owner, flags, ACLs, and extended attributes
-v -- show file names as they are copied
% kill <TAB>
2630 ttys000 0:00.09 -zsh
2663 ttys000 0:00.00 -zsh
由上面的例子可以看到,在打开自动完成功能后,使用Tab键可以自动提示cp
命令的可选参数,也能够自动提示出kill
命令可以杀掉的用户进程的pid。
shiqiang@QKing ~ % ls
Desktop Documents Downloads Library Movies Music Parallels Pictures Projects Public
shiqiang@QKing ~ % setopt auto_cd
shiqiang@QKing ~ % Projects
shiqiang@QKing Projects % pwd
/Users/shiqiang/Projects
shiqiang@QKing Projects % unsetopt auto_cd
打开这个选项后,就可以省略cd命令来实现自动切换文件夹。
在我整理资料的过程中,不断的看到一些文章资料介绍
fish shell
并且给它打上90后
最现代
等一系列标签来彰显它的年轻与现代化,出于好奇我也整理试用了一下。
Fish 是 Friendly interactive shell 的简称,默认提供了很多shell需要配置才能有的功能,因此在易用性上有了很大的进步。它的一些功能特性总结如下: