Home Shell 改造
Post
Cancel

Shell 改造

Shell 改造

致谢: 本文档中工具参考了 pengsida 分享的科研经验中的 设备配置 文档.

以下命令均基于 Ubuntu 系统

1. 安装 zsh

1
2
3
4
5
6
7
sudo apt install zsh

# 切换默认shell
# 切换默认shell对当前窗口无效, 新开窗口才有效
cat /etc/shells  	#查看所有shell
echo $SHELL      	#查看当前使用的shell
chsh -s /usr/bin/zsh	#更改默认shell

2. 安装 oh my zsh 及插件

2.1 oh my zsh 安装

1
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

2.2 迁移环境变量

迁移需要的环境变量到 .zshrc, 如: conda 环境变量 (一般位于配置文件末尾).

1
2
3
# 迁移原有的环境变量至 ~/.zshrc
cat ~/.bashrc
vim ~/.zshrc		# 将 .bashrc 中需要的环境变量复制至 .zshrc

2.3 命令高亮及语法检测插件 zsh-syntax-highlighting

1
2
3
4
5
6
7
8
9
# 克隆项目 (会自动下载到~/.oh-my-zsh/custom/plugins/ 目录)
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

# 修改 .zshrc, 找到 plugins, 在 plugins=( [plugins...] ) 中添加 zsh-syntax-highlighting
# 如: `plugins=(git)` => `plugins=(git zsh-syntax-highlighting)`
vim ~/.zshrc

# 在当前窗口立即生效
source ~/.zshrc 

2.4 自动补全插件 zsh-autosuggestions

1
2
3
4
5
6
7
8
9
# 安装
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

# 修改 .zshrc, 找到 plugins, 在 plugins=( [plugins...] ) 中添加 zsh-autosuggestions
# 如: `plugins=(git)` => `plugins=(git zsh-autosuggestions)`
vim ~/.zshrc

# 在当前窗口立即生效
source ~/.zshrc 
  • 补全如果出现了想要的语句,则直接 ctrl+f 选择
  • 如果需要显示所有可选项目,点击一次 tab 只能显示所有可选项但还是需要手动输入;点击两次 tab 可以直接用方向键选择项目.

3. 安装 tmux

tmux 可以将会话和终端窗口分离, 避免了关闭窗口导致当前窗口运行的程序直接中断.

3.1 安装

1
sudo apt-get install tmux

3.2 设置 tmux 窗口鼠标上下滚动

  • vim ~/.tmux.conf
  • 添加: set -g terminal-overrides 'xterm*:smcup@:rmcup@'
  • 进入任意一个 tmux 窗口, 重新加载配置文件tmux source-file ~/.tmux.conf
  • 重新进入 tmux 窗口

3.3 tmux 常用命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 启动tmux
tmux
# 启动, 并以自定义命名
tmux new -s <name>

# 退出, 会直接关闭伪窗口
exit 或 Ctrl+D

# 分离会话
tmux detach

# 查看当前所有伪窗口
tmux ls
# 重接会话 使用伪窗口编号
tmux attach -t 0
# 重接会话 使用伪窗口名称
tmux attach -t test

# 杀死窗口
# 使用会话编号
tmux kill-session -t 0
# 使用会话名称
tmux kill-session -t <name>

# 切换会话
# 使用会话编号
tmux switch -t 0
# 使用会话名称
tmux switch -t <session-name>

# 重命名会话
tmux rename-session -t 0 <new-name>

# 列出所有快捷键,及其对应的 Tmux 命令
tmux list-keys

# 列出所有 Tmux 命令及其参数
tmux list-commands

# 列出当前所有 Tmux 会话的信息
tmux info

# 重新加载当前的 Tmux 配置
tmux source-file ~/.tmux.conf

# 划分上下两个窗格
tmux split-window

# 划分左右两个窗格
tmux split-window -h

4. 安装 ctop

docker 容器快捷管理, 容器占用资源显示

4.1 安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 到 https://github.com/bcicen/ctop/releases, 选择对应版本, 复制下载链接
cd Donwload
wget <download_URL>

sudo mkdir /opt/ctop
# 把下载下来的 ctop 移动并改名到对应文件夹
sudo mv <ctop_filepath> /opt/ctop/ctop

# 添加环境变量: export PATH="/opt/ctop:$PATH"
vim ~/.zshrc
source ~/.zshrc

# 运行
ctop

4.2 ctop 快捷键

KeyAction
上\下切换选中容器
ENTER打开选中容器菜单
a切换显示所有容器(包括运行中和非运行中的)
f筛选显示的容器(打开时按esc键清除筛选)
H切换 ctop 标头显示
h打开帮助对话框
s选择容器排序字段
r反转容器排序顺序
o打开选中容器的单独性能视图
l查看容器日志(打开时按t键切换时间戳)
e打开当前容器 Shell (在 docker run 时附上 -it 的容器才可进入命令行)
c配置列
S将当前配置保存到文件
q退出 ctop
This post is licensed under CC BY 4.0 by the author.

Nvidia-Docker 教程

论文订阅