Open
Description
I wrote a basic plugin for locally sharing notes; it's nothing fancy. It creates a temp file with the note content and then serves it through HTTP using netcat
.
Code Here
#!/usr/bin/env bash
###############################################################################
# share
#
# A plugin for `nb`
#
# Author: rooyca (https://github.com/rooyca)
###############################################################################
_subcommands add "share"
_subcommands describe "share" <<HEREDOC
Usage:
nb share <ID>
Description:
Share your notes locally.
Examples:
nb share 101
HEREDOC
# Define the port to listen on
PORT=8833
TEMP_FILE_NAME="/tmp/nb-share-temp.txt"
_share() {
local _selector="${1:-}"
[[ -z "${_selector:-}" ]] && printf "Usage: share <selector>\\n" && exit 1
local content
content=$(_show "$_selector" --print | sed 's/\x1b\[[0-9;]*[a-zA-Z]//g')
# save content to a tmp file
echo "$content" > $TEMP_FILE_NAME
# Start a simple HTTP server to share the content
while true; do
{
echo -ne "HTTP/1.1 200 OK\r\n"
echo -ne "Content-Type: text/plain\r\n\r\n"
cat $TEMP_FILE_NAME
} | nc -l -p "$PORT" -q 1
done
}
I was wondering if something like this could be implemented natively?
P.S. Thank you so much for this awesome tool.
Metadata
Metadata
Assignees
Labels
No labels