值得切换到 zsh 来休闲使用吗?

发布于 2024-07-05 14:20:04 字数 1476 浏览 7 评论 0 原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

被翻牌 2024-07-12 14:20:04

就我个人而言,我喜欢 zsh。

一般来说,您可能不会注意到它和 bash 之间的区别,除非您想要快速执行递归通配符之类的操作:

  • 例如 **/*.c

或者使用后缀别名将特定的程序与不同的后缀关联起来,以便您可以直接“执行”它们。 下面的别名让您可以在提示符下“运行”C 源文件,只需输入 ./my_program.c – 这将完全像您输入 vim ./my_program.c. (相当于双击文件图标。)

  • alias -sc=vim

或者打印今天修改的文件名:

  • print *(e:age Today now:)

您可能可以在 bash 中完成所有这些操作,但我对 zsh 的经验是,如果我想做一些事情,我可能可以在 zsh-lovers.
我还找到了这本书 '从 Bash 到 Z-Shell' 非常有用。

玩令人难以置信的大量选项也很有趣!

Personally, I love zsh.

Generally, you probably won't notice the difference between it and bash, until you want to quickly do things like recursive globbing:

  • **/*.c for example.

Or use suffix aliases to associate specific progs with different suffixes, so that you can "execute" them directly. The below alias lets you "run" a C source file at the prompt by simply typing ./my_program.c – which will work exactly as if you typed vim ./my_program.c. (Sort of the equivalent to double clicking on the icon of a file.)

  • alias -s c=vim

Or print the names of files modified today:

  • print *(e:age today now:)

You can probably do all of these things in bash, but my experience with zsh is that if there's something I want to do, I can probably find it in zsh-lovers.
I also find the book 'From Bash to Z-Shell' really useful.

Playing with the mind bogglingly large number of options is good fun too!

倦话 2024-07-12 14:20:04

对于临时使用,您可能最好坚持使用 bash 并仅安装 bash 补全。

安装它非常简单,从 http:// /www.caliban.org/bash/index.shtml#completion 并提取它,

tar -xzvf bash-completion-20060301.tar.gz

然后将 bash_completion/bash_completion 文件复制到 /etc ,该

sudo cp bash_completion/bash_completion /etc

文件将提示您输入密码。 您可能想要为任何其他完成脚本创建一个 /etc/bash_completion.d 目录(例如我在那里有 git 完成脚本)。

完成此操作后,最后一步是确保主目录中的 .bash_profile 文件包含

if [ -f /etc/bash_completion ]; then
     . /etc/bash_completion 
fi

在登录时加载完成文件。

要测试它,只需打开一个新终端,然后尝试在 cvs 上完成,它应该会在完成列表中显示 cvs 选项。

For casual use you are probably better off sticking with bash and just installing bash completion.

Installing it is pretty easy, grab the bash-completion-20060301.tar.gz from http://www.caliban.org/bash/index.shtml#completion and extract it with

tar -xzvf bash-completion-20060301.tar.gz

then copy the bash_completion/bash_completion file to /etc with

sudo cp bash_completion/bash_completion /etc

which will prompt you for your password. You probably will want to make a /etc/bash_completion.d directory for any additional completion scripts (for instance I have the git completion script in there).

Once this is done the last step is to make sure the .bash_profile file in your home directory has

if [ -f /etc/bash_completion ]; then
     . /etc/bash_completion 
fi

in it to load the completion file when you login.

To test it just open a new terminal, and try completing on cvs and it should show you the cvs options in the list of completions.

过期情话 2024-07-12 14:20:04

切换到 zsh。 您将可以访问:

  1. zmv:您可以对数千个文件执行:zmv '(*).mp3' '$1.wma'
  2. zcalc:非常舒适的计算器,比bc更好。
  3. zparseopts:用于解析给脚本的任意复杂选项的单行代码。
  4. autopushd:您始终可以在 cd 之后执行 popd 以更改回之前的目录。
  5. 浮点支持。 有时需要它。
  6. 哈希支持。 有时它们只是一个关键功能。

Switch to zsh. You will have access to:

  1. zmv: You can do: zmv '(*).mp3' '$1.wma' for thousands of files.
  2. zcalc: Extremely comfortable calculator, better than bc.
  3. zparseopts: One-liner for parsing arbitrary complex options given to your script.
  4. autopushd: You can always do popd after cd to change back to your previous directory.
  5. Floating point support. It is needed from time to time.
  6. Hashes support. Sometimes they are just a key feature.
为你拒绝所有暧昧 2024-07-12 14:20:04

如果您只是想使用 ZSH 来更好地完成任务,那么配置非常简单。 将其放入 ~/.zshrc 中:

autoload -U zutil      # [1]
autoload -U compinit   # [2]
autoload -U complist   # [3]
compinit

但是,值得查看 ZSH 的所有其他强大功能。 上面的例子会给你一个非常简单的提示,并且完成得很好。 如果您不想摆弄配置,但想了解 ZSH 可以为您做什么,请 Google 搜索“zshrc”,您将获得一些准备使用的配置来开始使用。

If all you want to use ZSH for is better completion, the configuration is pretty easy. Place this in your ~/.zshrc:

autoload -U zutil      # [1]
autoload -U compinit   # [2]
autoload -U complist   # [3]
compinit

However, it's worth checking out all the other great features of the ZSH. The above example will give you a pretty plain prompt with good completion. If you don't want to fiddle with configurations, but want to see what ZSH can do for you, Google for "zshrc" and you will get some ready to use configurations to get started.

知足的幸福 2024-07-12 14:20:04

zsh 有一个控制台 GUI 配置的东西。 您可以快速轻松地进行设置,而无需摆弄配置文件。 我认为您不需要太多时间来设置它,仅使用默认值可能需要 10 秒,所以请继续尝试。

zsh has a console gui configuration thing. You can set it up pretty quickly and easily without having to fiddle with configuration files. I don't think you will need much time to set it up, probably 10 seconds with just using defaults, so go ahead and try it out.

Oo萌小芽oO 2024-07-12 14:20:04

Staale 谈论的是一个类似向导的程序 (CUI),它会在您第一次运行 zsh 时自动运行。 只需回答一些问题,查看/更改默认值及其为您配置的即可。

IBMdeveloperWorks 拥有有关 zsh 的丰富资源。

我还没有使用过非常高级的功能,到目前为止我还没有遇到严重的差异,这应该会妨碍来自 bash 的人。

一些示例:

  • !?pattern 将自动完成到
    历史匹配中的最后一个命令
    图案。 非常有用。

  • 您可以在
    右侧。 一种用途是保持固定
    左侧的宽度提示
    所以所有命令都很好地排列
    显示密码(或任何
    可变宽度)作为右手
    侧提示。

  • 您可以重定向来自多个文件的输入(尚未尝试此操作):cat < 文件1 < 文件2 < file3

Staale is talking about a wizard like program (CUI) which autoruns the first time you run zsh. Just answer some questions, view/change the defaults and its configured for you.

IBM developerWorks has great resources on zsh.

I have not used very advanced features and so far I have not come across serious differences which should hamper someone coming from bash.

Some examples:

  • !?pattern<Tab> will autocomplete to
    the last command in history matching
    pattern. Very useful.

  • You can configure a prompt on the
    RHS. One use is to keep a fixed
    width prompt on the left hand side
    so all commands line up nicely while
    displaying the pwd (or anything of
    variable width) as the right hand
    side prompt.

  • You can redirect input from multiple files (yet to try this): cat < file1 < file2 < file3

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文