Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Sharing notes locally #323

Open
Rooyca opened this issue Jun 22, 2024 · 0 comments
Open

[Feature Request] Sharing notes locally #323

Rooyca opened this issue Jun 22, 2024 · 0 comments

Comments

@Rooyca
Copy link
Contributor

Rooyca commented Jun 22, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant