Skip to content

Instantly share code, notes, and snippets.

@delphinus
Last active June 30, 2025 03:05
Show Gist options
  • Select an option

  • Save delphinus/d1280fd9c9f32218f2c65477ec3640db to your computer and use it in GitHub Desktop.

Select an option

Save delphinus/d1280fd9c9f32218f2c65477ec3640db to your computer and use it in GitHub Desktop.
Notify when slow commands finished in background
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 --format json | /usr/bin/ruby -r json -e 'puts JSON.parse($<.read).find{|x|x["pid"]=='$active_pid'}&.[]"focused_pane_id"')
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)
set -l escaped (string replace -a '"' '\"' -- $msg)
if test -n "$NVIM"; and type -q nvr
nvr --remote-send "<Cmd>lua vim.notify(\"$escaped\", vim.log.levels.WARN, { title = \"command completed\" })<CR>"
else
osascript -e "display notification \"$escaped\" with title \"command completed\""
end
end
end
@delphinus
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment