sncli icon indicating copy to clipboard operation
sncli copied to clipboard

Opening a note directly from shell

Open volt4ire opened this issue 6 years ago • 13 comments

Is there a way to open a note based on its title directly from the shell (ie: without opening first opening sncli and then selecting the note from the list)? Based on the docs it seems like you can open/edit a note directly by specifying its key with the -k option, but I don't know how to find or associate a key with a note. For example, I want to edit a simplenote note called "today" via sncli directly from bash, but running $sncli -k today returns a long python error message (see below). Thanks!

$ sncli -k today Traceback (most recent call last): File "/home/rwbarat/.local/bin/sncli", line 10, in sys.exit(main()) File "/home/rwbarat/.local/lib/python3.7/site-packages/simplenote_cli/sncli.py", line 1353, in main sncli(sync, verbose, config).gui(key) File "/home/rwbarat/.local/lib/python3.7/site-packages/simplenote_cli/sncli.py", line 967, in gui 'log' : self.log File "/home/rwbarat/.local/lib/python3.7/site-packages/simplenote_cli/view_note.py", line 21, in init self.note = self.ndb.get_note(self.key) if self.key else None File "/home/rwbarat/.local/lib/python3.7/site-packages/simplenote_cli/notes_db.py", line 351, in get_note return self.notes[key] KeyError: 'today'

volt4ire avatar Jul 17 '19 12:07 volt4ire

It's possible, but you must know the key. The key is the name of the json file without the extension. All notes are stored as individual file named xxxxx.json. xxxxx is the key. These files are stored in the "cfg_db_path" directory.

N0ury avatar Jul 17 '19 14:07 N0ury

To find the key, you can run sncli, then select the note you want, and type 'O' to show the note raw json. The key is displayed there.

N0ury avatar Jul 17 '19 14:07 N0ury

Thanks @nbenm. To add to this, there is a PR open (https://github.com/insanum/sncli/pull/49) to enable acting on a note based on its title, but it needs some work before it can be merged.

samuelallan72 avatar Jul 17 '19 22:07 samuelallan72

To find the key, you can run sncli, then select the note you want, and type 'O' to show the note raw json. The key is displayed there.

Awesome, didn't know that one, thanks.. any way I can view in my default editor?

drewauff avatar Dec 19 '20 03:12 drewauff

@drewauff

Awesome, didn't know that one, thanks.. any way I can view in my default editor?

Yep, you can set the cfg_pager option. It defaults to $PAGER if set, or less.

samuelallan72 avatar Dec 19 '20 03:12 samuelallan72

@drewauff

Awesome, didn't know that one, thanks.. any way I can view in my default editor?

Yep, you can set the cfg_pager option. It defaults to $PAGER if set, or less.

Yep, that did it, Thank You 👍🏽

drewauff avatar Dec 21 '20 01:12 drewauff

Hello. Is there a way to open a note in editor?? this command sncli -k a67e0325eb5b4e7790719fc0b22b99d1 opens it but in viewer mode. not inside editor.. anyone knows? thanks!

andmarti1424 avatar May 29 '22 14:05 andmarti1424

Le 2022-05-29 07:45, Andrés Martinelli a écrit :

Hello. Is there a way to open a note in editor?? this command sncli -k a67e0325eb5b4e7790719fc0b22b99d1 opens it but in viewer mode. not inside editor.. anyone knows? thanks!

-- Reply to this email directly or view it on GitHub: https://github.com/insanum/sncli/issues/88#issuecomment-1140464016 You are receiving this because you are subscribed to this thread.

Message ID: @.***>

Hi,

do the same and then type "e" to edit the note.

N0ury avatar May 29 '22 14:05 N0ury

en type "e" to edit the note.

Yes. I am aware of that. But I was asking if there is a way to enter directly to edition without the need of pressing 'e'. thanks again.

andmarti1424 avatar May 29 '22 14:05 andmarti1424

@andmarti1424

if there is a way to enter directly to edition without the need of pressing 'e'.

There is an edit subcommand, so this should do what you want:

sncli -k a67e0325eb5b4e7790719fc0b22b99d1 edit

EDIT: order of arguments is significant - currently it needs the -k <key arg before edit.

samuelallan72 avatar May 30 '22 01:05 samuelallan72

@andmarti1424

if there is a way to enter directly to edition without the need of pressing 'e'.

There is an edit subcommand, so this should do what you want:

sncli -k a67e0325eb5b4e7790719fc0b22b99d1 edit

EDIT: order of arguments is significant - currently it needs the -k <key arg before edit.

Actually I tried that. And it just showed:

 sncli [OPTIONS] [COMMAND] [COMMAND_ARGS]

 OPTIONS:
  -h, --help                  - usage help
  -v, --verbose               - verbose output
  -n, --nosync                - don't perform a server sync
  -r, --regex                 - search string is a regular expression
  -k <key>, --key=<key>       - note key
  -t <title>, --title=<title> - title of note for create (cli mode)
  -c <file>, --config=<file>  - config file to read from (defaults to ~/.snclirc)

 COMMANDS:
  <none>                      - console gui mode when no command specified
  sync                        - perform a full sync with the server
  list [search_string]        - list notes (refined with search string)
  export [search_string]      - export notes in JSON (refined with search string)
  dump [search_string]        - dump notes (refined with search string)
  create [-]                  - create a note ('-' content from stdin)
  import [-]                  - import a note in JSON format ('-' JSON from stdin)
  export                      - export a note in JSON format (specified by <key>)
  dump                        - dump a note (specified by <key>)
  edit                        - edit a note (specified by <key>)
  < trash | untrash >         - trash/untrash a note (specified by <key>)
  < pin | unpin >             - pin/unpin a note (specified by <key>)
  < markdown | unmarkdown >   - markdown/unmarkdown a note (specified by <key>)
  tag get                     - retrieve the tags from a note (specified by <key>)
  tag set <tags>              - set the tags for a note (specified by <key>)
  tag add <tags>              - add tags to a note (specified by <key>)
  tag rm <tags>               - remove tags from a note (specified by <key>)

andmarti1424 avatar May 31 '22 12:05 andmarti1424

Actually I tried that. And it just showed:

@andmarti1424 can you paste the entire output, including what you wrote on the command line?

samuelallan72 avatar May 31 '22 22:05 samuelallan72

EDIT: order of arguments is significant - currently it needs the -k <key arg before edit.

This was the problem. Thank you!

andmarti1424 avatar Jun 01 '22 11:06 andmarti1424