Last active
July 26, 2018 16:15
-
-
Save ZaWertun/5e2bc5185c22162a2409ef87fdb7cf76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Code::Stats script for fish shell | |
# This code fragment must be placed in ~/.config/fish/config.fish | |
# License: MIT | |
if status is-interactive | |
set -g __code_stats_xp 0 | |
set -g __code_stats_last (date +%s) | |
set -g __code_stats_version 0.1.0 | |
function __code_stats_pulse -e __code_stats_event -p %self | |
if not set -q __code_stats_key; or test $__code_stats_xp -eq 0 | |
return 1 | |
end | |
curl \ | |
--header "Content-Type: application/json" \ | |
--header "X-API-Token: $__code_stats_key" \ | |
--user-agent "code-stats-fish/$__code_stats_version" \ | |
--data "{\"coded_at\":\""(date +%Y-%m-%dT%H:%M:%S%z)"\",\"xps\":[{\"language\":\"Terminal (fish)\",\"xp\":$__code_stats_xp}]}" \ | |
--request POST \ | |
--silent \ | |
--output /dev/null \ | |
https://codestats.net/api/my/pulses & | |
disown | |
set -g __code_stats_xp 0 | |
set -g __code_stats_last (date +%s) | |
end | |
function __code_stats_gather --on-event fish_postexec | |
if set -q __code_stats_fatal | |
return 1 | |
end | |
if not set -q __code_stats_key | |
set -g __code_stats_fatal 1 | |
echo "Code::Stats script error: variable `__code_stats_key` is not set." | |
echo "Example: set -Ux __code_stats_key abc...xyz" | |
return 1 | |
end | |
set -l length (string length $argv) | |
if test $length -gt 0 | |
set -g __code_stats_xp (math $__code_stats_xp + $length) | |
end | |
if test (math \((date +%s) - $__code_stats_last\) / 60) -ge 10 | |
emit __code_stats_event | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment