Created
March 9, 2015 10:47
-
-
Save protist/820bb6a25722083a2edd to your computer and use it in GitHub Desktop.
Create a linkified vimwiki tree of the specified directory and subdirectories
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
#!/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. | |
# For the links to make sense, place the output of this script into a file located in this base directory. | |
# Print header | |
echo '= Wiki contents =' | |
echo | |
cd "$1" | |
while 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/')" | |
# Calculate depth of current file, where 1 is current directory. | |
depth=$(( $(<<<"$treetrunk" wc -m ) / 4 )) | |
# Work out path | |
path_array[$depth]="$filename" | |
path_formatted="$(printf "/%s" "${path_array[@]:1:$depth}")" | |
path_formatted="${path_formatted:1}" | |
# Print out line | |
echo -n "$treetrunk" | |
if $(<<<"$filename" grep -q '.wiki$'); then | |
echo "[[${path_formatted%.wiki}|${filename%.wiki}]]" | |
else | |
echo "$filename" | |
fi | |
done <<< "$(tree | head -n -2 | tail -n +2)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment