feat: add notify command, modify sidekick with tmux
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user