Last active
February 17, 2025 13:01
-
-
Save delphinus/e8f4108dd58424a1b3d89de4ebafc678 to your computer and use it in GitHub Desktop.
Notify when slow commands finished in background (v2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -gx NOTIFY_ON_COMMAND_DURATION 5000 | |
function fish_right_prompt | |
set -f check_neovim | |
if test -n "$CMD_DURATION"; and test $CMD_DURATION -gt $NOTIFY_ON_COMMAND_DURATION | |
if type -q wezterm; and test -n "$WEZTERM_PANE" | |
set -l active_pid (osascript -e 'tell application "System Events" to get the unix id of first process whose frontmost is true') | |
set -l active_pane (wezterm cli list-clients | perl -anle 'print $F[$#F] if $F[2] == '$active_pid) | |
if test -n "$active_pane"; and test $WEZTERM_PANE -eq $active_pane | |
set -f check_neovim 1 | |
end | |
else | |
set -f check_neovim 1 | |
end | |
if test -n "$check_neovim" | |
if test -z "$NVIM"; or ! type -q nvr | |
return | |
end | |
set -l pid (nvr --remote-expr 'luaeval("vim.F.npcall(vim.fn.jobpid, vim.bo.channel)")') | |
if test $fish_pid = $pid | |
return | |
end | |
end | |
set -l duration (bc -S2 -e $CMD_DURATION/1000) | |
set -l msg (echo (history | head -1) returned $status after $duration s) | |
if test -n "$NVIM"; and type -q nvr | |
nvr --remote-send '<Cmd>lua vim.notify("'$msg'", vim.log.levels.WARN, { title = "command completed" })<CR>' | |
else | |
osascript -e 'display notification "'$msg'" with title "command completed"' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment