Skip to content

Instantly share code, notes, and snippets.

@kidpixo
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kidpixo/9df8fc3298dfe84dc176 to your computer and use it in GitHub Desktop.
Save kidpixo/9df8fc3298dfe84dc176 to your computer and use it in GitHub Desktop.
This script search for all the lines beginning with '- [X] ' in all the files in a directory, where [X] could be [ ]/[-]/[-]
#!/opt/local/bin/fish
##########################################
# requires ag installed, optionally could
# be adapted to grep for a fewfiles
##########################################
# This script search for all the lines beginning with '- [X] ' in all the files in a directory, where [X] could be:
#[ ] = open item
#[x] = closed item
#[-] = ongoing item
#[?] = question item
# TBD:
#[/] = starting item
#[\] = closing item
#
# The directory must be set in the variable $checklist_path
##########################################
function printout
set graphic $argv[1]
set name $argv[2]
# protect the regex in the search string
if test $graphic = "?"
set search '^[^\h]\h\[\\'$graphic'\]'
else
set search '^[^\h]\h\['$graphic'\]'
end
echo -e "\e[47;1m\e[30;1m$name [$graphic]:\e[0m"
set tmp (ag --nonumbers --nofilename "$search" $checklist_path | sed -e 's/^.\{6\}//' -e '/^$/d')
# avoiding fish issue #159
# [Cannot save multi-line output in a variable](https://github.com/fish-shell/fish-shell/issues/159)
for elem in $tmp
echo -e '\e[1;37m['$graphic']\e[0m '$elem
end
echo -e '\e[1;37m'(count $tmp) $name 'items\e[0m'
echo
end
if test -n $checklist_path
#Ongoing
printout "-" ongoing
#Open
printout " " open
#Closed
printout "x" closed
#Question mark
printout "?" questions
else
echo 'Define the path to search for notes in $checklist_path first'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment