feat: add notify command, modify sidekick with tmux

This commit is contained in:
2026-05-26 16:54:53 +08:00
parent c32e8b4015
commit 4e8e3b7073
5 changed files with 63 additions and 1 deletions
+7
View File
@@ -0,0 +1,7 @@
function _notify_emit --argument-names title body
if set -q TMUX
printf '\ePtmux;\e\e]777;notify;%s;%s\a\e\\' "$title" "$body"
else
printf '\e]777;notify;%s;%s\a' "$title" "$body"
end
end
@@ -0,0 +1,13 @@
function _notify_human_duration --argument-names ms
test -z "$ms"; and set ms 0
set -l s (math --scale=0 $ms / 1000)
if test $s -lt 1
echo {$ms}ms
else if test $s -lt 60
echo {$s}s
else if test $s -lt 3600
echo (math --scale=0 $s / 60)m(math $s % 60)s
else
echo (math --scale=0 $s / 3600)h(math --scale=0 ($s % 3600) / 60)m
end
end
+24
View File
@@ -0,0 +1,24 @@
function notify-done --description '前置包装:运行命令并在完成时发送 OSC 777 通知'
if test (count $argv) -eq 0
echo "Usage: notify-done <command> [args...]" >&2
return 2
end
set -l start (date +%s)
$argv
set -l rc $status
set -l elapsed (math (date +%s) - $start)
set -l human (_notify_human_duration (math $elapsed \* 1000))
set -l label
if test $rc -eq 0
set label "完成: $argv[1]"
else
set label "失败 exit=$rc: $argv[1]"
end
set -l body "$human · "(hostname -s)" · "(string join ' ' $argv)
_notify_emit "$label" "$body"
return $rc
end
+18
View File
@@ -0,0 +1,18 @@
function notify --description '发送 OSC 777 通知;无参时复用上一条命令的状态与耗时'
set -l rc $status
set -l dur $CMD_DURATION
set -l label
if test (count $argv) -gt 0
set label (string join ' ' $argv)
else if test $rc -eq 0
set label "完成"
else
set label "失败 exit=$rc"
end
set -l body (_notify_human_duration $dur)" · "(hostname -s)" · "(pwd | string replace $HOME '~')
_notify_emit "$label" "$body"
return $rc
end
+1 -1
View File
@@ -5,7 +5,7 @@ return {
cli = {
mux = {
backend = vim.env.ZELLIJ and "zellij" or "tmux",
enabled = false,
enabled = true,
},
},
},