hb

Log | Files | Refs | README | LICENSE

commit 62d37548ecae4def64f6649fa5481349427194cc
Author: Bharatvaj <bharatvaj@yahoo.com>
Date:   Wed,  6 Oct 2021 14:20:37 +0530

Initial Commit

Diffstat:
ACOPYING | 6++++++
AREADME | 38++++++++++++++++++++++++++++++++++++++
Ainstall | 10++++++++++
Anb | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Anb.1 | 49+++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 162 insertions(+), 0 deletions(-)

diff --git a/COPYING b/COPYING @@ -0,0 +1,6 @@ +nb is in the public domain. + +To the extent possible under law, Bharatvaj <bharatvaj@getsh.org> +has waived all copyright and related or neighboring rights to this work. + +http://creativecommons.org/publicdomain/zero/1.0/ diff --git a/README b/README @@ -0,0 +1,38 @@ + +NB(1) BSD General Commands Manual NB(1) + +NAME + nb -- simple notebook manager + +SYNOPSIS + nb [n|new] file_name.md + nb [s|sync] + +DESCRIPTION + The nb provides a lightweight interface for accessing and adding notes on + command line. + + nb doesn't complain much and tries to work with what is available. + fzf(1) is used for fuzzy searching and it is launched by default if no + options are given. + + In the case of fzf unavailability, nb simply changes directory to NB_PATH + + If [sync] option is used, nb attempts a add/commit/push cycle on NB_PATH + via git(1) + +ENVIRONMENT + NB_PATH The location of your notebook folder. + +AUTHORS + Bharatvaj <bharatvaj@getsh.org> + +LICENSE + nb is in the public domain. + + To the extent possible under law, the creator of this work has waived all + copyright and related or neighboring rights to this work. + + http://creativecommons.org/publicdomain/zero/1.0/ + +BSD October 06, 2021 BSD diff --git a/install b/install @@ -0,0 +1,10 @@ +#!/bin/sh + +DESTDIR= +PREFIX="${DESTDIR}/usr/local" +BINDIR="${PREFIX}/bin" +MANDIR="${PREFIX}/share/man" + +mkdir -p "${BINDIR}" "${MANDIR}/man1" +install -m0755 nb "${BINDIR}" +install -m0644 nb.1 "${MANDIR}/man1" diff --git a/nb b/nb @@ -0,0 +1,59 @@ +#!/bin/sh + +# nb - simple notebook manager + +nb_fatal_error() { + echo "nb: $1" + exit 1 +} + +nb_browse() { + file="$(fzf)" + [ "${file}" != "" ] && ${EDITOR} "${file}" +} + +nb_sync() { + which git >/dev/null 2>/dev/null || nb_fatal_error "git not available, cannot sync" + git fetch + git add "${NB_PATH}" + git commit -m "$(uname -a)" + git pull + #TODO check for conflicts + # if conflict exists, checkout to a + # different unique branch + # And pull after fetch seems + # redundant, replace with merge + git push +} + +nb_new() { + [ -n "$1" ] || nb_fatal_error "usage: nb new <file_name>" + ${EDITOR} "${NB_PATH}/$1" +} + +nb_usage() { + [ -n "$1" ] && echo "nb: unknown command $1" + printf "Usage: nb [OPTIONS] + n, new Opens a file in the NB_PATH directory with EDITOR + s, sync Attempts a add/commit/push cycle in NB_PATH + h, help Prints this help message +" +} + +test -z "${EDITOR}" && export EDITOR=vi +#TODO if vi is not found, cat the note + +#TODO ask user to clone repo +# if folder does not exist +cd "${NB_PATH}" || nb_fatal_error "NB_PATH is not a directory" +nb_option=${1} +shift; +case $nb_option in + #TODO pass params to nb_browse + '')nb_browse ;; + #TODO strip $1 + n|new) nb_new "$@" ;; + s|sync) nb_sync ;; + h|help) nb_usage ;; + *) nb_usage "$@" ;; +esac diff --git a/nb.1 b/nb.1 @@ -0,0 +1,49 @@ +.Dd October 06, 2021 +.Dt NB 1 +.Os +.Sh NAME +.Nm nb +.Nd simple notebook manager +.Sh SYNOPSIS +.Nm +.Op n|new +.Ar file_name.md +.Nm +.Op s|sync +.Sh DESCRIPTION +The +.Nm +provides a lightweight interface for accessing and adding notes on command line. +.Pp +.Nm +doesn't complain much and tries to work with what is available. +.Xr fzf 1 +is used for fuzzy searching and it is launched by default if no options are given. +.Pp +In the case of fzf unavailability, +.Nm +simply changes directory to NB_PATH +.Pp +If +.Op sync +option is used, +.Nm +attempts a add/commit/push cycle on NB_PATH via +.Xr git 1 +.Sh ENVIRONMENT +.Bl -hang -width "NB_PATH" +.It Ev NB_PATH +The location of your notebook folder. +.El +.Sh AUTHORS +.An Bharatvaj Aq Mt bharatvaj@getsh.org +.Sh LICENSE +.Nm +is in the public domain. +.Pp +To the extent possible under law, +the creator of this work +has waived all copyright and related or +neighboring rights to this work. +.Pp +.Lk http://creativecommons.org/publicdomain/zero/1.0/