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

推荐订阅源

博客园_首页
Security Archives - TechRepublic
Security Archives - TechRepublic
Application and Cybersecurity Blog
Application and Cybersecurity Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
C
CERT Recently Published Vulnerability Notes
S
Security @ Cisco Blogs
S
Security Affairs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
L
Lohrmann on Cybersecurity
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hacker News: Ask HN
Hacker News: Ask HN
Forbes - Security
Forbes - Security
H
Heimdal Security Blog
A
Arctic Wolf
NISL@THU
NISL@THU
P
Proofpoint News Feed
W
WeLiveSecurity
S
Schneier on Security
AI
AI
Schneier on Security
Schneier on Security
N
News and Events Feed by Topic
L
LINUX DO - 最新话题
Cisco Talos Blog
Cisco Talos Blog
AWS News Blog
AWS News Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Know Your Adversary
Know Your Adversary
Scott Helme
Scott Helme
V
Vulnerabilities – Threatpost
Cyberwarzone
Cyberwarzone
I
Intezer
S
Securelist
Help Net Security
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
小众软件
小众软件
Last Week in AI
Last Week in AI
Jina AI
Jina AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
WordPress大学
WordPress大学
罗磊的独立博客
月光博客
月光博客
雷峰网
雷峰网
A
About on SuperTechFans
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
博客园 - 司徒正美
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events

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

效果展示: