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

Flag --edit locks nb systemwide until editor is closed #281

Open
eblume opened this issue Oct 16, 2023 · 3 comments
Open

Flag --edit locks nb systemwide until editor is closed #281

eblume opened this issue Oct 16, 2023 · 3 comments

Comments

@eblume
Copy link

eblume commented Oct 16, 2023

I have noticed that using nb add or nb edit with the --edit flag causes nb to stop responding to any further requests until the editor session is closed.

I was able to rectify this in my scripts by doing add/edit command with it's relevant --content section first, and then separately executing nb open to open the editor to the file, but I wonder if this is a bug or something that can be fixed? I understand the issue is probably related to the git usage pattern, maybe you can help me make sense of the workflow I should use instead.

Here was the pre-workaround version of my function:

function my_log() {
  # Use nb to add a diary entry. If it's the first entry of the day, use a full date line, otherwise use an abbreviated
  # one.
  long_form_date=$(date '+%A, %B %d, %Y')
  short_form_date=$(date '+%H:%M')
  calendar_date=$(date '+%Y-%m-%d')
  shortmsg=$'\n'"$@"
  edit=$(if [ $# -eq 0 ]; then echo "--edit"; else echo ""; fi)
  entries=$(nb list --type=log.md "${calendar_date}.log.md")
  if [ $? -eq 0 ]; then
    # entries WERE found, so use nb edit
    nb edit "${calendar_date}.log.md" --content "## ${short_form_date}${shortmsg}" $edit
  else
    # entries were NOT found, so use nb add
    nb add "${calendar_date}.log.md" --title "${long_form_date}" --content "## ${short_form_date}${shortmsg}" --type=log.md $edit
  fi
}

Here is the workaround function:

function my_log() {
  # Use nb to add a diary entry. If it's the first entry of the day, use a full date line, otherwise use an abbreviated
  # one.
  long_form_date=$(date '+%A, %B %d, %Y')
  short_form_date=$(date '+%H:%M')
  calendar_date=$(date '+%Y-%m-%d')
  shortmsg=$'\n'"$*"

  # First, create all preamble for this entry including the file itself if needed
  entries=$(nb list --type=log.md "${calendar_date}.log.md")
  if [ $? -eq 0 ]; then
    # entries were found, so use nb edit
    nb edit "${calendar_date}.log.md" --content "## ${short_form_date}${shortmsg}"
  else
    # entries were NOT found, so use nb add
    nb add "${calendar_date}.log.md" --title "${long_form_date}" --content "## ${short_form_date}${shortmsg}" --type=log.md
  fi

  # If no args were passed, open the file in the editor
  if [ $# -eq 0 ]; then
    # Why do this and not just use --edit? Because --edit _locks nb systemwide_.
    nb open "${calendar_date}.log.md"
  fi
}

I'm sure there's something I'm not quite getting here, but I'm currently unblocked with my workaround so please of course feel free to close this issue if there's nothing to track on your end.

@voxelv
Copy link

voxelv commented Jan 31, 2024

@eblume I noticed your use case is like what I requested under #300

@eblume
Copy link
Author

eblume commented Jan 31, 2024

Thanks @voxelv. It looks like my reading of #300's solution on lines 144-146, this plugin is not using --edit but rather nb edit. My issue is specifically related to using either nb add or nb edit while using the --edit flag to indicate that the editor should be invoked. In particular, my problem is that the resulting editor session seems to hold a "lock" of some sort on either nb itself (globally across all processes) or else on the underlying git repo. (Note the obscure corner case where nb edit is used with --edit which corresponds to the case that we want to append content to a document AND THEN, afterwards, open the resulting document in an editor.)

Can you tell me if the plugin exhibits this behavior as well? From my reading it doesn't seem to invoke --edit in any case so I don't know if a test can be made.

@eblume
Copy link
Author

eblume commented Jan 31, 2024

(An extra word aside here for my use case: I am trying to design an 'interactive log' of sorts where a long-lived editor session is set to autoload changes from scripted prompts while allowing the user to attach prose and links in context buffers. It's all very hacked and alpha right now, but the code is working and can be seen here.)

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

2 participants