From d7ce06b10b4c90ff07120ff5ad8f2291971c94fd Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Thu, 26 Sep 2019 19:56:43 +0530 Subject: [PATCH] Add plugin to take quick notes --- README.md | 7 +++---- nnn.1 | 5 ----- plugins/README.md | 1 + plugins/notes | 15 +++++++++++++++ src/nnn.c | 26 +++++--------------------- src/nnn.h | 3 --- 6 files changed, 24 insertions(+), 33 deletions(-) create mode 100755 plugins/notes diff --git a/README.md b/README.md index 06f25b7..68eb2ac 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ Visit the **[Wiki](https://github.com/jarun/nnn/wiki)** for operational concepts - Create, rename, duplicate files and directories - Per-context directory color (default: blue) - Spawn a shell, run apps, run commands, execute file - - Take quick notes, lock terminal (needs a locker) + - Lock terminal (needs a locker) - Shortcut reference a keypress away - Unicode support - Follows Linux kernel coding style @@ -179,7 +179,6 @@ Option completion scripts for Bash, Fish and Zsh can be found in respective subd | `NNN_USE_EDITOR=1` | open text files in `$VISUAL` (else `$EDITOR`, fallback vi) | | `NNN_CONTEXT_COLORS='1234'` | specify per context color [default: '4444' (all blue)] | | `NNN_SSHFS_OPTS='sshfs -o reconnect,idmap=user'` | specify SSHFS options | -| `NNN_NOTE='/home/user/Dropbox/notes'` | absolute path to note file [default: none] | | `NNN_OPENER=mimeopen` | custom file opener | | `NNN_IDLE_TIMEOUT=300` | idle seconds to lock terminal [default: disabled] | | `NNN_COPIER=copier` | clipboard copier script [default: none] | @@ -246,10 +245,10 @@ Press ? in `nnn` to see the list anytime. S du A Apparent du s Size E Extn t Time modified MISC - ! ^] Shell ^N Note L Lock + ! ^] Shell = Launcher R ^V Pick plugin :K xK Run plugin key K c SSHFS mount u Unmount - ^P Prompt/run expr = Launcher + ^P Prompt/run expr L Lock ``` Note: Help & settings, file details and archive listing are shown in the PAGER. Use the PAGER-specific keys in these screens. diff --git a/nnn.1 b/nnn.1 index a0fdfac..d74b848 100644 --- a/nnn.1 +++ b/nnn.1 @@ -182,11 +182,6 @@ when dealing with the !, e and p commands respectively. A single combination to NOTE: The options must be preceded by `sshfs` and comma-separated without any space between them. .Ed .Pp -\fBNNN_NOTE:\fR \fIabsolute\fR path to a note file. -.Bd -literal - export NNN_NOTE='/home/user/.mynotes' -.Ed -.Pp \fBNNN_OPENER:\fR specify a custom file opener. .Bd -literal export NNN_OPENER=mimeopen diff --git a/plugins/README.md b/plugins/README.md index 3ddbcf8..ace5375 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -19,6 +19,7 @@ The currently available plugins are listed below. | mocplay | sh | [moc](http://moc.daper.net/) | Appends (and plays, see script) selection/dir/file in moc| | ndiff | sh | vimdiff | Diff for selection (limited to 2 for directories) | | nmount | sh | pmount, udisks2 | Toggle mount status of a device as normal user | +| notes | sh | - | Open a quick notes file/dir in `$EDITOR` | | nwal | sh | nitrogen | Set image as wallpaper using nitrogen | | oldbigfile | sh | find, sort | List large files by access time | | organize | sh | file | Auto-organize files in directories by file type | diff --git a/plugins/notes b/plugins/notes new file mode 100755 index 0000000..02b9a0f --- /dev/null +++ b/plugins/notes @@ -0,0 +1,15 @@ +#!/usr/bin/env sh + +# Description: Open a quick notes file or directory in $EDITOR +# +# Details: Set the variable NOTE to the path to your quick notes file +# +# Shell: POSIX compliant +# Author: Arun Prakash Jana + +NOTE= +# NOTE=~/Dropbox/Notes/synced_note + +if [ ! -z "$NOTE" ]; then + $EDITOR "$NOTE" +fi diff --git a/src/nnn.c b/src/nnn.c index ea2aa7f..a7d678b 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -401,10 +401,9 @@ static const char * const messages[] = { #define NNN_CONTEXT_COLORS 2 #define NNN_IDLE_TIMEOUT 3 #define NNN_COPIER 4 -#define NNN_NOTE 5 -#define NNNLVL 6 /* strings end here */ -#define NNN_USE_EDITOR 7 /* flags begin here */ -#define NNN_TRASH 8 +#define NNNLVL 5 /* strings end here */ +#define NNN_USE_EDITOR 6 /* flags begin here */ +#define NNN_TRASH 7 static const char * const env_cfg[] = { "NNN_BMS", @@ -412,7 +411,6 @@ static const char * const env_cfg[] = { "NNN_CONTEXT_COLORS", "NNN_IDLE_TIMEOUT", "NNN_COPIER", - "NNN_NOTE", "NNNLVL", "NNN_USE_EDITOR", "NNN_TRASH", @@ -2852,10 +2850,10 @@ static bool show_help(const char *path) "cS du A Apparent du\n" "cs Size E Extn t Time modified\n" "1MISC\n" - "9! ^] Shell ^N Note L Lock \n" + "9! ^] Shell = Launcher\n" "9R ^V Pick plugin :K xK Run plugin key K\n" "cc SSHFS mount u Unmount\n" - "b^P Prompt/run expr = Launcher\n"}; + "b^P Prompt/run expr L Lock\n"}; fd = create_tmp_file(); if (fd == -1) @@ -3994,7 +3992,6 @@ nochange: case SEL_REDRAW: // fallthrough case SEL_RENAMEALL: // fallthrough case SEL_HELP: // fallthrough - case SEL_NOTE: // fallthrough case SEL_LOCK: { if (ndents) @@ -4027,19 +4024,6 @@ nochange: case SEL_RUNPAGE: spawn(pager, dents[cur].name, NULL, path, F_CLI); break; - case SEL_NOTE: - { - static char *notepath; - - notepath = notepath ? notepath : getenv(env_cfg[NNN_NOTE]); - if (!notepath) { - printwait("set NNN_NOTE", &presel); - goto nochange; - } - - spawn(editor, notepath, NULL, path, F_CLI); - break; - } default: /* SEL_LOCK */ lock_terminal(); break; diff --git a/src/nnn.h b/src/nnn.h index c65d562..8720efc 100644 --- a/src/nnn.h +++ b/src/nnn.h @@ -96,7 +96,6 @@ enum action { SEL_RUNCMD, SEL_RUNEDIT, SEL_RUNPAGE, - SEL_NOTE, SEL_LOCK, SEL_QUITCTX, SEL_QUITCD, @@ -246,8 +245,6 @@ static struct key bindings[] = { /* Open in EDITOR or PAGER */ { 'e', SEL_RUNEDIT }, { 'p', SEL_RUNPAGE }, - /* Open notes file */ - { CONTROL('N'), SEL_NOTE }, /* Lock screen */ { 'L', SEL_LOCK }, /* Quit a context */