diff --git a/README.md b/README.md index 21597f2..57c8155 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,20 @@ -# remind +# Remind -A simple bash script to remind something by stipulated time. \ No newline at end of file +A simple bash script to remind something by stipulated time. + +## Install + +```bash +sh <(curl -s https://git.lucasf.dev/public/remind/raw/branch/master/install.sh) +``` + +## Usage + +Example of usage: + +```bash +remind do something cool +> Time to delay: 15m +``` + +The time can be (s|m|h) diff --git a/beep.mp3 b/beep.mp3 new file mode 100644 index 0000000..0d51ac8 Binary files /dev/null and b/beep.mp3 differ diff --git a/clock.svg b/clock.svg new file mode 100644 index 0000000..f55c9d4 --- /dev/null +++ b/clock.svg @@ -0,0 +1,149 @@ + + diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..8c6690b --- /dev/null +++ b/install.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +main() { + local SOUNDDIR="$HOME/.local/share/sounds" + local ICONDIR="$HOME/.local/share/icons" + local CMDDIR="$HOME/.local/bin/" + + + if [[ ! -d "./remind" ]]; then + git clone https://git.lucasf.dev/public/remind > /dev/null 2>&1 + if [[ ! -d "$SOUNDDIR" ]]; then + mkdir -p "$SOUNDDIR" + fi + if [[ ! -d "$ICONDIR" ]]; then + mkdir -p "$ICONDIR" + fi + mv $(pwd)/remind/remind $CMDDIR + mv $(pwd)/remind/clock.svg $ICONDIR + mv $(pwd)/remind/beep.mp3 $SOUNDDIR + rm -rf $(pwd)/remind + else + echo -e "\033[31m[error]\nRemove the remind folder first.\n\033[0m" + exit 1 + fi + +} + +main +if [[ $? -eq 0 ]];then echo "Remind installed"; fi + +# vim: ft=bash:ts=4:sts=4:sw=4 diff --git a/remind b/remind new file mode 100755 index 0000000..1f73911 --- /dev/null +++ b/remind @@ -0,0 +1,64 @@ +#!/bin/bash + + +CMD="cancel" +SOUND_LOCATION="$HOME/.local/share/sounds" +ICON_LOCATION="$HOME/.local/share/icons/clock.svg" + +_execute() { + if [[ $TIMECHOOSEN =~ ^[1-9]?[0-9](s|m|h)$ ]]; then + sleep $TIMECHOOSEN + notify-send -i $ICON_LOCATION "Reminder" "$MSG" + ffplay -nodisp -autoexit -hide_banner -loglevel error $SOUND_LOCATION/beep.mp3 + else + echo -e "\033[31m[error]\nThe time must be provided as the example: 10(s|m|h).\n\033[0m" + fi +} + +_parse() { + if [[ $@ == "$CMD" ]]; then + _pre_cancel + else + _remind $@ + fi +} + +_remind() { + MSG="$@" + + if [[ -z "$@" ]]; then + echo -e "\033[31m[error]\nProvide a remind text first.\n\033[0m" + else + read -p 'Time to delay: ' TIMECHOOSEN + if [[ -z "$TIMECHOOSEN" ]]; then + echo -e "\033[31m[error]\nProvide a time.\n\033[0m" + else + _execute $@ $TIMECHOOSEN & + fi + fi +} + +_pre_cancel() { + NUMOFLINES=$(pgrep -a remind | wc -l) + if [[ $NUMOFLINES -le 2 ]]; then + echo "No reminders to cancel" + else + _cancel + fi +} + +_cancel() { + pgrep -a remind | awk -F "remind" -v nl="$NUMOFLINES" '{ if (NR < (nl - 1)) { print "[" NR "]" $NF}}' + read -p "Please choose a number to cancel [1-$(($NUMOFLINES - 2))]: " CHOOSE + if [[ $CHOOSE =~ ^[1-9]?[0-9] ]]; then + if [[ $CHOOSE -le $(($NUMOFLINES - 2)) ]]; then + kill $(pgrep -a remind | awk -F " " -v op="$CHOOSE" '{ if (NR == op) { print $1}}') + else + echo -e "\033[31m[error]\nInvalid option.\n\033[0m" + fi + else + echo -e "\033[31m[error]\nInvalid option.\n\033[0m" + fi +} + +_parse $@