mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-02-03 23:40:14 +08:00
Translated 20220323 Xonsh Shell Combines the Best of Bash Shell and Python in Linux Terminal.md
This post is translated by lkxed.
This commit is contained in:
parent
e1ac249f40
commit
f0e26f0a0f
@ -1,111 +0,0 @@
|
||||
[#]: subject: "Xonsh Shell Combines the Best of Bash Shell and Python in Linux Terminal"
|
||||
[#]: via: "https://itsfoss.com/xonsh-shell/"
|
||||
[#]: author: "Abhishek Prakash https://itsfoss.com/author/abhishek/"
|
||||
[#]: collector: "lujun9972"
|
||||
[#]: translator: "lkxed"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
Xonsh Shell Combines the Best of Bash Shell and Python in Linux Terminal
|
||||
======
|
||||
|
||||
Which is the most popular shell? I guess you’ll say bash or perhaps zsh and you are right about that.
|
||||
|
||||
There are several shells available for UNIX and Linux systems. bash, ksh, zsh, fish and more.
|
||||
|
||||
Recently, I came across another shell which offers a unique twist of combining Python and bash.
|
||||
|
||||
### Xonsh shell for the Python loving Linux users
|
||||
|
||||
[Xonsh][1] is a Python-powered, cross-platform, shell language and command prompt.
|
||||
|
||||
It combines Python and bash shell in a way that you can run Python commands directly in the shell. You can even combine Python and shell commands.
|
||||
|
||||
![][2]
|
||||
|
||||
Sounds good? It may sound even better if you are a Python programmer.
|
||||
|
||||
### Installing Xonsh shell on Linux
|
||||
|
||||
There are several ways you can install Xonsh shell on your system.
|
||||
|
||||
You can install it from your distribution’s package manager (it is available in the repositories of major distributions).
|
||||
|
||||
On Ubuntu and Debian, you may try:
|
||||
|
||||
```
|
||||
|
||||
sudo apt install xonsh
|
||||
|
||||
```
|
||||
|
||||
Since it is essentially a Python application, you always have the option to use Pip (if you have pip installed on your system). Conda can also be used for installing Xonsh. There is also an AppImage available along with a Docker image.
|
||||
|
||||
You may choose whichever installation method you prefer.
|
||||
|
||||
### Experiencing the Xonsh shell
|
||||
|
||||
If you are new to the multiple shell concept or the terminal, I suggest reading [my article on terminal introduction][3]. It will help clear numerous things for the Linux beginners.
|
||||
|
||||
Quick recap. Your terminal runs a default shell (usually bash shell). If you have other shells installed on your system, you can [easily switch the shells][4].
|
||||
|
||||
To enter the Xonsh shell, simply run this command:
|
||||
|
||||
```
|
||||
|
||||
xonsh
|
||||
|
||||
```
|
||||
|
||||
![][5]
|
||||
|
||||
It advises you to run a wizard and create a customized rc file for Xonsh shell. It’s optional and you may do it later as well.
|
||||
|
||||
You can start feeling a bit of difference as soon as you start using it.
|
||||
|
||||
As you start typing a command, Xonsh shell automatically suggests the last matching command from the history. You can press the right arrow key to confirm it and use the auto suggested command. You can press the up and down arrow key to go back to other matching commands from the history.
|
||||
|
||||
![Xonsh shell automatically suggests last matching command from the history as you type][6]
|
||||
|
||||
That’s not it. The tab completion is interactive here. Start typing the command and press tab and it shows a dropdown kind of interactive menu. From here, you can choose between the available commands.
|
||||
|
||||
![Tab completion in Xonsh shell][7]
|
||||
|
||||
You can combine the Python and bash commands and run them directly in the shell.
|
||||
|
||||
If you are into [terminal customization][8], you can spend some time and effort to customize tab completion, key bindings and color styles as per your preference.
|
||||
|
||||
It also has a user generated plugin systems called [Xontrib][9] and you can use them to extend the functionality of the Xonsh shell.
|
||||
|
||||
If you are a terminal lover and interested in learning more on it, you can go through its [extensive documentation system][10].
|
||||
|
||||
### In the end…
|
||||
|
||||
Most users stick with the default bash shell and there is nothing wrong with it. Some developers and sysadmins opt for Zsh for its additional features. Xonsh focuses entirely on Python and it may attract Python users. For the rest of us, bash is good enough.
|
||||
|
||||
Have you ever used Xonsh or some other shell? Why do you use it instead of bash? The comment section is all yours.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/xonsh-shell/
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/abhishek/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://xon.sh/
|
||||
[2]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2022/03/xonsh-shell-combines-python-bash.png?resize=800%2C470&ssl=1
|
||||
[3]: https://itsfoss.com/basic-terminal-tips-ubuntu/
|
||||
[4]: https://linuxhandbook.com/change-shell-linux/
|
||||
[5]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2022/03/xonsh-shell.png?resize=800%2C451&ssl=1
|
||||
[6]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2022/03/auto-suggestions-from-history-in-xonsh-shell.png?resize=800%2C258&ssl=1
|
||||
[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2022/03/tab-completion-xonsh-shell.png?resize=800%2C354&ssl=1
|
||||
[8]: https://itsfoss.com/customize-linux-terminal/
|
||||
[9]: https://github.com/topics/xontrib
|
||||
[10]: https://xon.sh/tutorial.html
|
@ -0,0 +1,109 @@
|
||||
[#]: subject: "Xonsh Shell Combines the Best of Bash Shell and Python in Linux Terminal"
|
||||
[#]: via: "https://itsfoss.com/xonsh-shell/"
|
||||
[#]: author: "Abhishek Prakash https://itsfoss.com/author/abhishek/"
|
||||
[#]: collector: "lujun9972"
|
||||
[#]: translator: "lkxed"
|
||||
[#]: reviewer: " "
|
||||
[#]: publisher: " "
|
||||
[#]: url: " "
|
||||
|
||||
Xonsh Shell Combines the Best of Bash Shell and Python in Linux Terminal
|
||||
Xnosh Shell 在 Linux 终端上结合了 Bash Shell 和 Python 的最佳特性
|
||||
======
|
||||
|
||||
最受欢迎的 shell 是什么?我猜你会回答 bash 或者 zsh,没错,的确如此。
|
||||
|
||||
UNIX 和 Linux 系统上有许多可用的 shell,包括 bash、ksh、zsh、fish 等等。
|
||||
|
||||
最近,我碰到了另外一个 shell,它结合了 Python 和 bash,还蛮特别的。
|
||||
|
||||
### Xonsh shell,为喜爱 Python 的 Linux 用户而打造
|
||||
|
||||
[Xonsh][1] 是一个使用 Python 编写的跨平台 shell 语言和命令提示符。
|
||||
|
||||
它结合了 Python 和 bash shell,因此你可以在这个 shell 中直接运行 Python 命令。你甚至可以把 Python 命令和 shell 命令混合起来使用。
|
||||
|
||||
![][2]
|
||||
|
||||
听起来不错吧?如果你是一个 Python 程序员的话,你应该会更加兴奋。
|
||||
|
||||
### 在 Linux 上安装 Xonsh shell
|
||||
|
||||
有多种方式可以在 Linux 系统上安装 Xonsh shell。
|
||||
|
||||
你可以使用软件包管理器安装它(主要的 Linux 发行版的仓库中都有 Xonsh shell)。
|
||||
|
||||
在 Ubuntu 和 Debian 上,你可以尝试运行:
|
||||
|
||||
```
|
||||
sudo apt install xonsh
|
||||
```
|
||||
|
||||
因为它本质上是一个 Python 应用,所以你总是可以使用 Pip 来安装(如果你的系统已经安装了 pip 的话)。或者,你也可以使用 Conda 来安装 Xonsh。同时,它还提供了 AppImage 格式和 Docker 镜像。
|
||||
|
||||
你可以自由选择你喜欢的安装方式。
|
||||
|
||||
### Xonsh shell 初体验
|
||||
|
||||
如果你不熟悉 Linux 的“多 shell “概念和终端的相关知识,我推荐你阅读 [我写的一篇终端入门的文章][3]。这篇文章会帮助 Linux 新手弄清楚很多东西。
|
||||
|
||||
我在这里简单介绍一下。你的终端运行着一个默认的 shell(通常是 bash shell)。如果你在系统上安装了其他的 shell,你可以 [轻松地切换这些 shell][4]。
|
||||
|
||||
|
||||
要进入 Xonsh shell,只需运行一条命令:
|
||||
|
||||
```
|
||||
xonsh
|
||||
```
|
||||
|
||||
![][5]
|
||||
|
||||
它会建议你运行一个设置向导,然后创建一个 Xonsh shell 的自定义 `rc` 配置文件。这是可选的,你也可以晚些时候再做。
|
||||
|
||||
一旦你开始使用它,你就立刻会感觉到一些不同。
|
||||
|
||||
当你开始输入一条命令时,Xonsh 会自动建议历史记录中的最后一条匹配命令。你可以按下右箭头键确认使用这条自动建议的命令。你也可以按下上、下箭头键来选择历史记录中的其他匹配命令。
|
||||
|
||||
![Xonsh shell automatically suggests last matching command from the history as you type][6]
|
||||
|
||||
不仅如此,它还支持交互式的 Tab 补全。当你开始输入命令,并按下 tab 键,它会显示一个类似于下拉式的交互式菜单。你可以在这个菜单中选择可用的命令。
|
||||
|
||||
![Tab completion in Xonsh shell][7]
|
||||
|
||||
你可以混合使用 Python 和 bash 命令,并且直接在 shell 中运行它们。
|
||||
|
||||
如果你对 [终端定制][8] 感兴趣,你可以花点时间和精力,根据自己的喜好来定制 tab 补全、按键绑定和颜色样式。
|
||||
|
||||
它同时拥有一个叫做 [Xontrib][9] 的用户自定义插件系统,你可以使用这些插件来扩展 Xonsh shell 的功能。
|
||||
|
||||
如果你是一个终端爱好者,并渴望学习更多终端知识,你可以浏览它的 [丰富的文档系统][10]。
|
||||
|
||||
### 最后
|
||||
|
||||
大多数用户坚持使用默认的 bash shell,这很正常。有一些开发者和系统管理员会选择使用 Zsh,因为它有很多附加特性。而 Xonsh 完全聚焦在 Python 上,对于 Python 使用者来说,它或许具有吸引力。对于其余的人来说,bash 已经足够好了。
|
||||
|
||||
你使用过 Xonsh 或者其他的 shell 吗?你用它来代替 bash 的原因是什么呢?欢迎在评论区留言。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: https://itsfoss.com/xonsh-shell/
|
||||
|
||||
作者:[Abhishek Prakash][a]
|
||||
选题:[lujun9972][b]
|
||||
译者:[lkxed](https://github.com/lkxed)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]: https://itsfoss.com/author/abhishek/
|
||||
[b]: https://github.com/lujun9972
|
||||
[1]: https://xon.sh/
|
||||
[2]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2022/03/xonsh-shell-combines-python-bash.png?resize=800%2C470&ssl=1
|
||||
[3]: https://itsfoss.com/basic-terminal-tips-ubuntu/
|
||||
[4]: https://linuxhandbook.com/change-shell-linux/
|
||||
[5]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2022/03/xonsh-shell.png?resize=800%2C451&ssl=1
|
||||
[6]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2022/03/auto-suggestions-from-history-in-xonsh-shell.png?resize=800%2C258&ssl=1
|
||||
[7]: https://i0.wp.com/itsfoss.com/wp-content/uploads/2022/03/tab-completion-xonsh-shell.png?resize=800%2C354&ssl=1
|
||||
[8]: https://itsfoss.com/customize-linux-terminal/
|
||||
[9]: https://github.com/topics/xontrib
|
||||
[10]: https://xon.sh/tutorial.html
|
Loading…
Reference in New Issue
Block a user