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

推荐订阅源

SecWiki News
SecWiki News
I
InfoQ
The Cloudflare Blog
人人都是产品经理
人人都是产品经理
博客园 - Franky
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
量子位
博客园_首页
罗磊的独立博客
V
V2EX
李成银的技术随笔
大猫的无限游戏
大猫的无限游戏
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
True Tiger Recordings
Vercel News
Vercel News
Cyberwarzone
Cyberwarzone
Cisco Talos Blog
Cisco Talos Blog
F
Fox-IT International blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
M
Microsoft Research Blog - Microsoft Research
Know Your Adversary
Know Your Adversary
爱范儿
爱范儿
The Register - Security
The Register - Security
G
Google Developers Blog
The Hacker News
The Hacker News
Malwarebytes
Malwarebytes
S
Securelist
博客园 - 三生石上(FineUI控件)
Jina AI
Jina AI
T
Threat Research - Cisco Blogs
T
The Exploit Database - CXSecurity.com
S
SegmentFault 最新的问题
博客园 - 叶小钗
F
Fortinet All Blogs
Apple Machine Learning Research
Apple Machine Learning Research
宝玉的分享
宝玉的分享
博客园 - 聂微东
T
Threatpost
博客园 - 【当耐特】
D
Docker
P
Privacy & Cybersecurity Law Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
G
GRAHAM CLULEY
V
Visual Studio Blog
C
Cisco Blogs
IT之家
IT之家
S
Security Archives - TechRepublic
Latest news
Latest news
阮一峰的网络日志
阮一峰的网络日志

Kang

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

效果展示: