From a372c2568efb7bf474b0026d9c81c76e095097e0 Mon Sep 17 00:00:00 2001 From: protist Date: Thu, 14 May 2015 23:30:31 +1000 Subject: [PATCH 1/4] Correct typo from vmtree to vwtree vwtree stands for VimWikiTREE. --- vmtree.sh => vwtree.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename vmtree.sh => vwtree.sh (100%) diff --git a/vmtree.sh b/vwtree.sh similarity index 100% rename from vmtree.sh rename to vwtree.sh From f40fe32ce1d5c06213d698ca9a0eb47d7a3da5c9 Mon Sep 17 00:00:00 2001 From: protist Date: Thu, 14 May 2015 23:35:21 +1000 Subject: [PATCH 2/4] =?UTF-8?q?Allow=20files=20with=20=E2=94=80=E2=94=80?= =?UTF-8?q?=20in=20their=20name;=20minor=20clean=20up?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use perl's non-greedy regex to allow files with ── in their name. * Remove extraneous newline after title. * Clarify that users can run command with no argument; script will run in the current directory. --- vwtree.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/vwtree.sh b/vwtree.sh index 2523ca0..a4bf98f 100755 --- a/vwtree.sh +++ b/vwtree.sh @@ -1,18 +1,19 @@ #!/usr/bin/env bash # Create a linkified vimwiki tree of the specified directory and subdirectories. -# It takes one argument: the base directory of the vimwiki. +# It takes one optional argument: the base directory of the vimwiki. +# Otherwise, the current directory is assumed to be the base directory. # For the links to make sense, save the output of this script into a file located in this base directory. -# This script requires `tree` to be installed. +# This script requires `tree` and `perl` to be installed. + +cd "$1" # If there is no argument supplied, this will not change the current directory. # Print header echo '= Table of contents =' -echo -cd "$1" while IFS='' read -r line; do - # Assuming there are no files with ── in their name. - filename="$(<<<"$line" sed -r 's/.*── (.*)/\1/' )" - treetrunk="$(<<<"$line" sed -r 's/(.*── ).*/\1/')" + # Use perl regex in case there are files with ── in their name. + filename="$(<<<"$line" perl -pe 's/.*?── (.*)/\1/' )" + treetrunk="$(<<<"$line" perl -pe 's/(.*?── ).*/\1/')" # Calculate depth of current file, where 1 is current directory. depth=$(( $(<<<"$treetrunk" wc -m ) / 4 )) From 9b389d415aa3420ad52084df0d942f8489048c3c Mon Sep 17 00:00:00 2001 From: protist Date: Thu, 14 May 2015 23:41:02 +1000 Subject: [PATCH 3/4] Print un-checked todo items Print one todo item per line in wiki format with linked page. Print at the top of the output file, with the contents following. --- vwtree.sh | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/vwtree.sh b/vwtree.sh index a4bf98f..93b0c8a 100755 --- a/vwtree.sh +++ b/vwtree.sh @@ -7,7 +7,29 @@ cd "$1" # If there is no argument supplied, this will not change the current directory. -# Print header +# Print todo header +echo '= Todo items =' + +# If a todo item is found, print the relevant information. +function print_matches() { + todo_pattern='^\s*[*-] \[ \]' + if grep -q "$todo_pattern" "$1"; then + matches="$(grep "$todo_pattern" "$1")" + # Format page_name for vimwiki syntax, i.e. no leading `./` or trailing `.wiki` + page_name="$(echo $1 | sed -r 's/^.\/(.*).wiki/\1/')" + # Escape literal slashes, otherwise the next sed will choke. + escaped_page_name="$(echo "$page_name" | sed 's,/,\\/,g')" + printf %s "$matches" | sed "s/^/* [[${escaped_page_name}]]: /" + echo + fi +} + +# Search for todo items +export -f print_matches +find . -name '*.wiki' -exec bash -c 'print_matches "$0"' {} \; +echo + +# Print contents header echo '= Table of contents =' while IFS='' read -r line; do From 439a5711431f6b0689c9eb1c413af2dbe5ffda79 Mon Sep 17 00:00:00 2001 From: protist Date: Fri, 15 May 2015 23:58:04 +1000 Subject: [PATCH 4/4] Add option to print one section, add usage, copyedit * Use -t to only print todo items; -c to only print table of contents. * Print usage with -h or error in options. * Fix header comments. * Minor grammar fixes. --- vwtree.sh | 138 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 88 insertions(+), 50 deletions(-) mode change 100755 => 100644 vwtree.sh diff --git a/vwtree.sh b/vwtree.sh old mode 100755 new mode 100644 index 93b0c8a..641a3c8 --- a/vwtree.sh +++ b/vwtree.sh @@ -1,55 +1,93 @@ #!/usr/bin/env bash -# Create a linkified vimwiki tree of the specified directory and subdirectories. -# It takes one optional argument: the base directory of the vimwiki. -# Otherwise, the current directory is assumed to be the base directory. -# For the links to make sense, save the output of this script into a file located in this base directory. +# Create a linkified vimwiki file of unchecked todo items and a tree of the specified directory and +# subdirectories. For the links to make sense, save the output of this script into a file located +# in this base directory. # This script requires `tree` and `perl` to be installed. -cd "$1" # If there is no argument supplied, this will not change the current directory. - -# Print todo header -echo '= Todo items =' - -# If a todo item is found, print the relevant information. -function print_matches() { - todo_pattern='^\s*[*-] \[ \]' - if grep -q "$todo_pattern" "$1"; then - matches="$(grep "$todo_pattern" "$1")" - # Format page_name for vimwiki syntax, i.e. no leading `./` or trailing `.wiki` - page_name="$(echo $1 | sed -r 's/^.\/(.*).wiki/\1/')" - # Escape literal slashes, otherwise the next sed will choke. - escaped_page_name="$(echo "$page_name" | sed 's,/,\\/,g')" - printf %s "$matches" | sed "s/^/* [[${escaped_page_name}]]: /" - echo - fi +# Define usage. +usage() { + cat <