使用 Zsh + Tmux + Dracula 主题资源设置终端

2025-06-04

使用 Zsh + Tmux + Dracula 主题设置终端

资源

Tmux 动画

我最近学习了如何使用 Tmux,改进了我的终端设置。它让我能够在项目之间更快地切换,甚至在机器关机后也能保存会话。我的目标是帮助你配置一个美观实用的环境。现在就开始吧。

我们将设置什么

Guake:自上而下的终端,只需按一下键即可立即打开。

Zsh:扩展的 Bourne Shell (sh),具有许多改进、强大的命令行编辑选项以及对插件和主题的支持。

Oh-My-Zsh:一个开源的、社区驱动的框架,用于管理您的 Zsh 配置。

Powerlevel10k:Zsh 的主题,带有界面助手,例如 git 当前分支和执行时间。

Tmux:一个用于类 Unix 操作系统的开源终端多路复用器。它允许在一个窗口中同时访问多个终端会话。

德古拉主题:由巴西开发人员Zeno Rocha创建的著名黑暗主题。

注意:以下步骤是在 Ubuntu 系统中进行的。在 MacOS 系统中,使用 iTerm2 作为终端也可以达到同样的效果。

安装 Guake

我以前在 MacOS 上用的是iTerm2,但现在在 Linux 上我使用Guake作为默认终端。我的目标是能够用一个简单的CTRL + SPACE快捷键在任何显示器上打开命令行。

因此,如果您使用的是 Ubuntu,只需使用 进行安装即可apt



sudo apt install guake


Enter fullscreen mode Exit fullscreen mode

选择您的快捷方式

转到“首选项”→“键盘快捷键”,然后选择您的键来切换 Guake 可见性。

将您的主题更改为德古拉

Dracula是目前最知名的主题之一。我在终端和 VSCode 中都使用它。Guake 已经预装了它,因此请前往“首选项”→“外观”,并选择“Dracula”作为内置方案。

其他配置

您可能还想更改窗口的透明度和高度。查看其文档了解更多信息

屏幕截图 1

Zsh 和 Oh My Zsh

现在,让我们在 Ubuntu 中安装 Z shell。



sudo apt install zsh


Enter fullscreen mode Exit fullscreen mode

对于其他平台,请查看本指南

将其设置为您的默认 shell。



chsh -s $(which zsh)


Enter fullscreen mode Exit fullscreen mode

您必须注销才能使更改生效。

再次,在 Guake 中,前往“首选项”→“Shell”,并将默认解释器设置为/usr/bin/zsh。重新启动后,您应该会看到下面的消息。

选择选项 0。我们将使用 Oh My Zsh 进行设置。

屏幕截图 2

安装 Oh My Zsh

Oh My Zsh是一个用于管理您的 Zsh 配置、主题、插件等的框架。



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


Enter fullscreen mode Exit fullscreen mode

安装成功后,您应该会看到下面的屏幕。

屏幕截图 3

现在您可以安装自动完成功能和多个插件,让您的工作更轻松。请查看文档中提供的可用插件。

我建议您从以下几点开始:

zsh-autosuggestions:根据您已经发出的命令提出建议。

zsh-syntax-highlighting:启用输入命令时的突出显示。

将两个插件克隆到您的 OhMyZsh 自定义文件夹中。



cd ~/.oh-my-zsh/custom/plugins
git clone https://github.com/zsh-users/zsh-autosuggestions.git
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git


Enter fullscreen mode Exit fullscreen mode

现在,编辑您的~/.zshrc文件以包含它们。



plugins=(
    git
    zsh-autosuggestions
    zsh-syntax-highlighting
)


Enter fullscreen mode Exit fullscreen mode

使用 重新启动你的 Zsh source ~/.zshrc

屏幕截图 4

现在,如果您开始输入,您将看到建议并可以按下right arrow key以快速自动完成。

功率级别10k

Powerlevel10k是 Zsh 的一个主题。它强调速度、灵活性和开箱即用的体验。

安装所需的字体

通过打开“首选项”→“外观”来配置 Guake。然后,取消勾选“使用系统固定宽度字体”,并选择 MesloLGS NF Regular。更多详情,请参阅此处的指南。

克隆存储库



git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k


Enter fullscreen mode Exit fullscreen mode

然后,将 powerlevel10k 添加到~/.zshrc



ZSH_THEME="powerlevel10k/powerlevel10k"


Enter fullscreen mode Exit fullscreen mode

重新启动 Zshsource ~/.zshrc并按照配置向导进行操作。

屏幕截图 5

在以下屏幕中选择您喜欢的样式。

屏幕截图 6

将更改应用到您的zshrc,您就完成了。

屏幕截图 7

您最终将得到如下所示的结果。

屏幕截图 8

Tmux 和 Dracula 主题

在最后一节中,我们将安装带有Dracula 主题的Tmux



sudo apt install tmux


Enter fullscreen mode Exit fullscreen mode

对于其他平台,请查看本指南

然后运行它。



tmux new


Enter fullscreen mode Exit fullscreen mode

屏幕截图 9

你会注意到我们丢失了之前的颜色。让我们通过下一个配置将它们恢复。

安装tpm来处理 tmux 插件。



git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm


Enter fullscreen mode Exit fullscreen mode

编辑~/.tmux.conf并将其放在底部。



# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'git@github.com:user/plugin'
# set -g @plugin 'git@bitbucket.com:user/plugin'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'


Enter fullscreen mode Exit fullscreen mode

重新加载 tmux 环境



# type this in terminal if tmux is already running
tmux source ~/.tmux.conf


Enter fullscreen mode Exit fullscreen mode

现在,让我们将 Dracula 主题安装为 tpm 插件。将以下内容添加到您的~/.tmux.conf文件中。



set -g @plugin 'dracula/tmux'

# Set 256 colors
set -s default-terminal 'tmux-256color'


Enter fullscreen mode Exit fullscreen mode

<prefix> + I(大写 i) 安装。默认值为<prefix>ctrl + b因此按ctrl + b + I

屏幕截图 10

现在,您可以通过键入 来退出 tmux exit,然后使用 创建一个新会话tmux new。现在,您应该已经使用 Tmux 和 Dracula 主题运行了 Powerlevel10k。

另外,安装以下插件可以随时保存和恢复您的 tmux 会话。



set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'


Enter fullscreen mode Exit fullscreen mode

现在您可以准备出发了!

最终结果

快速命令:

请记住默认值<prefix>ctrl+b

  • <prefix> + %和拆分窗格<prefix> + "
  • 按 关闭窗格<prefix> + x
  • 使用 切换窗格<prefix> + arrow
  • 按 创建新窗口<prefix> + c
  • 按 切换窗口<prefix> + number
  • 使用以下方式重命名窗口<prefix> + ,
  • 使用以下方式放大和缩小窗格<prefix> + z
  • 用 拆卸<prefix> + d并重新连接tmux

您可以在此处查看我的配置:

请留下评论,告诉我您对此设置的看法,以及您是否知道其他可以改进它的方法。:)

资源

文章来源:https://dev.to/andrenbrandao/terminal-setup-with-zsh-tmux-dracula-theme-48lm
PREV
何时使用哪个数组函数?为每个现有条目返回一个新条目:map() 返回仅包含部分现有条目的新数组:filter() 仅返回一个新条目:reduce() 对每个数组值执行某些操作但不返回任何内容:forEach() 最终说明
NEXT
Homebrew - 基础命令和速查表