Last active
March 3, 2019 06:53
-
-
Save sbrow/e46689cd1dcd71d4ec14216d599d5a55 to your computer and use it in GitHub Desktop.
Crawler script for BuJo
This file contains hidden or 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
#!/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}/" |
This file contains hidden or 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
#!/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 | |
} |
This file contains hidden or 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
#!/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