Commits

Ben Bass committed 32821fd Merge

merge

Comments (0)

Files changed (2)

 
 # Ben Bass 2012 @codedstructure
 
-# Note various things are wrapped in double-quotes to ensure
-# that things with spaces are handled OK.
-
-
-# TODO: maybe 'base secondlevel [option]' is better than 'base [option] secondlevel'
-# except then -s can't work well to determine whether it should make secondlevel
-# or whether secondlevel is the searchterm in something...
-
-# maybe only create secondlevel if not search?
-
 
 EDITFILE_DIR=~/Dropbox/editfile
 mkdir -p $EDITFILE_DIR  # ensure this exists
             # the pattern can be multiple things long...
             shift
             PATTERN="$@"
-            # enumerate editfile notes using compgen. Note this is quite slow...
+            # just search everything under EDITFIlE_DIR
             pushd $EDITFILE_DIR > /dev/null
             find . -type f \( -name \*.txt -o -name \*.rst -o -name \*.md \) -print0 | xargs -0 grep -Hn --color "$PATTERN"
             popd > /dev/null
     echo "  -s <pattern>"
     echo "        search for given pattern"
     echo "  -t    time track mode"
+    echo "  -i    import [FILEPATH]"
+    echo "  -x    export to [FILEPATH.tar]"
     echo " (Note these options are mutually exclusive)"
     echo
     exit 1
     shift
 fi
 
-OPTION_CHARS="alfsth"
+OPTION_CHARS="alfstixh"
 MODE='';
 while getopts "$OPTION_CHARS" option ; do
     case $option in
         's')
             if [[ -z $MODE ]] ; then MODE="SEARCH"; else usage; fi
             ;;
+        'i')
+            if [[ -z $MODE ]] ; then MODE="IMPORT"; else usage; fi
+            ;;
+        'x')
+            if [[ -z $MODE ]] ; then MODE="EXPORT"; else usage; fi
+            ;;
         'h')
             usage
             ;;
 
 shift $(($OPTIND - 1))
 
-# only 'search' can (and must) have additional arguments
-if [[ $MODE != "SEARCH" ]] && [[ -n $1 ]]; then
+# only search/import/export can (and must) have additional arguments
+if ! [[ $MODE =~ SEARCH|IMPORT|EXPORT ]] && [[ -n $1 ]]; then
     echo "Too many arguments: $@"
     echo
     usage
-elif [[ $MODE == "SEARCH" ]] && [[ -z $1 ]]; then
-    echo "Not enough arguments - search option requires pattern"
+elif [[ $MODE =~ SEARCH|IMPORT|EXPORT ]]  && [[ -z $1 ]]; then
+    echo "Not enough arguments - $MODE option requires an argument"
     echo
     usage
 fi
     mkdir -p $TARGET_DIR
     TARGET_PATH="$TARGET_DIR/$CATEGORY"
     HIST_FILE="$TARGET_DIR/.hist.$CATEGORY"
+    ASSETS_PATH="$TARGET_DIR/$CATEGORY.assets"
 else
     # edit the 'main' file
     TARGET_PATH="$EDITFILE_DIR/${MAJOR_NAME}"
     HIST_FILE="$EDITFILE_DIR/.hist.${MAJOR_NAME}"
+    ASSETS_PATH="$TARGET_DIR/${MAJOR_NAME}.assets"
 fi
 
 # support for various extensions.
     'SEARCH')
         grep -n --color "$@" "$TARGET_PATH"
         ;;
+    'IMPORT')
+        mkdir -p "${ASSETS_PATH}"
+        cp "$1" "${ASSETS_PATH}"
+        echo "Imported $1 to ${ASSETS_PATH}"
+        ;;
+    'EXPORT')
+        EXT_PATH=""
+        if test -d ${ASSETS_PATH} ; then
+            EXT_PATH="$(basename ${ASSETS_PATH})"
+        fi
+        (cd "$(dirname ${TARGET_PATH})"; tar -cf "$1" $(basename "$TARGET_PATH") ${EXT_PATH})
+        echo "Exported ${TARGET_PATH} bundle to  $1"
+        ;;
     'TRACK')
         now=$(date '+%Y/%m/%d %H:%M')
         # read history from previous
 exclamation mark simply runs the command; double '!!command' inserts the result
 into the target file.
 
+Storing assets
+--------------
+
+``editfile`` is about reducing the friction in being able to write. No need to
+think about where the document ends up, no need to go through a long startup
+procedure when making a new document. And more. So in writing more, I found
+my next use-case is being able to store non-text data alongside the text.
+
+Ideally I'd like to be able to include a highly efficient DSL which creates
+SVG diagrams in all my documents, but I've not yet found anything ideal;
+blockdiag_ comes close, but I want something which is already *right* in it's
+default styling, and blockdiag isn't that, for me.
+
+.. _blockdiag: http://blockdiag.com
+
+Anyway, sometimes a diagram isn't enough anyway, and I need a photo, or a piece
+of music. Or some other binary file.
+
+Importing a file
+~~~~~~~~~~~~~~~~
+
+    $ blog a-wonderful-blog-post -i ~/photo1.jpg
+    $ blog a-wonderful-blog-post -i ~/photo2.jpg
+
+Exporting bundles
+~~~~~~~~~~~~~~~~~
+
+    $ blog a-wonderful-blog-post -x ~/blog-post.tar
+
+
+Exporting content
+~~~~~~~~~~~~~~~~~
+
 Direct use of 'editfile'
 ------------------------