Skip to content

Instantly share code, notes, and snippets.

@sbrow
Last active March 3, 2019 06:53
Show Gist options
  • Save sbrow/e46689cd1dcd71d4ec14216d599d5a55 to your computer and use it in GitHub Desktop.
Save sbrow/e46689cd1dcd71d4ec14216d599d5a55 to your computer and use it in GitHub Desktop.
Crawler script for BuJo
#!/bin/bash
source $(dirname "${BASH_SOURCE[0]}")/crawler
if [[ -n $1 ]]; then
GLOB=("$@")
fi
SED='sed'
if [[ "$(uname)" == "Darwin" ]]; then
SED='gsed';
fi
bold=$(tput bold)
normal=$(tput sgr0)
Init "/tmp/crawler"
Crawler 'Notes' '^\#*[\ \t]*- [^[]*$'
Crawler 'Events' '^\#*\s*o'
Crawler 'Tasks' '\[[\ xX<^>/:-]\] '
echo "* * *" >> $OUT
Crawler 'Eliminated' '\[-\] '
Crawler 'Duplicate' '\[:\] '
Crawler 'Delegated' '\[/\] '
Crawler 'Migrated' '\[>\] '
Crawler 'Scheduled' '\[<\] '
Crawler 'Exported' '\[^\] '
Crawler 'Completed' '\[[xX]\] '
Crawler 'Incomplete' '\[\ \] '
bold_words='Tasks|Total|Events|Notes|[=-]+'
column -t -s "," $OUT | $SED -r "s/($bold_words)/${bold}\1${normal}/"
#!/bin/bash
OUT="tmp/crawler"
GLOB=(*)
# init sets up our outfile.
function Init() {
OUT=$1
# echo $(pwd) >> $OUT
echo "name,#" > $OUT
}
# Crawler searches glob $GLOB for regex $2
# and prints the number of hits to $OUT
# with label $1.
function Crawler() {
local name=$1
local reg=$2
local n=0
inc=$(grep -r "$reg" "${GLOB[@]}" | wc -l)
n=$((n+inc))
if (( $# >= 3 )); then
grep "$reg" "${GLOB[@]}"
fi
echo "$name,$n" >> $OUT
}
#!/bin/bash
sudo ln -s ./bjstat /usr/bin/bjstat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment