Skip to content

Instantly share code, notes, and snippets.

@shriakhilc
Last active February 11, 2018 19:47
Show Gist options
  • Save shriakhilc/8534752f6b80f42d36a11aaea88097af to your computer and use it in GitHub Desktop.
Save shriakhilc/8534752f6b80f42d36a11aaea88097af to your computer and use it in GitHub Desktop.
Linux Quick Reminder

Remind

A simple function wrapper over the default linux desktop notifications library, to be used in conjunction with the at command for setting quick reminders via the command-line. Just add the function to either ~/.bashrc or ~/.bash_profile and you're good to go. (Don't forget to source it or restart the bash terminal)

Tested with the bash shell on Ubuntu 17.10 . While the commands themselves should be available in most Linux distributions, some minor modifications might be needed for zsh or other shells.

Requirements and Installation instructions

notify-send should be installed by default on a lot of linux distributions, but in case it is missing install the notify-osd package. For Ubuntu, you can do this by executing

sudo apt-get install notify-osd

at is a command used to schedule 'jobs' that are executed at the specified time. It allows fairly complex time specifications apart from the standard 12-hour and 24-hour formats (Check the man page for more details). You can install it by running:

sudo apt-get install at

Sample Usage

The text body of your reminder must be passed to the command in quotes, so that it is treated as a single argument. Follow this with a time specified in a format accepted by the at command.

If no time is passed, the reminder is sent immediately.

  1. To set a reminder for 15 minutes later
remind "body" now + 15 minutes
  1. To set a reminder for 7pm
remind "body" 7pm

Resources

You can pass whatever icon and tone files you wish, but the samples I've referred to in the code can be found here. Just be sure to update the path accordingly, or it will go with the default icon. There is no default tone, so you'll be left with a simple notif rather than a reminder.

# Add this line to the bottom of your ~/.bashrc (or ~/.bash_profile, as applicable)
# This function can be named anything you like, not just "remind". Normal tab completion will work with this name
remind () {
# Flags and construction:
# urgency (`-u`) is set to critical because both Unity and Gnome ignore the `-t` flag
# and the default pop-up remains for only a short while.
# the `image-path` hint specifies the path to the notification icon, and the `sound-file` to tone.
# current code assumes both files are in the home directory (`~`).
# If no time args were passed runs with `at now`
if [[ ! -z "${@:2}" ]]; then
echo "notify-send \"$1\" -u critical -h string:image-path:bell-120.png -h string:sound-file:open-ended.ogg" | at "${@:2}"
else
echo "notify-send \"$1\" -u critical -h string:image-path:bell-120.png -h string:sound-file:open-ended.ogg" | at now
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment