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

推荐订阅源

博客园 - Franky
博客园 - 司徒正美
Microsoft Azure Blog
Microsoft Azure Blog
J
Java Code Geeks
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The GitHub Blog
The GitHub Blog
Recent Announcements
Recent Announcements
Blog — PlanetScale
Blog — PlanetScale
G
Google Developers Blog
WordPress大学
WordPress大学
A
About on SuperTechFans
Hugging Face - Blog
Hugging Face - Blog
T
Tor Project blog
阮一峰的网络日志
阮一峰的网络日志
Recent Commits to openclaw:main
Recent Commits to openclaw:main
The Hacker News
The Hacker News
F
Full Disclosure
有赞技术团队
有赞技术团队
H
Help Net Security
Security Latest
Security Latest
P
Palo Alto Networks Blog
MyScale Blog
MyScale Blog
Simon Willison's Weblog
Simon Willison's Weblog
G
GRAHAM CLULEY
P
Privacy International News Feed
P
Proofpoint News Feed
Scott Helme
Scott Helme
V
Vulnerabilities – Threatpost
罗磊的独立博客
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
aimingoo的专栏
aimingoo的专栏
Latest news
Latest news
Jina AI
Jina AI
Stack Overflow Blog
Stack Overflow Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Hacker News: Ask HN
Hacker News: Ask HN
爱范儿
爱范儿
T
Threat Research - Cisco Blogs
Last Week in AI
Last Week in AI
The Last Watchdog
The Last Watchdog
N
Netflix TechBlog - Medium
D
DataBreaches.Net
L
LINUX DO - 热门话题
Application and Cybersecurity Blog
Application and Cybersecurity Blog
L
Lohrmann on Cybersecurity
O
OpenAI News
S
SegmentFault 最新的问题
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

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

效果展示: