feat: use zellij as my daily terminal environemnt, remote tmux

This commit is contained in:
Ryan Yin
2023-12-27 22:26:06 +08:00
parent 148da9eecf
commit 248cf2e86f
11 changed files with 80 additions and 195 deletions

View File

@@ -22,7 +22,7 @@ Nix allows for easy-to-manage, collaborative, reproducible deployments. This mea
As for Flakes, refer to [Introduction to Flakes - NixOS & Nix Flakes Book](https://nixos-and-flakes.thiscute.world/nixos-with-flakes/introduction-to-flakes)
**Want to know NixOS & Flaks in detail? Looking for a beginner-friendly tutorial or best practices? You don't have to go through the pain I've experienced again! Check out my [NixOS & Nix Flakes Book - 🛠️ ❤️ An unofficial & opinionated :book: for beginners](https://github.com/ryan4yin/nixos-and-flakes-book)!**
**Want to know NixOS & Flaks in detail? Looking for a beginner-friendly tutorial or best practices? You don't have to go through the pain I've experienced again! Check out my [NixOS & Nix Flakes Book - 🛠️ ❤️ An unofficial & opinionated :book: for beginners](https://github.com/ryan4yin/nixos-and-flakes-book)!**
> If you're using macOS, check out [ryan4yin/nix-darwin-kickstarter](https://github.com/ryan4yin/nix-darwin-kickstarter) for a quick start.
@@ -31,8 +31,8 @@ As for Flakes, refer to [Introduction to Flakes - NixOS & Nix Flakes Book](https
| | NixOS(Wayland) | NixOS(Xorg) |
| --------------------------- | :---------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------- |
| **Window Manager** | [Hyprland][Hyprland] | [i3][i3] |
| **Terminal Emulator** | [Kitty][Kitty] | [Kitty][Kitty] |
| **Bar** | [Waybar][Waybar] | [i3block][i3block] |
| **Terminal Emulator** | [Zellij][Zellij] + [Kitty][Kitty] | [Zellij][Zellij] + [Kitty][Kitty] |
| **Bar** | [Waybar][Waybar] | [polybar][polybar] |
| **Application Launcher** | [anyrun][anyrun] | [rofi][rofi] |
| **Notification Daemon** | [Mako][Mako] | [Dunst][Dunst] |
| **Display Manager** | [GDM][GDM] | [GDM][GDM] |
@@ -40,7 +40,7 @@ As for Flakes, refer to [Introduction to Flakes - NixOS & Nix Flakes Book](https
| **network management tool** | [NetworkManager][NetworkManager] | [NetworkManager][NetworkManager] |
| **Input method framework** | [Fcitx5][Fcitx5] | [Fcitx5][Fcitx5] |
| **System resource monitor** | [Btop][Btop] | [Btop][Btop] |
| **File Manager** | [ranger][ranger] + [thunar][thunar] | [ranger][ranger] + [thunar][thunar] |
| **File Manager** | [yazi][yazi] + [thunar][thunar] | [yazi][yazi] + [thunar][thunar] |
| **Shell** | [Nushell][Nushell] + [Starship][Starship] | [Nushell][Nushell] + [Starship][Starship] |
| **Music Player** | [mpd][mpd], [ncmpcpp][ncmpcpp], [mpc][mpc], [Netease-cloud-music-gtk][netease-cloud-music-gtk] | [Netease-cloud-music-gtk][netease-cloud-music-gtk] |
| **Media Player** | [mpv][mpv] | [mpv][mpv] |
@@ -180,13 +180,14 @@ Other dotfiles that inspired me:
[Nushell]: https://github.com/nushell/nushell
[Starship]: https://github.com/starship/starship
[Waybar]: https://github.com/Alexays/Waybar
[i3block]: https://github.com/vivien/i3blocks
[polybar]: https://github.com/polybar/polybar
[rofi]: https://github.com/davatorium/rofi
[anyrun]: https://github.com/Kirottu/anyrun
[Dunst]: https://github.com/dunst-project/dunst
[Fcitx5]: https://github.com/fcitx/fcitx5
[Btop]: https://github.com/aristocratos/btop
[mpv]: https://github.com/mpv-player/mpv
[Zellij]: https://github.com/zellij-org/zellij
[Neovim]: https://github.com/neovim/neovim
[AstroNvim]: https://github.com/AstroNvim/AstroNvim
[flameshot]: https://github.com/flameshot-org/flameshot
@@ -204,7 +205,7 @@ Other dotfiles that inspired me:
[wl-clipboard]: https://github.com/bugaevc/wl-clipboard
[GDM]: https://wiki.archlinux.org/title/GDM
[thunar]: https://gitlab.xfce.org/xfce/thunar
[ranger]: https://github.com/ranger/ranger
[yazi]: https://github.com/sxyazi/yazi
[Catppuccin]: https://github.com/catppuccin/catppuccin
[Btrfs]: https://btrfs.readthedocs.io
[LUKS]: https://wiki.archlinux.org/title/Dm-crypt/Encrypting_an_entire_system

View File

@@ -33,6 +33,18 @@ Remove all unused plugins:
![](/_img/astronvim_2023-07-13_00-39.webp)
![](/_img/hyprland_2023-07-29_2.webp)
## Terminal Related
I used to use the following instructions frequently, but now **I switched my daily terminal environment to zellij**,
which provides a more powerful and stable terminal experience, so I don't use neovim's terminal feature anymore.
| Action | Shortcut |
| ----------------------------- | -------------- |
| Floating Terminal | `<Space> + tf` |
| Horizontal Split Terminal | `<Space> + th` |
| Vertical Split Terminal | `<Space> + tv` |
| Open IPython REPL | `<Space> + tp` |
## Visual Modes
| Action | Shortcut |
@@ -94,10 +106,6 @@ Provided by [flash.nvim](https://github.com/folke/flash.nvim), it's a intelligen
| Learn Neovim's Basics | `:Tutor` |
| Open file explorer | `<Space> + e` |
| Focus Neotree to current file | `<Space> + o` |
| Floating Terminal | `<Space> + tf` |
| Horizontal Split Terminal | `<Space> + th` |
| Vertical Split Terminal | `<Space> + tv` |
| Open IPython REPL | `<Space> + tp` |
| Toggle line wrap | `<Space> + uw` |
| Show line diagnostics | `gl` |
| Show function/variable info | `K` |

View File

@@ -1,8 +1,21 @@
# Termianl Emulators
1. kitty: My main terminal emulator.
2. wezterm: My secondary terminal emulator.
I used to spend a lot of time on terminal emulators, to make them match my taste,
but now I found that it's not worth it, **Zellij can provide a user-friendly and unified user experience for all terminal emulators! without any pain**!
Currently, I only use the most basic features of terminal emulators, such as true color, graphics protocol, etc.
Other features such as tabs, scrollback buffer, select/search/copy, etc, are all provided by zellij!
My current terminal emulators are:
1. kitty: My main terminal emulator.
1. to select/copy a large mount of text, We should do some tricks via kitty's `scrollback_pager` with neovim, it's really painful: <https://github.com/kovidgoyal/kitty/issues/719>
2. wezterm: My secondary terminal emulator.
1. its search ability is very basic, and it's not easy to use.
1. its scrollback buffer's copy mode is very like vim, which is nice, but zellij's even better, it can use neovim as its default scrollback buffer's editor without any pain!
3. foot: a fast, lightweight and minimalistic Wayland terminal emulator.
1. foot only do the things a terminal emulator should do, no more, no less.
1. It's really suitable for tiling window manager or zellij users!
## 'xterm-kitty': unknown terminal type when `ssh` into a remote host or `sudo xxx`

View File

@@ -7,24 +7,10 @@
#
# Kitty Configuration
#
# Useful Hot Keys for macOS:
# 1. New Tab: `command + t`
# 2. Close Tab: `command + w`
# 3. Switch Tab: `command + shift + [` | `command + shift + ]`
# 4. Increase Font Size: `command + =` | `command + +`
# 5. Decrease Font Size: `command + -` | `command + _`
# 6. And Other common shortcuts such as Copy, Paste, Cursor Move, etc.
# 7. Search/Select in the current window(show_scrollback): `ctrl + shift + f`
# This will open a pager, it's defined by `scrollback_pager`, default is `less`
# https://sw.kovidgoyal.net/kitty/overview/#the-scrollback-buffer
#
# Useful Hot Keys for Linux:
# 1. New Tab: `ctrl + shift + t`
# 2. Close Tab: `ctrl + shift + q`
# 3. Switch Tab: `ctrl + shift + right` | `ctrl + shift + left`
# 4. Increase Font Size: `ctrl + shift + =` | `ctrl + shift + +`
# 5. Decrease Font Size: `ctrl + shift + -` | `ctrl + shift + _`
# 6. And Other common shortcuts such as Copy, Paste, Cursor Move, etc.
# Useful Hot Keys for Linux(replace `ctrl + shift` with `cmd` on macOS)):
# 1. Increase Font Size: `ctrl + shift + =` | `ctrl + shift + +`
# 2. Decrease Font Size: `ctrl + shift + -` | `ctrl + shift + _`
# 3. And Other common shortcuts such as Copy, Paste, Cursor Move, etc.
#
###########################################################
{
@@ -48,33 +34,11 @@
{
"ctrl+shift+m" = "toggle_maximized";
"ctrl+shift+f" = "show_scrollback"; # search in the current window
"cmd+f" = "show_scrollback";
# Switch to tab 1-8(consistent with wezterm)
"ctrl+shift+1" = "goto_tab 1";
"ctrl+shift+2" = "goto_tab 2";
"ctrl+shift+3" = "goto_tab 3";
"ctrl+shift+4" = "goto_tab 4";
"ctrl+shift+5" = "goto_tab 5";
"ctrl+shift+6" = "goto_tab 6";
"ctrl+shift+7" = "goto_tab 7";
"ctrl+shift+8" = "goto_tab 8";
}
// (if pkgs.stdenv.isDarwin then {
# Switch to tab 1-8(consistent with wezterm)
"cmd+1" = "goto_tab 1";
"cmd+2" = "goto_tab 2";
"cmd+3" = "goto_tab 3";
"cmd+4" = "goto_tab 4";
"cmd+5" = "goto_tab 5";
"cmd+6" = "goto_tab 6";
"cmd+7" = "goto_tab 7";
"cmd+8" = "goto_tab 8";
} else {});
};
settings = {
background_opacity = "0.93";
macos_option_as_alt = true; # Option key acts as Alt on macOS
scrollback_lines = 10000;
enable_audio_bell = false;
tab_bar_edge = "top"; # tab bar on top
# To resolve issues:
@@ -82,13 +46,6 @@
# 2. https://github.com/ryan4yin/nix-config/issues/8
# Spawn a nushell in login mode via `bash`
shell = "${pkgs.bash}/bin/bash --login -c 'nu --login --interactive'";
# for selecting/searching in the current window
# https://github.com/kovidgoyal/kitty/issues/719
scrollback_pager = ''$SHELL -c 'nvim -u NONE -R -M -u ${./kitty_pager.lua} -c "lua kitty_pager(INPUT_LINE_NUMBER, CURSOR_LINE, CURSOR_COLUMN)" -' '';
# for active tab
active_tab_title_template = "{index}:{title}";
# for inactive tab
tab_title_template = "{index}:{title}";
};
# macOS specific settings

View File

@@ -1,62 +0,0 @@
kitty_pager = function(INPUT_LINE_NUMBER, CURSOR_LINE, CURSOR_COLUMN)
print('kitty sent:', INPUT_LINE_NUMBER, CURSOR_LINE, CURSOR_COLUMN)
vim.opt.encoding='utf-8'
vim.opt.clipboard = 'unnamed'
vim.opt.compatible = false
vim.opt.number = false
vim.opt.relativenumber = false
vim.opt.termguicolors = true
vim.opt.showmode = false
vim.opt.ruler = false
vim.opt.laststatus = 0
vim.o.cmdheight = 0
vim.opt.showcmd = false
vim.opt.scrollback = INPUT_LINE_NUMBER + CURSOR_LINE
local term_buf = vim.api.nvim_create_buf(true, false);
local term_io = vim.api.nvim_open_term(term_buf, {})
vim.api.nvim_buf_set_keymap(term_buf, 'n', 'q', '<Cmd>q<CR>', { })
vim.api.nvim_buf_set_keymap(term_buf, 'n', '<ESC>', '<Cmd>q<CR>', { })
local group = vim.api.nvim_create_augroup('kitty+page', {})
local setCursor = function()
vim.api.nvim_feedkeys(tostring(INPUT_LINE_NUMBER) .. [[ggzt]], 'n', true)
local line = vim.api.nvim_buf_line_count(term_buf)
if (CURSOR_LINE <= line) then
line = CURSOR_LINE
end
vim.api.nvim_feedkeys(tostring(line - 1) .. [[j]], 'n', true)
vim.api.nvim_feedkeys([[0]], 'n', true)
vim.api.nvim_feedkeys(tostring(CURSOR_COLUMN - 1) .. [[l]], 'n', true)
end
vim.api.nvim_create_autocmd('ModeChanged', {
group = group,
buffer = term_buf,
callback = function()
local mode = vim.fn.mode()
if mode == 't' then
vim.cmd.stopinsert()
vim.schedule(setCursor)
end
end,
})
vim.api.nvim_create_autocmd('VimEnter', {
group = group,
pattern = '*',
once = true,
callback = function(ev)
local current_win = vim.fn.win_getid()
for _, line in ipairs(vim.api.nvim_buf_get_lines(ev.buf, 0, -2, false)) do
vim.api.nvim_chan_send(term_io, line)
vim.api.nvim_chan_send(term_io, '\r\n')
end
for _, line in ipairs(vim.api.nvim_buf_get_lines(ev.buf, -2, -1, false)) do
vim.api.nvim_chan_send(term_io, line)
end
vim.api.nvim_win_set_buf(current_win, term_buf)
vim.api.nvim_buf_delete(ev.buf, { force = true } )
vim.schedule(setCursor)
end
})
end

View File

@@ -3,15 +3,10 @@
#
# Wezterm Configuration
#
# Useful Hot Keys for Linux:
# 1. New Tab: `ctrl + shift + t`
# 2. Close Tab: `ctrl + shift + q`
# 3. Switch Tab: `super + shift + right` | `super + shift + left`
# 4. Increase Font Size: `ctrl + shift + =` | `ctrl + shift + +`
# 5. Decrease Font Size: `ctrl + shift + -` | `ctrl + shift + _`
# 6. And Other common shortcuts such as Copy, Paste, Cursor Move, etc.
# 7. Copy Mode(vim like): `Ctrl + Shift + x`
# 8. Search Mode: `Ctrl + Shift + f`
# Useful Hot Keys for Linux(replace `ctrl + shift` with `cmd` on macOS)):
# 1. Increase Font Size: `ctrl + shift + =` | `ctrl + shift + +`
# 2. Decrease Font Size: `ctrl + shift + -` | `ctrl + shift + _`
# 3. And Other common shortcuts such as Copy, Paste, Cursor Move, etc.
#
# Default Keybindings: https://wezfurlong.org/wezterm/config/default-keys.html
#

View File

@@ -1,61 +0,0 @@
{pkgs, ...}: {
programs.tmux = {
enable = true;
shell = "${pkgs.nushellFull}/bin/nu";
# Resize the window to the size of the smallest session for which it is the current window.
#
aggressiveResize = true;
# https://github.com/tmux-plugins/tmux-sensible
# tmux-sensible overwrites default tmux shortcuts, makes them more sane.
sensibleOnTop = true;
# https://github.com/sxyazi/yazi/wiki/Image-preview-within-tmux
extraConfig = ''
set -g allow-passthrough on
set -ga update-environment TERM
set -ga update-environment TERM_PROGRAM
'';
# keyMode = "vi"; # default is emacs
baseIndex = 1; # start index from 1
escapeTime = 0; # do not wait for escape key
plugins = with pkgs.tmuxPlugins; [
{
# theme
# https://github.com/catppuccin/tmux
plugin = catppuccin;
extraConfig = ''
set -g @catppuccin_flavour 'mocha' # or frappe, macchiato, mocha
set -g @catppuccin_window_status_enable "yes"
'';
}
# https://github.com/tmux-plugins/tmux-yank
# Enables copying to system clipboard.
yank
{
# https://github.com/tmux-plugins/tmux-resurrect
# Manually persists tmux environment across system restarts.
# prefix + Ctrl-s - save
# prefix + Ctrl-r - restore
#
plugin = resurrect;
# Restore Neovim sessions
extraConfig = "set -g @resurrect-strategy-nvim 'session'";
}
# set -g @plugin 'tmux-plugins/tmux-cpu'
{
plugin = cpu;
extraConfig = ''
set -g status-right '#{cpu_bg_color} CPU: #{cpu_icon} #{cpu_percentage} | %a %h-%d %H:%M '
'';
}
];
};
}

View File

@@ -0,0 +1,29 @@
# Zellij - A workspace lives in your terminal
Zellij is a terminal workspace with batteries included.
At its core, it is a terminal multiplexer (similar to tmux and screen), but this is merely its infrastructure layer.
Zellij is very user-friendly and easy to use, with a step-by-step hint system that will help you get to know the keybindings, which is very like the Neovim or helix.
> By contrast, tmux's key design is counterintuitive, there is no prompt system, and the plug-in performance is rubbish. It's really a pain to use.
> tmux's inital release was in 2007, it's too old, I would recommend any users that do not have a experience with multiplexer to use zellij instead of tmux.
## Why use zellij as the detault terminal environment?
By auto start zellij on shell login, and exit the shell session on zellij exit, we can use zellij as the default terminal environment.
By this way, We will only use the most basic features of the terminal emulator(kitty/alacritty/wezterm/...),
while most of the functions of terminal are provided by zellij.
Thus we can easily switch to any terminal emulator without losing any key functions,
and do not need to take care of the differences between different terminal emulators.
And Zellij can be used not only locally, but also on any remote server, which is very convenient. Learn once and use everywhere!
> Yeah, you didn't misread it, zellij is very suitable for not only remotely, but also locally!
Some features such as search/copy/scrollback in different terminal emulators are implemented in different ways, and has different user experience.
For example, Wezterm's default search function is very basic, and it's not easy to use. Kitty's scrollback search/copy is really tricky to use.
As for some Editor such as Neovim, its intergrated terminal is really useful, but zellij is more powerful and useful than it, and more stable!
Zellij overcomes these problems, and provides a unified user experience for all terminal emulators!
Teminal emulators should only be responsible for displaying characters.

View File

@@ -16,7 +16,8 @@ in {
^zellij
}
# auto exit the shell session when zellij exit
# Auto exit the shell session when zellij exit
$env.ZELLIJ_AUTO_EXIT = "true" # enable auto exit
if "ZELLIJ_AUTO_EXIT" in $env and $env.ZELLIJ_AUTO_EXIT == "true" {
exit
}

View File

@@ -1,6 +1,10 @@
{pkgs, ...}: {
# TODO vscode & chrome both have wayland support, but they don't work with fcitx5, need to fix it.
programs = {
# a wayland only terminal emulator
foot = {
enable = true;
};
# source code: https://github.com/nix-community/home-manager/blob/master/modules/programs/chromium.nix
google-chrome = {
enable = true;

View File

@@ -40,7 +40,7 @@
tree
gnused
gawk
tmux
zellij
docker-compose
];