当前位置:网站首页>Kubectl_好用的命令行工具:oh-my-zsh_技巧和窍门
Kubectl_好用的命令行工具:oh-my-zsh_技巧和窍门
2022-07-24 15:16:00 【InfoQ】
Zsh 技巧和窍门
什么是 Zsh?
安装 Zsh
Mac
brew install zshLinux(Ubuntu)
# 1. 安装zsh
sudo apt-get install zsh
# 2. 确认是否安装成功
zsh --version
# 3. 设置zsh为默认shell
sudo chsh -s (which zsh)
# 4. 注销重新登录
Linux(Centos)
# 1. 安装zsh
sudo yum install zsh
# 2. 确认是否安装成功
zsh --version
# 3. 设置zsh为默认shell
sudo chsh -s (which zsh)
# 4. 注销重新登录
# 查看系统当前 shell
cat /etc/shells
yum remove zsh
sudo yum update -y
sudo yum install -y git make ncurses-devel gcc autoconf man
git clone -b zsh-5.7.1 https://github.com/zsh-users/zsh.git /tmp/zsh
cd /tmp/zsh
./Util/preconfig
./configure
sudo make -j 20 install.bin install.modules install.fns
command -v zsh | sudo tee -a /etc/shells
sudo chsh -s /usr/local/bin/zsh
oh-my-Zshsh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
手动安装
1.1 卸载低版本
# 卸载当前版本
sudo yum remove zsh
1.2 下载源码
- 源码:https://zsh.sourceforge.io/Arc/source.html
# 下载
wget https://sourceforge.net/projects/zsh/files/zsh/5.8/zsh-5.8.tar.xz/download
# 解压
tar xvf zsh-5.8.tar.xz
1.3 编译安装
# 安装编译工具
yum install gcc perl-ExtUtils-MakeMaker
yum install ncurses-devel
# 进入源码目录
cd zsh-5.8
# 执行配置
# 默认安装在:/usr/local/bin/zsh
./configure
# 编译和安装
make && make install
# 添加信息
vim /etc/shells
# 在最后一行加上:/usr/local/bin/zsh
1.4 验证结果
# 切换shell
chsh -s /usr/local/bin/zsh
# 查看版本信息
zsh --version
# zsh 5.8 (x86_64-pc-linux-gnu)
Zsh基本命令
6个鲜为人知的 Zsh 技巧和窍门
take命令
- 这个命令是 mkdir 和 cd 两个命令的组合。也可以根据需要生成中间目录。
- 指定命令查看历史
- 输入指定命令,再按向上箭头,可循环遍历以该命令开头的历史记录
zmv
- 用 zmv 重命名大量文件。首先,运行
autoload zmv来安装zmv。然后执行如下命令:
zmv '(*).(jpg|jpeg)' 'demo-1.2'
zcalc
- 在命令行中打开计算器,首先,运行
autoload zcalc来安装zcalc。然后就可以执行zcalc命令。
Ctrl-q
- 当你输入了一条长的命令,发现需要在其之前先执行一条命令时,就可以按
Ctrl-q暂存当前命令,然后输入另外一条命令,当另外这条命令执行结束后,会自动重新填充好暂存的命令。
ctrl-x-e
- 当你输入了一条很长的命令,发现命令中间有地方输入错误时,可以按
ctrl-x-e将该命令拷贝到编辑器中进行编辑,编辑完后,保存退出即可。
好用的插件
plugins=(git autojump last-working-dir tmux tmuxinator web-search fancy-ctrl-z themes)
- autojump
- last-working-dir
- tmux
- tmuxinator
- web-search
- fancy-ctrl-z
安装oh-my-zsh
- 可以通过 curl 或 wget 两种方式来安装,用一条命令即可安装。
curl 安装
GitHub
:
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
Gitee ( 国内镜像 )
sh -c "$(curl -fsSL https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh)"
wget 安装
GitHub
:
sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
Gitee ( 国内镜像 )
sh -c "$(wget -O- https://gitee.com/pocmon/mirrors/raw/master/tools/install.sh)"
[[email protected]]/fly/k8s/shell/ohmyzsh# ./install.sh
Cloning Oh My Zsh...
remote: Enumerating objects: 1280, done.
remote: Counting objects: 100% (1280/1280), done.
remote: Compressing objects: 100% (1236/1236), done.
remote: Total 1280 (delta 24), reused 1230 (delta 24), pack-reused 0
Receiving objects: 100% (1280/1280), 1.06 MiB | 1.23 MiB/s, done.
Resolving deltas: 100% (24/24), done.
From https://github.com/ohmyzsh/ohmyzsh
* [new branch] master -> origin/master
Branch master set up to track remote branch master from origin.
Already on 'master'
/fly/k8s/shell/ohmyzsh
Looking for an existing zsh config...
Found ~/.zshrc. Backing up to /root/.zshrc.pre-oh-my-zsh
Using the Oh My Zsh template file and adding it to ~/.zshrc.
__ __
____ / /_ ____ ___ __ __ ____ _____/ /_
/ __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \
/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / /
\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/
/____/ ....is now installed!
Before you scream Oh My Zsh! look over the `.zshrc` file to select plugins, themes, and options.
• Follow us on Twitter: https://twitter.com/ohmyzsh
• Join our Discord community: https://discord.gg/ohmyzsh
• Get stickers, t-shirts, coffee mugs and more: https://shop.planetargon.com/collections/oh-my-zsh
升级oh-my-zsh
获取更新
~/.zshrc- 自动更新无确认提示:
zstyle ':omz:update' mode auto
- 如果有可用更新,请每隔几天提供一次提醒:
zstyle ':omz:update' mode reminder
- 要完全禁用自动更新:
zstyle ':omz:update' mode disabled
# This will check for updates every 7 days
zstyle ':omz:update' frequency 7
# This will check for updates every time you open the terminal (not recommended)
zstyle ':omz:update' frequency 0
手动更新
omz update
卸载 Oh My Zsh
oh-my-zshuninstall_oh_my_zshbashzsh使用 Oh My Zsh
插件
启用插件
.zshrc$HOMEvim ~/.zshrc
plugins=(
git
bundler
dotenv
macos
rake
rbenv
ruby
)
# 刷新配置
source ~/.zshrc
使用插件
主题
选择主题
~/.zshrcZSH_THEME="robbyrussell"
ZSH_THEME="agnoster" # (this is one of the fancy ones)
# see https://github.com/ohmyzsh/ohmyzsh/wiki/Themes#agnoster

ZSH_THEME="random" # (...please let it be pie... please be some pie..)
ZSH_THEME_RANDOM_CANDIDATES=(
"robbyrussell"
"agnoster"
)
ZSH_THEME_RANDOM_IGNORED=(pygmalion tjkirch_mod)
异常问题
1. 卸载zsh后无法登陆root账户的解决方案
#在终端中输入
sudo vim /etc/passwd
#将第一行
root:x:0:0:root:/root:/bin/zsh
#改为
root:x:0:0:root:/root:/bin/bash
# 将最后一行
username:x:1000:1000:username,,,:/home/username:/username/local/bin/zsh
# 改为
username:x:1000:1000:username,,,:/home/username:/username/local/bin/bash
# 保存就可以登录root了
参考链接:
边栏推荐
- “00后”来了!数睿数据迎来新生代「无代码」生力军
- 【OpenCV 例程300篇】238. OpenCV 中的 Harris 角点检测
- Property datasource is required exception handling [idea]
- 基于ABP实现DDD--实体创建和更新
- Jmmert aggregation test report
- 2022 RoboCom 世界机器人开发者大赛-本科组(省赛)-- 第五题 树与二分图 (已完结)
- Spark: specify the date and output the log of the corresponding date (entry level - simple implementation)
- 2022 RoboCom 世界机器人开发者大赛-本科组(省赛)RC-u4 攻略分队 (已完结)
- Sword finger offer II 001. integer division
- Unity uses NVIDIA flex for unity plug-in to realize the effects of making software, water, fluid, cloth, etc. learning tutorial
猜你喜欢

《Route planning method for UAV in unknown environment based on improved SAS algorithm》翻译

Learning and thinking about the relevant knowledge in the direction of building network security knowledge base

Problem handling of repeated restart during Siemens botu installation

Sword finger offer II 001. integer division

MySQL build master-slave synchronization - build with docker

Jmeter-调用上传文件或图片接口

How to set packet capturing mobile terminal

JMeter - call the interface for uploading files or pictures

Cloud development standalone image Jiugongge traffic main source code

(09) flask is OK if it has hands - cookies and sessions
随机推荐
26.文件使用磁盘的代码实现
Error when using Fiddler hook: 502 Fiddler - connection failed
Use of keywords const, volatile and pointer; Assembly language and view of register status
Performance test - Preparation of test plan
2022 robocom world robot developer competition - undergraduate group (provincial competition) -- question 1: don't waste gold (finished)
Extjs4 instance address and Chinese document address
Leetcode 1288. delete the covered interval (yes, solved)
Problem handling of repeated restart during Siemens botu installation
Applet tab
异或程序
Strongly connected component
C# SQLite Database Locked exception
onBlur和onChange冲突解决方法
Outlook tutorial, how to create tasks and to DOS in outlook?
Leetcode-09 (next rank + happy number + full rank)
Kotlin类与继承
"After 00" is coming! Digital data ushers in a new generation of "codeless" forces
Wildfire STM32 domineering, through the firmware library to achieve water light
2022 RoboCom 世界机器人开发者大赛-本科组(省赛)-- 第五题 树与二分图 (已完结)
Outlook tutorial, how to set rules in outlook?