MyLog.sh

mylog.sh is a simple bash script to maintain and manage a personal, private log, although it also has the option to post entries to a redmatrix channel.

Download:

Installation:

  • run the install.sh

HOW TO USE mylog:

  • mylog - opens a new mylog file to edit in your chosen editor.
  • mylog r - reads all entries (cats all files in the dir, pipes to less)
  • mylog r yyyymmdd - reads entries from date yyyymmdd. One can specify just yyyymm, or just yyyy, even.
  • mylog l - lists all mylog entries. Like r, it can be narrowed down with date parameters.
  • mylog e filename - opens mylog file filename for editing.
  • mylog v filename - opens mylog file filename for viewing.
  • mylog d filename - deletes mylog file filename.
  • mylog s searchterm - searches for searchterm in dream entries.
  • mylog h - displays this help message.

Dependencies:

  • bash
  • vim, emacs, nano, or other terminal editor
  • curl (for redmatrix posting)

Source Code:

You could see this on github, of course, and it might even be more up to date there.

#!/bin/bash
 
#################################
# mylog - by tony baldwin       #
# http://tonybaldwin.me         #
# keeping a personal log        #
# released according to GPL v.3 #
#################################
 
filedate=$(date +%Y%m%d%H%M%S)
 
source  ~/.mylog.conf
cd ~/.mylog
 
if [[ $1 = r ]]; then
	if [[ $2 ]]; then
		cat $2* | less
	else
		for i in $(ls -Rt *.mylog); do cat $i; done | less
	fi
else
if [[ $1 = h ]]; then
	echo "mylog - opens a new mylog file to edit in your editor.
mylog e filename - opens log entry with filename for editing. Must use full filename.
mylog v filename - opens log entry with filename for viewing. Must use full filename.
mylog d filename - delete mylog file with filename.
mylog r - reads all entries (cats all files in the dir, pipes to less)
mylog r yyyymmdd - reads entries from date yyyymmdd. One can specify just yyyymm, or just yyyy, even.
mylog l - lists all mylog entries. Like r, it can be narrowed down with date parameters.
mylog s searchterm - searches for searchterm in my entries.
mylog h - displays this help message.
mylog management system by tony baldwin, http://tonybaldwin.me, released according to GPL v. 3"
 
else
if [[ $1 = l ]]; then
	if [[ $2 ]]; then
		ls -1t | grep $2
	else
		ls -1t
	fi
else
if [[ $1 = d ]]; then
	read -p "Are you certain you wish to delete $2? " dr
	if [[ $dr = y ]]; then
		rm $2
	else
		exit
	fi
else
if [[ $1 = v ]]; then
	less $2
else
if [[ $1 = e ]]; then
	$editor $2
else
if [[ $1 = s ]]; then
	grep -iw $2 *
 
else
	date=`date`
	echo -e "\n$date\n\nWRITE HERE\n\n-------------------" > $filedate.mylog
	$editor $filedate.mylog
	if [[ $rplug = y ]]; then
		read -p "Post to my redmatrix? (y/n) " post
		if [[ $post = y ]]; then
			read -p "which channel? " chan
			read -p "Will we be crossposting?  (y/n) " xpo
			if [[ $xpo == "y" ]]; then
				read -p "xpost to friendica? (auto to pump/ltree) (y/n) " fxq
				if [[ $fxq == "y" ]]; then
				fx=1
				fi
				read -p "xpost to pumpio? (y/n) " ppx
				if [[ $ppx == "y" ]]; then
				pp=1
				 fi
				read -p "xpost to wordpress? (y/n) " wpp
				if [[ $wpp == "y" ]]; then
				wp=1
				fi
				read -p "xpost to livejournal? (y/n) " ljp
				if [[ $ljp == "y" ]]; then
				lj=1
				fi
				read -p "xpost to insanejournal? (y/n) " ijp
				if [[ $ijp == "y" ]]; then
				ij=1
				fi
				read -p "xpost to dreamwidth? (y/n) " dwp
				if [[ $dwp == "y" ]]; then
				dw=1
				fi
				read -p "xpost to libertree? (y/n) " ltp
				if [[ $ltp == "y" ]]; then
				lt=1
				fi
				read -p "xpost to statusnet? (y/n) " snp
				if [[ $snp == "y" ]]; then
				sn=1
		else	
			let fx=pp=wp=ij=lj=dw=lt=sn=0
		fi
		echo -e "\nposted with mylog - https://github.com/tonybaldwin/mylog\n--\n" >> ~/.mylog/$filedate.my
		ud="$(cat ~/.mylog/$filedate.mylog)"
# and this is the curl command that sends the update to the server
 
		if [[ $(curl --ssl -u $ruser:$rpass -d "status=$ud&title=$title&channel=$chan&category=$cats&rtof_enable=$fx&pumpio_enable=$pp&ljpost_enable=$lj&ijpost_enable=$ij&dwpost_enable=$dw&wppost_enable=$wp&libertree_enable=$lt&statusnet_enable=$sn&app=reddi.sh" $rurl/api/statuses/update.xml | grep error) ]]; then
			echo "Error!"
			exit
		else 
			echo "Success!"
		read -p "Shall we have a look in your browser now? (y/n): " op
			if [ $op = "y" ]; then
			xdg-open $rurl/channel/$chan
			fi
		fi
	fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
exit

Tony Baldwin 2015/01/20 02:27