Skip to content

Instantly share code, notes, and snippets.

@neeasade
Created March 19, 2018 12:19
Show Gist options
  • Save neeasade/5dbadb84b04c33885bc4fee50612ec5f to your computer and use it in GitHub Desktop.
Save neeasade/5dbadb84b04c33885bc4fee50612ec5f to your computer and use it in GitHub Desktop.
org-pomoro music hook and display workflow
#!/bin/sh
result="$(emacsclient --eval "(progn $@)")"
if [ "$result" = "nil" ] || [ -z "$result" ]; then
exit 1
else
echo "$result"
exit 0
fi
#!/bin/sh
# usage: mkb ${percent}
# port of http://git.z3bra.org/mkb/file/mkb.c.html
# args
progress="$1"
size="$2"
char1="$3"
char2="$4"
sep="$5"
start="$6"
end="$7"
# defaults
progress=${progress:-30}
size=${size:-32}
char1="${char1:-━}"
char2="${char2:-━}"
sep="${sep:-╋}"
start="${start:-}"
end="${end:-}"
# some ideas
#char1="◼" sep="◼" char2="◻"
#char1="▰" sep="▰" char2="▱"
passed=false
content="${start}"
content="${content}${start}"
for i in $(seq 1 $size); do
if [ "$(echo "$i < $progress / 100 * $size" | bc -l)" = 1 ]; then
current="$char1"
else
$passed && current="$char2" || current="$sep"
passed=true
fi
content="${content}${current}"
done
content="${content}${end}"
echo "$content"
(use-package org-pomodoro
:config
(defun neeasade/toggle-music(action)
(let ((command (concat "mpc " action)))
(shell-command command)
))
(add-hook 'org-pomodoro-started-hook
(apply-partially #'neeasade/toggle-music "play"))
(add-hook 'org-pomodoro-break-finished-hook
(apply-partially #'neeasade/toggle-music "play"))
(add-hook 'org-pomodoro-finished-hook
(apply-partially #'neeasade/toggle-music "pause"))
)
#!/bin/sh
# show status of org-pomodoro in a progress bar.
# tied to mpd, toggles on when working, off on break
calc() {
echo "$*" | bc -l
}
time_offset_percent() {
duration="$1" # minutes
interval="$(calc ${duration} \* 60)"
time_left="$(elisp '(format-time-string "%s" (org-pomodoro-remaining-seconds))' | tr -d '"')"
percent="$(calc "((${interval} - ${time_left}) / ${interval}) * 100" | sed 's/\..*//')"
percent=${percent:-0}
echo "${percent}"
}
progress() {
mkb "$(time_offset_percent "$1")" 10 ◼ ◻ ◻
}
get_length() {
elisp "org-pomodoro-${@}length"
}
pomodoro_state="$(elisp org-pomodoro-state)"
case ${pomodoro_state} in
:short-break)
echo "Break $(progress $(get_length short-break-))"
;;
:long-break)
echo "Long break $(progress $(get_length long-break-))"
;;
:pomodoro)
task="$(elisp org-clock-current-task | tr -d '"')"
echo "${task} $(progress $(get_length))"
;;
:none)
echo "Pick a task!"
;;
*)
echo "No Task!"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment