Skip to content

Commit 4762a15

Browse files
committed
feat(mise): auto-set wezterm tab title by project
1 parent df39a83 commit 4762a15

3 files changed

Lines changed: 46 additions & 20 deletions

File tree

.config/mise/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ python.uv_venv_create_args = ["--seed"]
1212
terminal_progress = false
1313
lockfile = true
1414

15+
[hooks]
16+
enter = { script = 'set_terminal_title', shell = "zsh" }
17+
leave = { script = "reset_terminal_title", shell = "zsh" }
1518

1619
[tools]
1720
rust = "nightly"

.config/zsh/custom_functions.zsh

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,52 @@
1-
#!/usr/env zsh
1+
#!/usr/bin/env zsh
22

33
# Set terminal title
44
function set_terminal_title() {
5-
local title="$1"
6-
if [[ -z "$title" ]]; then
7-
echo "Usage: set_terminal_title <title>"
8-
return 1
5+
local icon_dir=""
6+
local start_dir current_dir project_root project_name package_json
7+
8+
start_dir="$PWD"
9+
current_dir="$start_dir"
10+
project_root=""
11+
12+
while [ -n "$current_dir" ] && [ "$current_dir" != "/" ]; do
13+
if [ -d "$current_dir/.git" ]; then
14+
icon_dir="󰊢 "
15+
project_root="$current_dir"
16+
break
17+
fi
18+
19+
current_dir="$(dirname "$current_dir")"
20+
done
21+
22+
if [ -z "$project_root" ]; then
23+
project_root="$start_dir"
24+
fi
25+
26+
package_json="$project_root/package.json"
27+
tsconfig="$project_root/tsconfig.json"
28+
project_name="$(basename "$project_root")"
29+
30+
if [ -f "$package_json" ]; then
31+
icon_dir="󰌞 "
32+
33+
if command -v jq >/dev/null 2>&1; then
34+
project_name="$(jq -r '.name // empty' "$package_json" 2>/dev/null || true)"
35+
fi
36+
fi
37+
38+
if [ -f "$tsconfig" ]; then
39+
icon_dir="󰛦 "
940
fi
1041

11-
case "$TERM" in
12-
wezterm)
13-
wezterm cli set-tab-title "$title"
14-
;;
15-
esac
42+
if [ "$TERM" = "wezterm" ]; then
43+
wezterm cli set-tab-title "$icon_dir $project_name"
44+
fi
1645
}
1746

1847
# Reset terminal title
1948
function reset_terminal_title() {
20-
case "$TERM" in
21-
wezterm)
22-
wezterm cli set-tab-title ""
23-
;;
24-
esac
49+
if [ "$TERM" = "wezterm" ]; then
50+
wezterm cli set-tab-title ""
51+
fi
2552
}

mise.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ lockfile = true
33

44
[env]
55
HK_MISE = 1
6-
HK_STAGE = 0
6+
HK_STAGE = 1
77

88
[tools]
99
pkl = "latest"
@@ -12,10 +12,6 @@ shellcheck = "latest"
1212
stylua = "latest"
1313
yamllint = "latest"
1414

15-
[hooks]
16-
enter = { script = 'set_terminal_title "󰒓 {{ config_root | basename }}"', shell = "zsh" }
17-
leave = { script = "reset_terminal_title", shell = "zsh" }
18-
1915
[tasks.check]
2016
description = "Run all checks"
2117
run = "hk run check"

0 commit comments

Comments
 (0)