Ars Asks: Share your shell and show us your tricked-out terminals!

Ars Asks: Share your shell and show us your tricked-out terminals!

Ars 问答:分享你的 Shell,展示你那炫酷的终端!

I spend more time today than ever before interacting with terminal windows, which is something I don’t think Past Me would have believed in the early ’90s. Back then, poor MS-DOS was the staid whipping boy of the industry, and at least on the consumer side, graphical environments like Windows (and maybe even odder creatures like AmigaOS) seemed poised to stamp the command line into oblivion, leaving text interfaces behind as we all blasted into the ooey-GUI future.

如今,我花在与终端窗口交互上的时间比以往任何时候都要多,这在 90 年代初是当时的我想都不敢想的。那时,可怜的 MS-DOS 是业界沉闷的“出气筒”。至少在消费端,像 Windows(甚至像 AmigaOS 这样更奇怪的系统)这样的图形界面似乎注定要将命令行彻底淘汰,让我们在奔向“图形界面未来”的过程中抛弃文本交互。

As it turns out, though, the command line is still the best tool for some jobs—many jobs, in fact. I read a wise post some years ago (probably on Slashdot) arguing that a mouse-driven point-and-click interface essentially reduces the user to pointing at something on the screen and grunting, “DO! DO THAT!” at the computer. (The rise of right-click context menus adds the ability for the user to also grunt “MORE THINGS!” but doesn’t otherwise add vocabulary.) The command line, by contrast, gives the user the opportunity to precisely tell the computer what they want done, using words instead of one or two gestalts that the computer must interpret based on context.

然而事实证明,命令行仍然是完成某些工作——实际上是许多工作——的最佳工具。几年前我读过一篇很有见地的文章(可能是在 Slashdot 上),文中指出,鼠标驱动的“点击式”界面本质上是将用户降格为对着屏幕指指点点,并向计算机嘟囔着:“做!做那个!”(右键上下文菜单的出现让用户能多嘟囔一句“做更多事!”,但并没有增加实质性的词汇量。)相比之下,命令行让用户有机会通过文字精确地告诉计算机想要执行的操作,而不是依赖计算机根据上下文去解读那一两个模糊的指令。

It sounds kind of silly to say it, but the command line is what finally dragged me off Windows as my daily driver back in 2007. At the time, I’d been forced into regular bash usage at work as I took over the day-to-day administration of Boeing Houston’s fleet of then-brand-new EMC Celerra NSX enterprise NAS appliances, and while there were GUI management options available (I am perhaps triggering trauma in a small subset of older readers by saying the words “EMC Control Center”), the environment I’d inherited was firmly held together by bash scripts.

说出来可能有点傻,但正是命令行在 2007 年最终让我放弃了 Windows 作为主力系统。当时,我在工作中被迫频繁使用 bash,因为我接手了波音休斯顿分部当时全新的 EMC Celerra NSX 企业级 NAS 设备群的日常管理工作。虽然当时也有图形化管理选项(提到“EMC Control Center”这几个字可能勾起了部分老读者的一些创伤),但我所接手的环境完全是由 bash 脚本支撑起来的。

At first, I had turned up my nose at the Linux-ness of it all, but kind of like the fungus in The Last of Us, the shell’s tendrils slowly infected my brain. I began to realize that sad old cmd.exe and MS-DOS batch files really were kind of terrible, and that maybe, just maybe, the Linux-y ravings of my angry graybeard sysadmin mentor were not as crazy as they seemed. I didn’t think I’d ever arrive at his method of only running manually compiled Slackware—and, indeed, 20 years on, I’m still not even close—but the guy had a point.

起初,我对这一切“Linux 味儿”嗤之以鼻,但就像《最后生还者》里的真菌一样,Shell 的触须慢慢侵蚀了我的大脑。我开始意识到,那令人沮丧的旧 cmd.exe 和 MS-DOS 批处理文件确实很糟糕,也许,仅仅是也许,我那位脾气暴躁的资深系统管理员导师对 Linux 的狂热推崇并没有看起来那么疯狂。我没想过自己会达到他那种只运行手动编译的 Slackware 的境界——事实上,20 年过去了,我依然相去甚远——但他确实说得有道理。

The more I used a Unix-y shell at work, the more I began to miss it at home. Windows Vista and its early WDDM woes had reduced my previously badass main PC with two Nvidia 7900GT cards in SLI to a stuttering BSOD-spitting mess, and the future of Microsoft OSes looked bleak—Windows 7 wouldn’t be along to change the situation for years. Exposure therapy to the bash shell brought me to the tipping point, and I jumped ship to the Macintosh side of the house. It was a move calculated to give me the best of all possible worlds—a good graphical interface with the same bash shell under the hood that I’d come to depend on at work.

在工作中使用的 Unix 类 Shell 越多,我就越在家里怀念它。Windows Vista 及其早期的 WDDM 问题,让我那台曾经配备双 Nvidia 7900GT SLI 的强悍主机变成了一台卡顿且频繁蓝屏的废铁,而微软操作系统的未来看起来也一片黯淡——Windows 7 还要好几年才能到来改变现状。对 bash shell 的“暴露疗法”让我达到了临界点,于是我转投了 Macintosh 阵营。这是一个经过深思熟虑的决定,旨在获得两全其美的效果:既有优秀的图形界面,底层又拥有我在工作中已经产生依赖的 bash shell。

I haven’t looked back. These days, I run three different operating systems at home. MacOS is still my daily driver on the desktop; Windows lives on the gaming PC in the corner; and Linux (in the form of Ubuntu server LTS) is headless in the closet, where it belongs. God is in his heaven, and all is right with my computing world—and still, as with every day since sometime in early 2007, I spend at least an hour or two with a terminal window doing things the old-fashioned, text-y way.

从此我再也没有回头。如今,我在家里运行着三种不同的操作系统。MacOS 依然是我桌面上的主力;Windows 运行在角落里的游戏 PC 上;而 Linux(以 Ubuntu Server LTS 的形式)则在壁橱里以无头模式运行,待在它该待的地方。上帝在天堂,我的计算世界一切安好——而且,正如自 2007 年初以来的每一天一样,我每天至少会花一两个小时在终端窗口里,用那种老派的、纯文本的方式处理事务。

The fish shell long ago became my default on my Mac, in no small part because I like fish’s colors and find them helpful (don’t judge me!). When I’m logged into Linux, though, I stick with good old bash. I know zsh and other modern alternatives have their fans, but I’ve found my happy place, and I’m content to stay there. Being a child of the BBS era, when ANSI graphics were the hotness, I have spent about as much time as any other terminal-enjoying admin customizing my environment and making it into a place where I feel comfy working.

Fish shell 早已成为我 Mac 上的默认 Shell,很大程度上是因为我喜欢它的配色,并觉得它们很有帮助(别评判我!)。不过,当我登录 Linux 时,我还是坚持使用老派的 bash。我知道 zsh 和其他现代替代品有很多拥趸,但我已经找到了属于自己的舒适区,并乐于待在那里。作为 BBS 时代的孩子,在 ANSI 图形还是潮流的年代,我像其他热爱终端的管理员一样,花了不少时间定制我的环境,把它打造成一个让我工作起来感到舒适的地方。

Oh God, I’m doing it. I’m doing the thing they do on recipe sites where all the reader really wants is directions for making pecan pie but instead gets a giant personal backstory. Forgive me. I’m old. Let’s get to the pie, and by pie, I mean the screenshots and code!

天哪,我又开始了。我正在做那些食谱网站上常有的事:读者明明只想看怎么做山核桃派,结果却被迫看了一大堆作者的个人背景故事。原谅我,我老了。让我们直接进入“派”的主题吧——我指的“派”就是截图和代码!

My favorite thing: The terminal timer. It’s incredibly handy, at least for me, to have an easy-to-see reference of how long the last command took to run. (You don’t need that kind of thing until you need it, and then you often really need it.) To that end, I have some functions living in my .bashrc file that time each command and then append that time—and the last error code emitted—to the next bash prompt.

我最喜欢的功能:终端计时器。至少对我来说,能直观地看到上一条命令运行了多久是非常方便的。(你可能平时不需要它,但一旦需要,它就真的非常重要。)为此,我在我的 .bashrc 文件中加入了一些函数,用于记录每条命令的耗时,并将该时间以及最后产生的错误代码附加到下一个 bash 提示符中。

It’s neat seeing how long each of these things took to execute. And sometimes it’s even useful! Coupled with printing the current time as part of the prompt, it gives you a good idea of not just how long the last few commands took to run but also when you were running them. That’s very handy for absentminded admins (/me raises hand) who leave terminal sessions up for days at a time with important work sitting in them.

看到每条命令执行了多久感觉很棒,而且有时它确实很有用!再加上将当前时间作为提示符的一部分打印出来,你不仅能清楚地知道最近几条命令运行了多久,还能知道你是在什么时候运行它们的。这对于那些容易健忘的管理员(/me 举手)来说非常方便,他们经常让终端会话保持开启好几天,里面还运行着重要的工作。