hb

Log | Files | Refs | README | LICENSE

commit 46fd684ad9362c0187173617939ce5a03ec0bc87
parent e48e293e20f34ccb496da986b929328df5f4d7fb
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date:   Mon, 12 Aug 2024 22:01:35 +0530

Rename nb to hb due to name conflicts

Diffstat:
MCOPYING | 2+-
Ahb | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ahb.1 | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Dnb | 99-------------------------------------------------------------------------------
Dnb.1 | 49-------------------------------------------------
Mtest | 10+++++-----
6 files changed, 154 insertions(+), 154 deletions(-)

diff --git a/COPYING b/COPYING @@ -1,4 +1,4 @@ -nb is in the public domain. +hb 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. diff --git a/hb b/hb @@ -0,0 +1,99 @@ +#!/bin/sh + +# hb - simple notebook manager + +hb_fatal_error() { + echo "hb: " + while [ $# -gt 0 ]; do echo "$1"; shift; done + exit 1 +} + +hb_browse() { + cd "${HB_PATH}" + file="$(find . -name '.git*' -prune -o -type f | cut -d"/" -f2- | ${FUZZER})" + [ "${file}" != "" ] && { + echo "${file}" >> ${HB_HIST} + ${EDITOR} "${file}"; + } +} + +hb_recent() { + cd "${HB_PATH}" + if [ -f "${HB_HIST}" ]; then + file="$(cat "${HB_HIST}" | tail -n 1)" + test -f "${file}" && { + ${EDITOR} "${file}"; + exit 0; + } + fi + hb_fatal_error "No recent history" +} + +hb_sync() { + which git >/dev/null 2>/dev/null || hb_fatal_error "git not available, cannot sync" + cd "${HB_PATH}" + git fetch + git add "${HB_PATH}" + if [ -n "$1" ]; then + git commit -m "$1" + else + git commit -m "$(uname)" + fi + 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 +} + +hb_new() { + [ -n "$1" ] || hb_fatal_error "usage: hb new < <-c|-m> files... | filename >" + if [ $# -gt 1 ]; then case "$1" in + -c) shift; cp -v "$@" "$HB_PATH/" ;; + -m) shift; mv -v "$@" "$HB_PATH/" ;; + *) [ -n "$1" ] && hb_fatal_error "unknown command -- $@" "usage: hb new <-c|-m> files..." ;; + esac; fi + [ $? -ne 0 ] && exit 1; + if ${EDITOR} "${HB_PATH}/$1"; then + echo "${file}" >> "${HB_HIST}" + fi +} + +hb_usage() { + [ -n "$1" ] && echo "$0: Unknown command $1" + printf 'Usage: hb [OPTIONS] + n, new < <-c|-m> files... | filetocreate > + Creates filetocreate in $HB_PATH directory with $EDITOR + if -c option, files are copied to $HB_PATH + if -m option, files are moved to $HB_PATH + s, sync [ "message" ] + Attempts a pull/commit/push cycle in $HB_PATH + if "message" is present, commit with "message" + r, recent Open the last file that was accessed + h, help Prints this help message +' +} + +test -z "${EDITOR}" && { export EDITOR=vi; } +# TODO detect windows, type on windows invokes a different command +which "${EDITOR}" >/dev/null 2>/dev/null || { export EDITOR=cat; } +XDG_DATA_HOME="${XDG_DATA_HOME:=$HOME}" +HB_PATH="${HB_PATH:=$XDG_DATA_HOME/notes}" + +: ${XDG_DATA_HOME:=$HOME/.local/share} +: ${HB_PATH:=$XDG_DATA_HOME/notes} +: ${HB_HIST:="$HB_PATH/.hbhistory"} + +test -d "${HB_PATH}" || { hb_fatal_error "HB_PATH: ${HB_PATH} is not a directory"; exit 1; } +hb_option=${1} +[ $# -ge 1 ] && shift +case $hb_option in + '') hb_browse ;; + n|new) hb_new "$@" ;; + s|sync) hb_sync "$@" ;; + r|recent) hb_recent ;; + h|help) hb_usage ;; + *) hb_usage "$@" ;; +esac diff --git a/hb.1 b/hb.1 @@ -0,0 +1,49 @@ +.Dd October 06, 2021 +.Dt HB 1 +.Os +.Sh NAME +.Nm hb +.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 HB_PATH +.Pp +If +.Op sync +option is used, +.Nm +attempts a add/commit/push cycle on HB_PATH via +.Xr git 1 +.Sh ENVIRONMENT +.Bl -hang -width "HB_PATH" +.It Ev HB_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/ diff --git a/nb b/nb @@ -1,99 +0,0 @@ -#!/bin/sh - -# nb - simple notebook manager - -nb_fatal_error() { - echo "nb: " - while [ $# -gt 0 ]; do echo "$1"; shift; done - exit 1 -} - -nb_browse() { - cd "${NB_PATH}" - file="$(find . -name '.git*' -prune -o -type f | cut -d"/" -f2- | ${FUZZER})" - [ "${file}" != "" ] && { - echo "${file}" >> ${NB_HIST} - ${EDITOR} "${file}"; - } -} - -nb_recent() { - cd "${NB_PATH}" - if [ -f "${NB_HIST}" ]; then - file="$(cat "${NB_HIST}" | tail -n 1)" - test -f "${file}" && { - ${EDITOR} "${file}"; - exit 0; - } - fi - nb_fatal_error "No recent history" -} - -nb_sync() { - which git >/dev/null 2>/dev/null || nb_fatal_error "git not available, cannot sync" - cd "${NB_PATH}" - git fetch - git add "${NB_PATH}" - if [ -n "$1" ]; then - git commit -m "$1" - else - git commit -m "$(uname)" - fi - 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 < <-c|-m> files... | filename >" - if [ $# -gt 1 ]; then case "$1" in - -c) shift; cp -v "$@" "$NB_PATH/" ;; - -m) shift; mv -v "$@" "$NB_PATH/" ;; - *) [ -n "$1" ] && nb_fatal_error "unknown command -- $@" "usage: nb new <-c|-m> files..." ;; - esac; fi - [ $? -ne 0 ] && exit 1; - if ${EDITOR} "${NB_PATH}/$1"; then - echo "${file}" >> "${NB_HIST}" - fi -} - -nb_usage() { - [ -n "$1" ] && echo "$0: Unknown command $1" - printf 'Usage: nb [OPTIONS] - n, new < <-c|-m> files... | filetocreate > - Creates filetocreate in $NB_PATH directory with $EDITOR - if -c option, files are copied to $NB_PATH - if -m option, files are moved to $NB_PATH - s, sync [ "message" ] - Attempts a pull/commit/push cycle in $NB_PATH - if "message" is present, commit with "message" - r, recent Open the last file that was accessed - h, help Prints this help message -' -} - -test -z "${EDITOR}" && { export EDITOR=vi; } -# TODO detect windows, type on windows invokes a different command -which "${EDITOR}" >/dev/null 2>/dev/null || { export EDITOR=cat; } -XDG_DATA_HOME="${XDG_DATA_HOME:=$HOME}" -NB_PATH="${NB_PATH:=$XDG_DATA_HOME/notes}" - -: ${XDG_DATA_HOME:=$HOME/.local/share} -: ${NB_PATH:=$XDG_DATA_HOME/notes} -: ${NB_HIST:="$NB_PATH/.nbhistory"} - -test -d "${NB_PATH}" || { nb_fatal_error "NB_PATH: ${NB_PATH} is not a directory"; exit 1; } -nb_option=${1} -[ $# -ge 1 ] && shift -case $nb_option in - '') nb_browse ;; - n|new) nb_new "$@" ;; - s|sync) nb_sync "$@" ;; - r|recent) nb_recent ;; - h|help) nb_usage ;; - *) nb_usage "$@" ;; -esac diff --git a/nb.1 b/nb.1 @@ -1,49 +0,0 @@ -.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/ diff --git a/test b/test @@ -2,17 +2,17 @@ logfile=test.log -export NB_PATH=sample +export HB_PATH=sample export EDITOR=ls export FUZZER="xargs" -test_browse() { FUZZER="echo good_file.txt" ./nb; } +test_browse() { FUZZER="echo good_file.txt" ./hb; } -test_browsefail() { ! FUZZER="echo bad_file.txt" ./nb; } +test_browsefail() { ! FUZZER="echo bad_file.txt" ./hb; } -test_nonexistentfile() { ! ./nb n -c nonexistentfile; } +test_nonexistentfile() { ! ./hb n -c nonexistentfile; } -test_existentfile() { ./nb n -c COPYING; } +test_existentfile() { ./hb n -c COPYING; } set -- browse browsefail nonexistentfile existentfile date +"==========[%Y/%m/%d %H:%M:%S]==========" >> $logfile