franciscolourenco / done Goto Github PK
View Code? Open in Web Editor NEWA fish-shell package to automatically receive notifications when long processes finish.
License: MIT License
A fish-shell package to automatically receive notifications when long processes finish.
License: MIT License
terminal-notifier has the ability to trigger a sound using the -sound
parameter. It would be a nice addition if this was configurable.
I don't know if it's possible but what about warning the user when the program is hanging or when there is a prompt to answer?
That would be really really helpful
In #36 it was pointed out that Done does not send message when working on a remote server.
This feature request is to allow the user to use a custom command to allow sending the done message to them. Getting notification message to popup on remote machines is problematic at best.
However there are a number of push and chat services such as PushBullet and Telegram that have APIs that allow one to quickly put together a Fish function or shell script that sends out a message. I have created some of these that I can add to the end of a long running command, however I sometimes forget to add the notification function command after my long running command, ie. sleep 300; telegram-me
and then of course do not get notified.
Looking at the done
code there are numerous checks to make sure that the terminal window is not in the foreground and that this is not a SSH session.
Done also appears to have the option to run a custom command to notify, but it seems no way to pass the done message to that custom command.
To do list get notifications while ssh into a remote server.
1. Add a way to disable foreground checking
2. Add a to disable SSH checking
3. Add a way to pass the done message to the custom command
4. Document usage.
In my original comment on #36, I suggested that variables could be set for some of these but I think that a configuration file for done
might be a better idea for setting the above three items.
If the done
project also wants to include sample Fish functions for some of the push and chat services, I could help out by creating on for Telegram.
After the above is finished the user could install done
on the remote server then configure it to disable foreground checking, disable SSH checking, and set the custom command that done will call and pass the message to so that it can be delivered.
Something like:
set -l NOTIF_BEEP 1 # Allow beep or not
# Beep
if test "$NOTIF_BEEP" -eq 1
echo -n \a
end
(btw the bell sound doesn't work on my computer but that's not fish related)
AFAICT, this doesn't work with tmux.
OS: MacOS 10.14.5
Terminal: iTerm2 3.3.0beta5
tmux: 2.9a
fish: 3.0.2
without tmux, this works as expected. With tmux, I get no notifications.
I have an editw
function that opens a file in TextMate and waits (mate -w
) for the file to be closed before allowing the terminal to continue. This is the only way to use a GUI editor for things like git commit messages or interactive rebase. The editw
function falls back to using Vim for non-login shells and SSH connections.
I get no notification when this function ends up launching Vim since it lives in the terminal, but when TextMate is invoked from the terminal, I always get a notification from done when it closes and the terminal continues.
Is there a way to change this behavior?
It seems like a list of commands to exclude (like this example) might be the simplest way to accomplish this. The list would need to be user-configurable. I can submit a PR to introduce excluded commands unless someone knows of a better approach.
Hey, thank you for this project. It's a really handy feature to get notifications for long-running commands, it's something I've long wanted to have ❤️
I had to log out from my sway session to get this to apply. You could maybe add some notice in the readme about that. Something like:
## Installation
...
You may also need to log out of your current session.
Have a nice day 👍
It would be nice if I could exclude certain commands from the list; particularly those who are interactive, such as vim
, git commit
or git add -i
. Since I'm interacting with those commands myself, I get no value from being notified about those commands finishing; and since the whole command is driven by human actions, they often take more than ten seconds.
I see in the source code that there's already a list of commands to ignore; it would be nice if it were customizable. If you have any ideas about how this should be implemented, I may be able to implement this myself.
Another approach would be to detect if a command is interactive, I guess? I have no idea if that's remotely feasible or not.
I've been thinking about reducing the default minimum period a command needs to run in order to trigger a notification from 10s
to 3s
or 5s
. Any scenarios where you think this would be undesirable?
I followed the manual instrunctions from the readme:
> curl -Lo ~/.config/fish/conf.d/done.fish --create-dirs https://raw.githubusercontent.com/franciscolourenco/done/master/conf.d/done.fish
Even after logging in again sleep 6
doesn't lead to a notification. I have no clue what I have done wrong, or what part isn't working. I would be happy if you can help. Thanks for your time.
System information:
> echo $__done_version
1.15.0
Edit:
notify-send test
leads to a notification
When a long-running process finishes, these messages show up in the terminal:
(standard_in) 1: syntax error
(standard_in) 1: syntax error
test: Missing argument at index 2
test: Missing argument at index 2
Also, the title of the notification is just "Done in", not e.g. "Done in 20s".
I think the problem is on lines 159 and 160 of done.fish
, which read:
set -l seconds (math --scale=0 "$milliseconds/1000" % 60)
set -l minutes (math --scale=0 "$milliseconds/60000" % 60)
Running one of those lines in a terminal fails. I think Fish doesn't like the %. If I move the quotes to this...
set -l seconds (math --scale=0 "$milliseconds/1000 % 60")
set -l minutes (math --scale=0 "$milliseconds/60000 % 60")
...then the error messages go away, and the notification shows the runtime.
I see that it has an internal list of commands to skip but it would be great if we could add to the list.
I generally love using your package (I get alerted when long compilation or test run on another desktop is over), but I repeatably end up with 3-6 notifications hanging on the screen as closing them is unpleasant.
It would be nice if they could disappear by themselves.
I changed line 222 of done.fish
to:
notify-send --urgency=$urgency --icon=utilities-terminal --app-name=fish --expire-time=60000 "$title" "$message"
and my notifications nicely disappear after 60 seconds under KDE Plasma.
I noticed that notify-send
manpage claims that Gnome Shell ignores this param, and I do not know how well it is supported by non-Linux tools, but … well, there is at least one popular desktop which handles that limit properly.
Of course hardcoding 60s is bad idea, whether such time limit is used and which should be configurable via some variable (and in case it is enabled by default, sth like 5 mins seems more reasonable).
Prompt hangs if fish is being run from Linux VT console.
This happens because test -n __done_get_focused_window_id
always evaluates to true
, regardless of DISPLAY variable being set.
I don't use tmux and done 1.7 started giving me error messages about being unable to connect to tmux on stderr.
> sleep 6
error connecting to /tmp/tmux-1000/default (No such file or directory)
It would be nice if instead of "1837 seconds", the display said "30:37".
When I have some command that returns a non-zero status, the notification stays on the screen forever, until I manually close it. I'm using done with KDE Plasma, under Arch Linux, and this only happens for notifications of this package.
Related to #2
__done_notification_command
is good enough for simple things but the escaping needed can get really bad for complex commands.
What do you think about testing if __fish_config_dir/conf.d/done_command.fish
exists and sourcing it in case it does?
I'm up to making a PR. I actually have my done.fish
edited in this way already.
As in subject.
Hi, since this morning I started to have errors at the end of every command output:
$ sleep 6; echo yay
yay
test: Missing argument at index 2
~/.config/fish/conf.d/done.fish (line 180):
if test -q __done_notification_urgency_level
^
in function '__done_ended'
in event handler: handler for generic event “fish_prompt”
(Type 'help test' for related documentation)
not sure what caused the issue. Alerts are working fine as usual (both normal and errors).
I'm using tmux 3.1b, fish 3.1.2, done 1.14.7.
command -s tell
returns nothing now. tell
is no longer a program.
not sure what would be a better test.
Hey,
somehow there is a notification coming even tho the terminal is my active window but I had multiple terminals open. (the open with task was the active one)
Best 💪
I don't know what the plugin is supposed to do but I type "sleep 6" and nothing happens.
I made my tests by connecting on a debian 9 server, logging in SSH, in Byobu, installing fisherman and "done" aand typing "sleep 6" and switching window or not.
I suggest to add these commands to the default ignored commands:
nano vim edit sudoedit ssh top man htop iotop less more
If I find more I'll note them down.
Feel free to discuss them
Current version defines multiple functions which need to be loaded in order for the plugin to work. Fish however, only loads automatically the function which name matches the file's name (_done
in this case).
One option would be to define all the functions inside a main function, but then, the main function needs to also be executed when the shell is started, not only loaded.
@jbucaran Any idea on how to work around this?
Example:
function _done
set _initial_window_id ''
function _get_window_id
if _is_available lsappinfo
lsappinfo info -only bundleID (lsappinfo front) | cut -d '"' -f4
else if _is_available xprop
xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2
end
end
function _is_terminal_focused
test $_initial_window_id = (_get_window_id)
end
function _is_available
type -q $argv
end
function _started --on-event fish_preexec
echo "_ended"
set _initial_window_id (_get_window_id)
end
function _ended --on-event fish_prompt
echo "_ended"
if test $CMD_DURATION
# Store duration of last command
set duration (echo "$CMD_DURATION 1000" | awk '{printf "%.3fs", $1 / $2}')
set notify_duration 10000
if begin
test $CMD_DURATION -gt $notify_duration # longer than notify_duration
and not _is_terminal_focused # terminal or window not in foreground
end
set -l title "Finished in $duration"
set -l message "$history[1]"
if _is_available terminal-notifier # https://github.com/julienXX/terminal-notifier
terminal-notifier -message "$message" -title "$title" -sender "$_initial_window_id"
else if _is_available osascript # AppleScript
osascript -e "display notification \"$message\" with title \"$title\""
else if _is_available notify-send # Linux notify-send
notify-send --icon=terminal --app-name=terminal "$title" "$message"
else # anything else
echo -e "\a" # bell sound
end
end
end
end
end
balupton@balbook ~> fisher done
Installing 1 plugin/s
OK Fetch done github.com/fisherman/done
Installing 1 dependency
OK Fetch humanize_duration github.com/fisherman/humanize_duration
Done in 5s 980ms
balupton@balbook ~> ping -t 5 google.com
PING google.com (216.58.200.110): 56 data bytes
64 bytes from 216.58.200.110: icmp_seq=0 ttl=55 time=55.864 ms
64 bytes from 216.58.200.110: icmp_seq=1 ttl=55 time=58.456 ms
64 bytes from 216.58.200.110: icmp_seq=2 ttl=55 time=57.946 ms
64 bytes from 216.58.200.110: icmp_seq=3 ttl=55 time=58.496 ms
64 bytes from 216.58.200.110: icmp_seq=4 ttl=55 time=56.049 ms
--- google.com ping statistics ---
5 packets transmitted, 5 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 55.864/57.362/58.496/1.165 ms
balupton@balbook ~> ping -t 15 google.com
PING google.com (216.58.200.110): 56 data bytes
64 bytes from 216.58.200.110: icmp_seq=0 ttl=55 time=55.806 ms
64 bytes from 216.58.200.110: icmp_seq=1 ttl=55 time=58.316 ms
64 bytes from 216.58.200.110: icmp_seq=2 ttl=55 time=55.934 ms
64 bytes from 216.58.200.110: icmp_seq=3 ttl=55 time=55.723 ms
64 bytes from 216.58.200.110: icmp_seq=4 ttl=55 time=58.599 ms
64 bytes from 216.58.200.110: icmp_seq=5 ttl=55 time=58.707 ms
64 bytes from 216.58.200.110: icmp_seq=6 ttl=55 time=55.607 ms
64 bytes from 216.58.200.110: icmp_seq=7 ttl=55 time=58.368 ms
64 bytes from 216.58.200.110: icmp_seq=8 ttl=55 time=58.910 ms
64 bytes from 216.58.200.110: icmp_seq=9 ttl=55 time=58.689 ms
64 bytes from 216.58.200.110: icmp_seq=10 ttl=55 time=58.462 ms
64 bytes from 216.58.200.110: icmp_seq=11 ttl=55 time=58.585 ms
64 bytes from 216.58.200.110: icmp_seq=12 ttl=55 time=55.883 ms
64 bytes from 216.58.200.110: icmp_seq=13 ttl=55 time=58.740 ms
64 bytes from 216.58.200.110: icmp_seq=14 ttl=55 time=59.470 ms
--- google.com ping statistics ---
15 packets transmitted, 15 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 55.607/57.720/59.470/1.389 ms
test: Missing argument at index 2
Whenever I run a command I get this error message
fish: Unknown command: humanize_duration ~/.config/fish/functions/fish_right_prompt.fish (line 1): echo $CMD_DURATION | humanize_duration ^ in command substitution called on line 28 of file ~/.config/fish/functions/fish_right_prompt.fish in function 'fish_right_prompt' in command substitution ~/.config/fish/functions/fish_right_prompt.fish: Unknown error while evaluating command substitution in function 'fish_right_prompt' in command substitution
Would it be possible to customize the command that's used? I use ntfy for the same purpose, but I always have to run everything prefixed by the command. This plugin is great in that it's automatic, but it's currently not working for me, and I don't really want to install Ruby just to install the terminal notifier...
Pretty much as in the description. Switching to the terminal when clicking on the corresponding notification would be nice.
Actually, it displays the notification when the window is not focused, which is great, but if you open a new tab and switch to it, then the notification won't display because it considers you're in the same windows (which is true lol)
Need to add a tab option
I'm on linux so it's probably this line to edit, but no idea how:
xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2
Maybe getting the tab title can work too?
PS: why is the main file in /conf.d/ ??
I have this error after the last FISH update (to 3.1).
done version 1.14.3
~/.config/fish/conf.d/done.fish (line 126):
eval $__done_notification_command
^
in function “__done_ended”
called on standard input
in event handler: handler for generic event “fish_prompt”
done 1.7 tries to call __done_get_window_id
but that function does not seem to be defined. Is it supposed to be __done_get_focused_window_id
?
> true
fish: Unknown command '__done_get_window_id'
~/.config/fish/conf.d/done.fish (line 1):
__done_get_window_id
^
in command substitution
called on line 62 of file ~/.config/fish/conf.d/done.fish
in function “__done_started”
called on standard input
with parameter list “true”
in event handler: handler for generic event “fish_preexec”
Hi there, thank you for your work!
Since the latest version 1.14.1, it seems like done.fish is invoking import
somewhere and import
is also known as an ImageMagick tool, blocking the shell, waiting for a GUI input.
I'm not sure if it's related to PowerShell addition because of Import-Module
or something like this.
Can I give you some help to find this?
Thanks!
Running __done_get_focused_window_id
currently returns this:
$ __done_get_focused_window_id
usage: xprop [-options ...] [[format [dformat]] atom] ...
where options include:
-grammar print out full grammar for command line
-display host:dpy the X server to contact
-id id resource id of window to examine
-name name name of window to examine
-font name name of font to examine
-remove propname remove a property
-set propname value set a property to a given value
-root examine the root window
-len n display at most n bytes of any property
-notype do not display the type field
-fs filename where to look for formats for properties
-frame don't ignore window manager frames
-f propname format [dformat] formats to use for property of given name
-spy examine window properties forever
It is the results of running xprop -version 2>&1 >/dev/null
at done.fish#L33. There is no option -version
in KDE Neon's (which is Ubuntu 18.04-based) xprop
. Commenting out that line makes it work well.
done fails for me because $CMD_DURATION
was renamed to $cmd_duration
.
This is the commit fish-shell/fish-shell@18b06f3
When I run terminal-notifier -message "Test" -sender "$__done_initial_window_id"
this does not work. However when I run terminal-notifier -message "Test" -sender "iTerm2"
this works. It looks like __done_initial_window_id
is being set to com.googlecode.iterm2
.
jorgebucaran/FISH-humanize_duration was renamed to jorgebucaran/fish-humanize-duration
https://github.com/fisherman/done/blob/d07eca1cde37303cf63ca8ab4fbb951d883a3f81/conf.d/done.fish#L30
I sourced done.fish in my config.fish, and after every fish prompt, there will be a line of error message:
No protocol specified
and found the issue is caused by the xprop line:
xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2
but I'm not familiar with the xprop, after googling a while but didn't get the solution.
FYI:
openSUSE Tumbleweed
fish-shell v2.7.1
Thanks for making an interesting plugin!
I'll definitely use it if we can configure the command to notify.
Here's why:
Thanks in advance.
When logging in remotely over SSH in a non-graphical session, after every command
xprop: unable to open display ''
is displayed. Maybe check for DISPLAY
environment variable first, before running xprop
?
So in the spirit of
[ -n "$DISPLAY" ]; and xprop etc
It doesn't work for my old platform which is CentOS 6.5 32-bit
notify-send -v: 0.5.0
Error message:
Unknown option --app-name=terminal
Don't know if it is caused by the old version of notify-send, but I cannot get new version right now.
So, after modifying the line in done.fish
notify-send --icon=terminal --app-name=terminal "$title" "$message"
to
notify-send --icon=terminal "$title" "$message"
it will work.
BTW: you didn't mention in the README.md file that the done
plugin depends on humanize_duration plugin.
When I run sleep 6 like in the readme.md, no burnt toast output is displayed. Burnt toast does work when the New-BurntToastNotification command is run in both PowerShell 5 (default windows) and PowerShell 7 (the new open source one), which means it isn't a executionpolicy issue.
Perhaps the notification can say whether the command finished with an error or successfully? This could be as simple as "Finished in X" and "Errored in X".
After installation, running sleep 6
does nothing. I tried in both iTerm 2 and Fish apps.
The file at test/done.fish
doesn't appear to contain valid fish syntax where the test
function is used, is this on purpose?
function setup
source conf.d/done.fish
end
test "command are executed without errors"
0 -eq (echo 1 > /dev/null; echo $status)
end
Output:
/t/d/test >>> fish done.fish
done.fish (line 7): 'end' outside of a block
end
^
fish: Error while reading file done.fish
After using done for some time, I find maintaining __done_exclude
unpleasant. It simply grows long. Mostly it's because I happen to spawn GUI apps from the terminal, and - for example - when my emacsclient -cn
ends it's job after an hour or two, fish gladly notifies me.
So it would be nice if I could „add next exception without touching those already existing”. For example by sth like
set -Ua __done_exclude emacsclient
set -Ua __done_exclude '(scite|gedit)'
(result: all exceptions which were present, are still there, and I just added two more)
Hi,
I'm getting the following error after a fisher add
:
❯ sleep 7
wslvar: command not found
~/.config/fish/conf.d/done.fish (line 1):
wslvar windir
^
in command substitution
called on line 1 of file ~/.config/fish/conf.d/done.fish
in command substitution
called on line 164 of file ~/.config/fish/conf.d/done.fish
in function '__done_ended'
in event handler: handler for generic event “fish_prompt”
~/.config/fish/conf.d/done.fish: Unknown error while evaluating command substitution
in command substitution
called on line 164 of file ~/.config/fish/conf.d/done.fish
in function '__done_ended'
in event handler: handler for generic event “fish_prompt”
~/.config/fish/conf.d/done.fish: Unknown error while evaluating command substitution
in function '__done_ended'
in event handler: handler for generic event “fish_prompt”
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.