Linux 之 zsh

Linux 之 zsh安装现在好多linux发行版好像都自带zsh的,比如说centos。[root@master~]#chsh-l/bin/sh/bin/bash/usr/bin/sh/usr/bin/bash/usr/bin/tmux/bin/zsh/usr/bin/fish如果实在没有的话,就用yum安装一个。yuminstallzsh…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全家桶1年46,售后保障稳定

安装

zsh 安装

现在好多 linux 发行版好像都自带 zsh 的,比如说 centos。

[root@master ~]# chsh -l
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
/usr/bin/tmux
/bin/zsh
/usr/bin/fish

Jetbrains全家桶1年46,售后保障稳定

如果实在没有的话,就用 yum 安装一个。

yum install zsh

如果直接切换到 zsh 的话,看起来和默认 bash 好像没太大区别。

[root@master ~]# chsh 
Changing shell for root.
New shell [/bin/bash]: /bin/zsh
Shell changed.

一般来说,是要配合现在很流行的 oh my zsh 来使用的。

oh my zsh 安装

[root@master]~# git clone https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh 
Cloning into '/root/.oh-my-zsh'...
remote: Enumerating objects: 26567, done.
remote: Counting objects: 100% (188/188), done.
remote: Compressing objects: 100% (99/99), done.
remote: Total 26567 (delta 97), reused 166 (delta 88), pack-reused 26379
Receiving objects: 100% (26567/26567), 7.76 MiB | 61.00 KiB/s, done.
Resolving deltas: 100% (13325/13325), done.

[root@master]~# cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

使用

再次连接的话,就是下面这种的了。

Connecting to 192.168.128.139:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Tue Aug 24 11:14:39 2021 from 192.168.128.1

➜  ~ 
➜  ~ cd insight-tool
➜  insight-tool git:(master) ✗ 

如果你想下次连接的时候使用默认的 bash 的话,就用 chsh 切换回去就好了。

➜  insight-tool git:(master) ✗ chsh -s /bin/bash
Changing shell for root.
Shell changed.

 如果你想立即马上切换回 bash 的话,直接输入 bash 就好了。

➜  ~ bash
[root@master ~]# 

如果还有安装其他的 shell, 任意切换也没有任何问题。

[root@master ~]# fish
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
root@master ~# zsh
➜  ~ bash
[root@master ~]# 

配置

➜  ~ vim .zshrc

家目录下的这个 .zshrc 就是 zsh 的配置文件了,像主题,插件之类的就需要在里边进行配置。

其实还有个 .zsh_history ,记录了你在 zsh 下各种操作的历史记录,类似于下面这种的。前面那个大数字大家肯定很容易猜到是啥。

➜  ~ vim .zsh_history

...
: 1629789654:0;vim .zshrc
: 1629789748:0;vim .zsh_history
>>> 1629789748 / 365 / 24 / 60 / 60
51.680293886352096

对,没错,稍微转换一下就容易发现:就是当前的时刻到 1970 年经历过的秒数。

主题

默认的主题时 robbyrussell,通过注释也可以看出,如果你设置主题为 ”random” 的话,每次进入 zsh 的时候它就会随机帮你选一个主题。

➜  ~ vim .zshrc

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="robbyrussell"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

为了体验一下,完全可以尝试一下。

ZSH_THEME="random"
[root@master ~]# zsh
[oh-my-zsh] Random theme 'kphoen' loaded
[root@master:~]
# bash
[root@master ~]# zsh
~ ➤  Random theme 'arrow' loaded
~ ➤  bash                                                                                                   
[root@master ~]# zsh
/root/.oh-my-zsh/themes/emotty.zsh-theme:49: command not found: emotty
[oh-my-zsh] Random theme 'emotty' loaded
root@master  bash                                                                                                 ~
[root@master ~]# zsh
[oh-my-zsh] Random theme 'wuffers' loaded
{} ~ 

它所有的主题都存放在 oh-my-zsh 项目 themes 目录下的:

➜  themes git:(master) ls | head -n 10
3den.zsh-theme
adben.zsh-theme
af-magic.zsh-theme
afowler.zsh-theme
agnoster.zsh-theme
alanpeabody.zsh-theme
amuse.zsh-theme
apple.zsh-theme
arrow.zsh-theme
aussiegeek.zsh-theme

如果你想查看所有主题的效果,请转到这个链接:https://github.com/ohmyzsh/ohmyzsh/wiki/Themes

插件

插件也是在 .zshrc 这个文件里设置的,默认只配置了 git,可以自行添加。

➜  ~ vim .zshrc

# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git osx autojump)

source $ZSH/oh-my-zsh.sh

比如说添加 git 插件后,当你处于一个 git 受控的目录下时,Shell 会明确显示 「git」和 branch,如上图所示,另外对 git 很多命令进行了简化,例如 gco=’git checkout’、gd=’git diff’、gst=’git status’、g=’git’等等,熟练使用可以大大减少 git 的命令长度。

相关的插件文件在 ~/.oh-my-zsh/plugins 目录下,默认提供了几百种。

➜  plugins git:(master) pwd
/root/.oh-my-zsh/plugins
➜  plugins git:(master) ls | wc
    301     301    2379

每个插件都有相应的 README.md 说明文档,可以自行了解插件的功能和用法。

➜  plugins git:(master) cd git
➜  git git:(master) ll
total 44K
-rw-r--r--. 1 root root 9.4K Aug 24 11:13 git.plugin.zsh
-rw-r--r--. 1 root root  31K Aug 24 11:13 README.md

我大概看了几个,大部分主要时设置常用命令的别名,用户就可以不用输入全称了,比如 yum 的这个插件。

➜  yum git:(master) pwd
/root/.oh-my-zsh/plugins/yum
➜  yum git:(master) ll
total 8.0K
-rw-r--r--. 1 root root 1.4K Aug 24 11:13 README.md
-rw-r--r--. 1 root root  864 Aug 24 11:13 yum.plugin.zsh
➜  yum git:(master) vim README.md 
# Yum plugin

This plugin adds useful aliases for common [Yum](http://yum.baseurl.org/) commands.

To use it, add `yum` to the plugins array in your zshrc file:

```zsh
plugins=(... yum)
```

## Aliases

| Alias | Command                           | Description                  |
|-------|-----------------------------------|------------------------------|
| ys    | `yum search`                      | Search package               |
| yp    | `yum info`                        | Show package info            |
| yl    | `yum list`                        | List packages                |
| ygl   | `yum grouplist`                   | List package groups          |
| yli   | `yum list installed`              | Print all installed packages |
| ymc   | `yum makecache`                   | Rebuild the yum package list |
| yu    | `sudo yum update`                 | Upgrade packages             |
| yi    | `sudo yum install`                | Install package              |
| ygi   | `sudo yum groupinstall`           | Install package group        |
| yr    | `sudo yum remove`                 | Remove package               |
| ygr   | `sudo yum groupremove`            | Remove pagage group          |
| yrl   | `sudo yum remove --remove-leaves` | Remove package and leaves    |
| yc    | `sudo yum clean all`              | Clean yum cache              |

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/234955.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • Django(60)Django内置User模型源码分析及自定义User

    Django(60)Django内置User模型源码分析及自定义User前言Django为我们提供了内置的User模型,不需要我们再额外定义用户模型,建立用户体系了。它的完整的路径是在django.contrib.auth.models.User。User模型源码分析

  • yarn 安装依赖(ubuntu16.04安装教程)

    Yarn是由Facebook开发的开源的JavaScript包管理工具,它在现在流行的npm基础上进行了升级改进。Facebook开发团队创造yarn来克服npm的缺陷。并声明它比npm更快,更可靠,更安全。Yarn能够向npm一样根据全局注册信息,自动的管理包的安装,更新,配置,删除过程。Yarn的优点是:它比npm的速度更快,因为它会缓存所有下载下来的包,因此它不需要下载第二遍。最…

  • 多层try catch嵌套_方法嵌套一般不超过多少层

    多层try catch嵌套_方法嵌套一般不超过多少层先是aspx页面>其中关键是>GetData是一个自义函数,原型如下:protectedDataTableGetData(objectobj){DataTabledt=newDataTable();//这里做一些事情returndt;}完整的代码如下:aspxnidsbloghttp://www.ljnid.cn>aspx.cs文件usingSys

    2022年10月11日
  • lambda表达式用法_使用lambda表达式定义函数

    lambda表达式用法_使用lambda表达式定义函数(一)输入参数在Lambda表达式中,输入参数是Lambda运算符的左边部分。它包含参数的数量可以为0、1或者多个。只有当输入参数为1时,Lambda表达式左边的一对小括弧才可以省略。输入参数的数量大于或者等于2时,Lambda表达式左边的一对小括弧中的多个参数质检使用逗号(,)分割。示例1下面创建一个Lambda表达式,它的输入参数的数量为0.该表达式将显示“ThisisaLambdae…

  • oracle:修改表名

    oracle:修改表名修改语句:ALTERTABLE旧表名RENAMETO新表名;

  • finsh AJax

    finsh AJax2019独角兽企业重金招聘Python工程师标准>>>…

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号