Skip to content

Instantly share code, notes, and snippets.

@fzenke
Last active August 26, 2016 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fzenke/88559589d9e394bdc3a886d00a2880c4 to your computer and use it in GitHub Desktop.
Save fzenke/88559589d9e394bdc3a886d00a2880c4 to your computer and use it in GitHub Desktop.
cmdnotes: Small bash extension scripts to take notes on the command line
#!/bin/bash
# cnote -- Shell extension scripts to take notes on the command line
# Source this file from .bashrc or your shell init script to enable command line notes
# Usage:
# To create and edit a note
# $ cnew <notename>
# To list all notes containing <regexp> in their title
# $ cnls <regexp>
# To trash a note
# $ cnrm <notename>
# The editor you want to use
# this might be set already in your .bashrc
# export EDITOR=/usr/bin/vim
# set this to any path were you want to keep the notes
CNOTEDIR="$HOME/ownCloud/appData/cnote"
cnote() {
PARAM=`basename $1`
CNOTENAME=$PARAM
DATETIME=`date +"%y-%m-%d_%H:%M"`
if [[ -z $PARAM ]]
then
CNOTENAME="note_$DATETIME"
fi
CNOTEPATH="$CNOTEDIR/$CNOTENAME.txt"
if [[ ! -a $CNOTEPATH ]]
then
echo "note created $DATETIME" > $CNOTEPATH
fi
$EDITOR $CNOTEPATH
}
cnls() {
ls -c $CNOTEDIR/*.txt | xargs -n1 basename | grep "$*" | sed 's/\.txt$//g'
}
cnrm() {
mkdir -p $CNOTEDIR/trash
PARAM=`basename $1`
CNOTENAME=$PARAM
CNOTEPATH="$CNOTEDIR/$CNOTENAME.txt"
mv -f $CNOTEPATH $CNOTEDIR/trash/
}
cnpurge() {
rm -f $CNOTEDIR/trash/*.txt
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment