改用 alacritty

原先習慣用 terminator, 為何不用 gnome-terminal 的原因甚至已經忘了。某天看到 ghostty 宣傳說顯示速度很快,看了一下測試報告都是跟 alacritty 比較,表示應該也很快,就決定都玩一下。結果用了 alacritty 覺得很「斯巴達」,尤其那個 vi mode, 正合胃口。ghostty 一堆功能似乎也不需要,就放著了,先換成 alacritty.

過程還蠻順的,主要是以下幾個設定:

TERM 是 alacritty, 先要讓 .bashrc 認得。首先是彩色的提示詞:

1
2
3
4
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color|*-256color|alacritty*) color_prompt=yes;;
esac

以及後面改 window title 的部份:

1
2
3
4
5
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*|alacritty*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;

這邊有個麻煩,因為其他機器上的 .bashrc 沒改,所以連過去以後又變成不認得,乾脆在 ~/.ssh/config 裡面加一行:

1
SetEnv TERM=xterm-256color

這樣連出去時就會用很平常的 xterm-256color. 然後是設定檔 ~/.config/alacritty/alacritty.toml

1
2
3
4
5
6
7
8
9
10
[general]
import = [
"~/code/alacritty-theme/themes/solarized_dark.toml",
]
[font]
size = 10
[keyboard]
bindings = [
{ key = "P", mods = "Control|Shift", command = { program = "alacritty.sh", args = [ "ct", ]}}
]

這邊就是先把 alacritty-theme 抓到 ~/code/ 然後預設為慣用的 solarized_dark. [keyboard] 則是多設定一快速鍵可以切換 theme. 針對這寫了一個小 script, alacritty.sh:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash

ALACRITTY_THEME="/tmp/alacritty-theme"
THEME=solarized_dark

case "$1" in
change-theme|ct)
case "$(cat "$ALACRITTY_THEME")" in
solarized_dark) THEME=solarized_light;;
solarized_light) THEME=google;;
esac
alacritty msg config "$(cat ~/code/alacritty-theme/themes/${THEME}.toml)"
notify-send "$THEME"
echo "$THEME" | tee "$ALACRITTY_THEME"
exit
;;
esac

if pgrep -u $(id -u) 'alacritty$' &> /dev/null; then
exec alacritty msg create-window "$@"
else
echo "$THEME" > "$ALACRITTY_THEME"
exec alacritty "$@"
fi

這 script 有多重功能,除了加 change-themect 可以在 solarized_dark, solarized_light, google 三個 theme 循環切換之外,一般呼叫時也會偵測是否已經在執行,如果有的話,開新視窗就好,不用多跑一份。

最後一個設定是針對 Emacs 的。以前寫過 Emacs 彩色終端,這邊就是要加上 alacritty-direct. 一樣用 wrapper script emacs.sh 達成。功能除了設定 TERM, 還會看是否已經在執行(因為我都用 server-mode),如果有,就直接跑 emacsclient.

1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash

if pgrep -u $(id -u) 'emacs$' &> /dev/null; then
case x"$TERM" in
xalacritty*) export TERM=alacritty-direct;;
xxterm-256color) export TERM=xterm-direct;;
esac
exec emacsclient -t "$@"
else
exec /usr/bin/emacs "$@"
fi

用起來真的蠻有感的,顯示什麼都是刷一下就結束。還不錯。