monochromatic

monochromatic blog: http://blog.z3bra.org
git clone git://z3bra.org/monochromatic
Log | Files | Refs

post.sh (807B)


      1 #!/bin/sh
      2 
      3 # Ask the user for a title
      4 if [ $# -lt 1 ]; then
      5 	printf "Post title: "
      6 	read title
      7 else
      8 	title="$@"
      9 fi
     10 
     11 # use post title to name the file
     12 file=`echo ${title}| tr -d ",.?!;\"'" | tr -s ' ' | tr 'A-Z ' 'a-z-' | sed "s/-*$//"`.txt
     13 
     14 test -z "$file" && exit 1
     15 
     16 #date format for the post
     17 date=`date +"%d %B, %Y"`
     18 
     19 # The format of the path to the post, here: /yyyy/mm/
     20 folder=`date +%Y/%m`
     21 
     22 # create the path if it does not exists
     23 test -d ${folder} || mkdir -p ${folder}
     24 
     25 # build the whole path
     26 post="${folder}/${file}"
     27 
     28 # create the file
     29 cat <<EOF > ${post}
     30 # [${title}](#)
     31 ## &mdash; ${date}
     32 
     33 EOF
     34 
     35 if ! test -f ${post}; then
     36     echo "cannot create ${post}"
     37     exit 1
     38 fi
     39 
     40 echo "$post created (symlinked to last.txt)"
     41 
     42 # create a symlink to the last post, to easily access it
     43 ln -fs ${post} last.txt