惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
B
Blog RSS Feed
V
V2EX
博客园 - 聂微东
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 司徒正美
L
LINUX DO - 热门话题
WordPress大学
WordPress大学
腾讯CDC
酷 壳 – CoolShell
酷 壳 – CoolShell
Scott Helme
Scott Helme
T
Threatpost
P
Privacy International News Feed
博客园 - Franky
Spread Privacy
Spread Privacy
K
Kaspersky official blog
博客园_首页
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
爱范儿
爱范儿
L
Lohrmann on Cybersecurity
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
The Exploit Database - CXSecurity.com
GbyAI
GbyAI
T
Tenable Blog
C
Cisco Blogs
阮一峰的网络日志
阮一峰的网络日志
V
Visual Studio Blog
I
Intezer
J
Java Code Geeks
P
Proofpoint News Feed
C
Cybersecurity and Infrastructure Security Agency CISA
Y
Y Combinator Blog
月光博客
月光博客
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
H
Help Net Security
D
Docker
M
MIT News - Artificial intelligence
AWS News Blog
AWS News Blog
Security Latest
Security Latest
C
CERT Recently Published Vulnerability Notes
Blog — PlanetScale
Blog — PlanetScale
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Threat Research - Cisco Blogs
T
Tor Project blog
The Cloudflare Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Microsoft Azure Blog
Microsoft Azure Blog

Kang

C/C++ 模板元编程学习 Ubuntu包管理 C/C++编译知识 如何使用 CMake vscode插件配置 MSVC,GCC,Clang——不同C/C++编译器对比 开源贡献的一些规范 Github Pages + Hexo 搭建个人博客 将光猫设置为桥接 Ubuntu安装记录 Ubuntu包管理
Shell
Yu Kang · 2024-07-27 · via Kang

Shell分类

Windows

Windows has two command-line shells:

  • the Command shell (cmd)

  • PowerShell

cmd可以运行win命令;PowerShell可以运行win命令和cmdlet命令。

cmd脚本语言.bat;PowerShell脚本语言.ps1

Linux

sh, csh, tcsh, bash, zsh, fish…

Bash Shell

1989 年首次发布,由 Brain Fox 为 GNU 项目编写的,目的是作为 Bourne Shell (sh) 的免费软件替代品,是大多数 Linux 发行版的默认 Shell 环境。

用户配置设置在 .bashrc 中。

Z Shell

1990 年由 Paul Falstad 发布,它具有 Bash、Korn Shell 和 C Shell 共有的一些功能,macOS 默认使用 Zsh Shell。

比 Bash 可配置度更高,有围绕 Z Shell 构建的框架(Oh My Zsh)。

用户配置设置在 .zshrc 中。

Fish Shell

2005 年由 Axel Liljencrantz 创建,不符合 POSIX shell 标准。

由于默认情况下 Fish 已经预置了很多配置,因此它被认为比 Zsh 等其他 sh 选项更适合初学者。

自定义工具

查看/切换shell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 查看可用shell
cat /etc/shells                          
# /etc/shells: valid login shells
/bin/sh
/bin/bash
/usr/bin/bash
/bin/rbash
/usr/bin/rbash
/usr/bin/sh
/bin/dash
/usr/bin/dash
/usr/bin/tmux
/usr/bin/screen
/bin/zsh
/usr/bin/zsh

# 查看当前shell
echo $SHELL

# 可以通过包管理器安装zsh
# 切换成zsh
chsh -s $(which zsh)

一些主题中的部件需要特殊字体,下载使用使用Nerd字体。

Window:官网下载MesloLG Nerd Font,将所有的TrueType字体文件右键进行安装。

MacOS/Linux:脚本安装。

1
2
3
git clone https://github.com/ryanoasis/nerd-fonts.git --depth 1
cd nerd-fonts
./install.sh

Oh my zsh

适用于zsh。

1
2
3
4
# 安装命令
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# 卸载
uninstall_oh_my_zsh

安装后~/.zshrc会改变,从而启动oh-my-zsh,此时终端如下:

之后可以下载主题和插件,一方面要将下载保存到$ZSH_CUSTOM(/.oh-my-zsh/custom),另一方面要在`/.zshrc`进行相应设置以生效。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 主题$ZSH_CUSTOM/themes,插件$ZSH_CUSTOM/plugins
# powerlevel10k主题  
git clone https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k  
# zsh-autosuggestions自动提示插件  
git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions  
# zsh-syntax-highlighting语法高亮插件  
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting

# 对于p10k,需要进行自定义配置
p10k configure

# ~/.zshrc
# 修改主题  
ZSH_THEME="powerlevel10k/powerlevel10k"

# 启用插件  
plugins=(  
  git  
  zsh-autosuggestions  
  zsh-syntax-highlighting  
)

# 更改配置后重载
omz reload

效果展示:

Zim

Zim 启动速度更快,相比 oh-my-zsh 更加轻量级,适用于zsh。

1
2
# 安装命令
curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh

安装后~/.zshrc会改变,而Zim的配置文件为~/.zimrc,在该文件中列出需要使用的插件(包括主题),比如:

1
2
zmodule romkatv/powerlevel10k
zmodule completion

之后运行zimfw install来安装所需插件,与oh-my-zsh类似,同样需要配置p10k主题。

效果展示:

Oh my posh

可以用于多种shell。

可以在Windows中美化PowerShell的样式。

1
2
# 安装命令
winget upgrade JanDeDobbeleer.OhMyPosh -s winget

Windows中自带蓝色的Windows PowerShell,可以在Microsoft Store中下载黑色的PowerShell,本文使用黑色的PowerShell作为终端的默认shell。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 查看使用的shell
oh-my-posh get shell

# PowerShell配置脚本文件位置(类似~/.zshrc)
(base) PS C:\Users\kangy> $PROFILE
C:\Users\kangy\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
# 编辑PowerShell配置文件脚本
notepad $PROFILE
# 若文件不存在则创建
New-Item -Path $PROFILE -Type File -Force
# 在脚本中添加如下启动oh-my-posh并使主题生效
& ([ScriptBlock]::Create((oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\jandedobbeleer.omp.json" --print) -join "`n"))

# 重载shell
. $PROFILE

效果展示: