26 Commits
legacy ... v2.0

Author SHA1 Message Date
Vera Lewis
215c8b96b5 Merge branch 'main' of gitlab.com:xenami/vns 2025-12-17 23:41:52 -06:00
Vera Lewis
2bc8a8fe72 Updated documentation 2025-12-17 23:34:03 -06:00
Vera Lewis
a8d975535c Updated documentation 2025-12-17 23:18:05 -06:00
Vera Lewis
f6eab4d8b5 simplified vns_gpgid 2025-12-17 23:10:04 -06:00
Vera Lewis
2f5271d668 Documented duplicate feature; fixed a bug in duplicate caused by nonexistent notebooks 2025-11-07 03:55:07 -06:00
Vera Lewis
e06e98beef Added docstring for vns_journal 2025-09-05 21:04:32 -05:00
Vera Lewis
286b3efbdf further cleanup of gpg/gpg2 calls 2025-09-05 21:03:12 -05:00
Vera Lewis
72ae650e24 changed two instances of gpg to gpg2 2025-09-04 22:26:01 -05:00
Vera Lewis
771ed9c4c3 Added Daily Journal functionality 2025-09-04 22:22:46 -05:00
Vera Lewis
0d6c725ef4 Fixed creation glitch with multiple GPG IDs 2024-08-17 04:53:39 -05:00
Vera Lewis
6a7655326b Added Query function, cleaned up arg parser 2024-06-28 18:43:42 -05:00
Vera Lewis
6ff62ebd19 Added credit for zsh completion file 2024-04-11 01:46:40 -05:00
Vera Lewis
96848fb85c Updated vns_import to use vns_gpgid, as well as create nonexistent paths 2024-04-01 19:39:42 -05:00
Vera Lewis
5e4ec8f765 vns_mv now commits after renaming a note; code cleanup 2024-04-01 03:49:15 -05:00
Vera Lewis
fb164789b1 Removed product printing string 2024-03-31 03:47:46 -05:00
Vera Lewis
ae90dce106 Fixed init committing before .gpg-id created; muted calls to gpg 2024-03-31 03:37:30 -05:00
Vera Lewis
a7c57c3779 vns_print now verifies the existence of the note to print 2024-03-31 02:17:00 -05:00
Vera Lewis
2bcbf830d4 Updated vns_merge to use new vns_gpgid recipients 2024-03-31 02:14:21 -05:00
Vera Lewis
1b4a3ff549 Fixed new path creation for vns_create 2024-03-31 01:39:05 -05:00
Vera Lewis
0432e9d86f Added re-encryption capability to init function and changed create to use stored gpg recipients 2024-03-31 01:32:50 -05:00
Vera Lewis
3d933a6831 minor edit to Makefile, used only for installing 2024-03-31 01:32:33 -05:00
Vera Lewis
1005e99309 Removed execute from vns; set appropriate modes in makefile 2024-03-27 22:30:19 -05:00
Vera Lewis
0011cf88c0 Updated Makefile to install ZSH completion 2024-03-27 19:28:45 -05:00
Vera Lewis
eaea4139cc Moved ZSH completion to appropriate directory structure 2024-03-27 19:27:31 -05:00
Vera Lewis
2f582525f6 Significant changes towards VNS 2.0 2024-03-27 19:26:46 -05:00
Jon Lewis
90cb8d02bf Major work done for vns v1.2 2019-09-17 22:35:05 -05:00
6 changed files with 500 additions and 583 deletions

View File

@@ -1,3 +1,9 @@
v1.1 v1.1
Added merge, rename options Added merge, rename options
Enabled gpg-agent Enabled gpg-agent
v1.2
* Added import, duplicate options
* reworked delete option to support multiple deletions
* GNU Switches were never supported, and documentation has been updated to reflect this
* Reworked merge function

2
DEBUG
View File

@@ -1,4 +1,4 @@
Vim Note System, v1.1 Vim Note System, v1.2
The following is a table of exit codes The following is a table of exit codes

339
LICENSE
View File

@@ -1,339 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

View File

@@ -11,20 +11,24 @@ to a popular note-taking app. The thought occurred that a note system need
not reinvent the wheel with its own GUI editor and proprietary file format, not reinvent the wheel with its own GUI editor and proprietary file format,
but instead could use the tools already provided by the operating system. but instead could use the tools already provided by the operating system.
vim note system usage: vns [-cdelpqr] <notebook/section/name>
================== vns -I GPG_RECIPIENT (GPG_RECIPIENTS...)
vns -h
usage: vns [-cedlp] <notebook/section/name>
vns [-hi]
vns git ... vns git ...
-c | --create : Create note -c : Create note
-d | --delete : Delete note -d : Delete note(s)
-e | --edit : Open note for editing -e : Open note for editing
-h | --help : Display this message -h : Display this message
-i | --init : Initialize note store" -i : import file as note
-l | --list : List all notes in <notebook> -I : Initialize note store
-p | --print : Print note to console -j : Open Daily Journal Entry
-l : List all notes in <notebook>
-m : Merge two or more notes
-p : Print note to console
-q : Query notes for expression
-r : Rename/move a note
-u : Duplicate note as given path
## Installing ## Installing
### Dependencies ### Dependencies
@@ -33,15 +37,15 @@ but instead could use the tools already provided by the operating system.
* tree * tree
* git * git
** Note: ** Install [vim-gnupg] before use. vns *does* check this, but only *after* ** Note: ** Install [vim-gnupg] before use. vns does not verify notes encrypt successfully.
a note has been created.
To install, place `vns` in your path, and run `vns -i`. To install, place `vns` in your path, and run `vns -I`.
vim note system will establish its note store under ~/.config/vns. vim note system will establish its note store under ~/.vns.
The location of the store may be changed on line 6. The location of the store may be changed on line 4, or via the envioronment
variable VNS_STORE.
To uninstall, remove the files you copied. Notes will still exist in ~/.config/vns To uninstall, remove the files you copied. Notes will still exist in ~/.vns
## Tips and Tricks ## Tips and Tricks
* To list all notes in all notebooks, simply run `vns`. * To list all notes in all notebooks, simply run `vns`.
@@ -51,6 +55,9 @@ but instead could use the tools already provided by the operating system.
The code here is my own, however much of VNS's design and behavior was The code here is my own, however much of VNS's design and behavior was
influenced by [pass]. influenced by [pass].
ZSH Completion is heavily modified, but adapted from pass's zsh completion file
as an example.
## License ## License
Vim Note System is licensed under the terms of the GNU General Public License Vim Note System is licensed under the terms of the GNU General Public License
Version 2, as detailed in `LICENSE`. Version 2, as detailed in `LICENSE`.
@@ -59,7 +66,7 @@ Version 2, as detailed in `LICENSE`.
If something seems off, or just doesn't work, please open an issue and I'll look If something seems off, or just doesn't work, please open an issue and I'll look
into it. into it.
Feature requests should be submitted to jon.lewis@xenami.net with [SNS Feature Request] Feature requests should be submitted to xenami@xenami.net with [VNS Feature Request]
in the subject line. in the subject line.
[pass]: http://passwordstore.org [pass]: http://passwordstore.org

463
vns
View File

@@ -1,27 +1,9 @@
#!/usr/bin/env bash #!/bin/bash
# Vim Note System v1.1, a simple script for managing encrypted plaintext notes # Vim Note System, a simple script for managing encrypted plaintext notes
# Copyright (C) 2018 Jon Lewis
# This program is free software; you can redistribute it and/or modify readonly VNS_STORE="${VNS_STORE:-$HOME/.vns}" # Where vns expects its note store
# it under the terms of the GNU General Public License as published by GPG_TTY="$(tty)" # Sets up gpg-agent for use
# the Free Software Foundation; either version 2 of the License, or export GPG_TTY
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
set -euo pipefail # Terminate the script if anything goes wrong
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
readonly VNS_PRODUCT="Vim Note System, v1.1" # String to print for reports
readonly VNS_STORE="$HOME/.config/vns" # Where vns expects its note store
readonly GPG_TTY="$(tty)" # Sets up gpg-agent for use
vns_raise (){ vns_raise (){
@@ -31,21 +13,31 @@ vns_raise (){
local -r VNS_RED_COLOR='\033[0;31m' local -r VNS_RED_COLOR='\033[0;31m'
local -r VNS_RESET_COLOR='\033[0m' local -r VNS_RESET_COLOR='\033[0m'
printf "%s, %s\\n\\n" "$VNS_PRODUCT"
printf "$VNS_RED_COLOR!$VNS_RESET_COLOR - %s\\n" "$1" 1>&2 printf "$VNS_RED_COLOR!$VNS_RESET_COLOR - %s\\n" "$1" 1>&2
exit "$2" exit "$2"
} }
vns_report () {
# report (message)
# Prints message to the console, formatted with a blue asterisk to indicate
# some successful operation has completed
local -r VNS_BLUE_COLOR='\033[0;34m'
local -r VNS_RESET_COLOR='\033[0m'
printf "${VNS_BLUE_COLOR}*${VNS_RESET_COLOR} - %s\n" "$*"
}
vns_checkDeps (){ vns_checkDeps (){
# checkDeps # checkDeps
# Prints a list of unbound variables # Prints a list of missing dependencies
# Currently these dependencies are {vim, tree, git}
readonly VNS_DEPS=("vim" "gpg2" "tree" "git") for DEP in 'vim' 'tree' 'git'; do
if ! command -v "$DEP" >/dev/null 2>&1; then
for DEP in "${VNS_DEPS[@]}"; do
if test ! -e "$(which "$DEP" 2>/dev/null)"; then
printf "%s " "$DEP" printf "%s " "$DEP"
fi fi
done done
@@ -59,33 +51,86 @@ vns_sanityCheck () {
# --- Dependencies --- # --- Dependencies ---
# Get list of missing dependencies # Get list of missing dependencies
local MISSING; MISSING="$(vns_checkDeps)" MISSING="$(vns_checkDeps)"
# If that list is not empty, inform the user and exit on code 20 # Inform the user of missing dependencies and exit on code 20 if any were found
if [ -n "$MISSING" ]; then if [ -n "$MISSING" ]; then
vns_raise "Missing Dependencies: $MISSING" 20 vns_raise "Missing Dependencies: $MISSING" 20
fi
# --- Store --- # --- Store ---
# Verify that the note store has been initialized # Verify that the note store has been initialized
if [ ! -d "$VNS_STORE" ]; then elif [ ! -d "$VNS_STORE" ]; then
vns_raise "The vns store needs to be initialized (hint: -i)" 21 vns_raise "The vns store needs to be initialized (hint: -I)" 21
# Verify that intended GPG recipients are stored in compliance with v2.0
elif [ ! -r "$VNS_STORE/.gpg-id" ]; then
vns_raise "Re-initialize (-I) with gpg recipients. Existing notes will be re-encrypted" 21
fi fi
} }
vns_init () { vns_init () {
# initStore # init (GPG recipients...)
# Prepares $VNS_STORE for use # Prepares $VNS_STORE for use
if [ -d "$VNS_STORE/.git" ]; then # Verify that recipients were specified
vns_raise "Store already initialized" 2; if [ "$#" -lt 1 ]; then
vns_raise "No GPG Recipients Specified" 3
# Re-encrypt existing notes, if present
elif [ -d "$VNS_STORE/.git" ]; then
# Reset list of GPG recipients
echo -n '' > "${VNS_STORE}/.gpg-id"
vns_reencrypt "$@"
# No existing store found; initialize a new one
else
# Create a new VNS Store
git init "$VNS_STORE" >/dev/null
vns_report "Initialized new VNS store"
fi fi
mkdir -p "$VNS_STORE" # Store GPG Recipients for later note creation whether re-encrypting, or
cd "$VNS_STORE" || exit # initializing a new store
git init >/dev/null
for recipient in "$@"; do
echo "$recipient" >> "${VNS_STORE}/.gpg-id"
done
vns_git add .gpg-id >/dev/null
vns_git commit -am "Updated GPG recipients" >/dev/null
}
vns_reencrypt () {
# reencrypt (GPG recipients...)
# Re-encrypt all notes with provided gpg recipients.
# Construct list of arguments from provided recipients
local -a GPG_RECIPS;
for recipient in "$@"; do
GPG_RECIPS=( "${GPG_RECIPS[@]}" "-r" "$recipient" )
done
# Find all notes and re-encrypt them
find "${VNS_STORE}" -name "*.gpg" | while read -r FILE; do\
gpg2 --batch --decrypt "$FILE" 2>/dev/null | gpg2 --batch "${GPG_RECIPS[@]}" --encrypt --output "${FILE}_new".gpg >/dev/null 2>&1
mv "${FILE}_new.gpg" "$FILE";
done
vns_report "Re-encrypted existing notes with $*"
vns_git commit -am "Re-encrypted existing notes with ${GPG_RECIPS[*]}" >/dev/null 2>&1
}
vns_gpgid () {
# gpgid
# Print a list of all recipients listed in .gpg-id
sed 's/^/-r /' "$VNS_STORE/.gpg-id"
} }
@@ -94,20 +139,24 @@ vns_printHelp (){
# printHelp # printHelp
# Prints help information to stdout # Prints help information to stdout
printf "%s" "usage: vns [-cedlp] <notebook/section/name>" printf "%s" "usage: vns [-cdelpqr] <notebook/section/name>"
printf "\\n%s" " vns -I" printf "\\n%s" " vns -I GPG_RECIPIENT (GPG_RECIPIENTS...)"
printf "\\n%s" " vns -h" printf "\\n%s" " vns -h"
printf "\\n%s" " vns git ..." printf "\\n%s" " vns git ..."
printf "\\n" printf "\\n"
printf "\\n%s" " -c : Create note" printf "\\n%s" " -c : Create note"
printf "\\n%s" " -d : Delete note" printf "\\n%s" " -d : Delete note(s)"
printf "\\n%s" " -e : Open note for editing" printf "\\n%s" " -e : Open note for editing"
printf "\\n%s" " -h : Display this message" printf "\\n%s" " -h : Display this message"
printf "\\n%s" " -i : import file as note" printf "\\n%s" " -i : import file as note"
printf "\\n%s" " -I : Initialize note store" printf "\\n%s" " -I : Initialize note store"
printf "\\n%s" " -j : Open Daily Journal Entry"
printf "\\n%s" " -l : List all notes in <notebook>" printf "\\n%s" " -l : List all notes in <notebook>"
printf "\\n%s" " -m : Merge two or more notes" printf "\\n%s" " -m : Merge two or more notes"
printf "\\n%s" " -p : Print note to console" printf "\\n%s" " -p : Print note to console"
printf "\\n%s" " -q : Query notes for expression"
printf "\\n%s" " -r : Rename/move a note"
printf "\\n%s" " -u : Duplicate note as given path"
printf "\\n\\n" printf "\\n\\n"
} }
@@ -116,22 +165,18 @@ vns_list () {
# list (notebook) # list (notebook)
# Prints a tree containing all notes in the notebook # Prints a tree containing all notes in the notebook
# If no notebook is specified, the entire store is used # If no notebook is specified, all notes are shown
numNotes () { find . -name "*.gpg" \( ! -regex '.*/\..*' \) | wc -l; }
# Check for default behavior # Check for default behavior
if [ -z "${*:1:1}" ]; then if [ "$#" -lt 1 ]; then
readonly NOTEBOOK="" local -r "NOTEBOOK"=""
if [ "$(numNotes)" != "0" ];then printf "%s\\n" "vns"
printf "%s\\n" "Store"
fi
else else
readonly NOTEBOOK="$1" readonly NOTEBOOK="$1"
printf "%s\\n" "$1" printf "%s\\n" "$1"
fi fi
tree -C --noreport --prune "$VNS_STORE/$NOTEBOOK"\ tree --noreport --prune "$VNS_STORE/$NOTEBOOK"\
| tail -n +2\ | tail -n +2\
| sed s/\.gpg//g | sed s/\.gpg//g
@@ -142,24 +187,41 @@ vns_rm () {
# rm (note) # rm (note)
# removes (note) from the store # removes (note) from the store
local -r VNS_BLUE_COLOR='\033[0;34m' # Verify notes were provided
local -r VNS_RESET_COLOR='\033[0m' if [ "$#" -lt 1 ]; then
vns_raise "Insufficient arguments" 30
fi
# Verify $1 is bound while [ "$#" -gt 0 ]; do
if [ -z "${*:1:1}" ]; then vns_raise "Insufficient arguments" 30; fi
# Verify the note exists # Verify the note exists
if [ ! -r "$VNS_STORE/$1.gpg" ]; then if [ ! -r "$VNS_STORE/$1.gpg" ]; then
vns_raise "Note does not exist" 31; vns_raise "Note does not exist" 31;
fi fi
# Delete the Note # Delete the Note
git rm "$VNS_STORE/$1.gpg" > /dev/null vns_git rm "$VNS_STORE/$1.gpg" > /dev/null
git commit -m "Deleted $1" > /dev/null vns_git commit -m "Deleted $1" > /dev/null
# Report success # Report success
printf "%s, %s\\n\\n" "$VNS_PRODUCT" vns_report "Deleted $1"
printf "$VNS_BLUE_COLOR!$VNS_RESET_COLOR - %s\\n" "Deleted $VNS_STORE/$1"
# Move to the next item
shift
done
}
vns_header () {
# header (title)
# Print note title and date in Markdown format
if [ "$#" -lt 1 ]; then
vns_raise "header: no note title provided" 4
else
echo "# $1"
printf "## %s" "$(date)"
fi
} }
vns_create () { vns_create () {
@@ -169,9 +231,11 @@ vns_create () {
local -r VNS_RED_COLOR='\033[0;31m' local -r VNS_RED_COLOR='\033[0;31m'
local -r VNS_RESET_COLOR='\033[0m' local -r VNS_RESET_COLOR='\033[0m'
local -a create_gpgid="($(vns_gpgid))"
# Verify $1 is bound if [ "$#" -lt 1 ]; then
if [ -z "${*:1:1}" ]; then vns_raise "Insufficient arguments" 40; fi printf "usage: %s %s\n" "$(basename "$0")" "-c [notebook/section/](name)"
return
fi
# Refuse to overwrite a note # Refuse to overwrite a note
if [ -r "$VNS_STORE/$1.gpg" ]; then vns_raise "Note already exists" 41; fi if [ -r "$VNS_STORE/$1.gpg" ]; then vns_raise "Note already exists" 41; fi
@@ -179,19 +243,20 @@ vns_create () {
# If the note belongs to a new notebook, create the notebook # If the note belongs to a new notebook, create the notebook
if [ ! -d "$(dirname "$1")" ]; then mkdir -p "$VNS_STORE/$(dirname "$1")"; fi if [ ! -d "$(dirname "$1")" ]; then mkdir -p "$VNS_STORE/$(dirname "$1")"; fi
# Create-Edit the note # Create empty note
vim "$VNS_STORE/$1.gpg" mkdir -p "$(dirname "$VNS_STORE/$1.gpg")"
if [ -n "${VNS_TITLE+isset}" ]; then
# Warn the user if the note failed to encrypt vns_header "${VNS_TITLE}" | gpg2 --batch "${create_gpgid[@]}" --encrypt -o "$VNS_STORE/$1.gpg" 2>/dev/null
if ! grep "PGP" <<< "$(file "$VNS_STORE/$1.gpg")" > /dev/null; then else
printf "$VNS_RED_COLOR!$VNS_RESET_COLOR - %s\\n %s\\n"\ vns_header "$(basename "$1")" | gpg2 --batch "${create_gpgid[@]}" --encrypt -o "$VNS_STORE/$1.gpg" 2>/dev/null
"The created note was not encrypted."\
"Check your vim-gnupg setup."
fi fi
# Update Git # Edit the note
git add "$VNS_STORE/$1.gpg" > /dev/null vim "$VNS_STORE/$1.gpg"
git commit -m "Added $1" > /dev/null
# Update vns_git
vns_git add "$VNS_STORE/$1.gpg" > /dev/null
vns_git commit -m "Added $1" > /dev/null
} }
@@ -201,7 +266,7 @@ vns_edit () {
# Open (note) for editing in Vim # Open (note) for editing in Vim
# Verify $1 is bound # Verify $1 is bound
if [ -z "${*:1:1}" ]; then vns_raise "Insufficient arguments" 50; fi if [ "$#" -lt 1 ]; then vns_raise "Insufficient arguments" 50; fi
# Refuse to edit non-existent notes # Refuse to edit non-existent notes
if [ ! -r "$VNS_STORE/$1.gpg" ]; then vns_raise "Note not found: $1" 51; fi if [ ! -r "$VNS_STORE/$1.gpg" ]; then vns_raise "Note not found: $1" 51; fi
@@ -209,9 +274,23 @@ vns_edit () {
# Edit the specified note # Edit the specified note
vim "$VNS_STORE/$1.gpg" vim "$VNS_STORE/$1.gpg"
# Update Git # Update vns_git
git add "$VNS_STORE/$1.gpg" > /dev/null vns_git add "$VNS_STORE/$1.gpg" > /dev/null
git commit -m "Edited $1" > /dev/null vns_git commit -m "Edited $1" > /dev/null
}
vns_journal () {
# journal
# Create or edit a Daily Journal Entry under yy/mm/dd
TODAY="$(date '+%y/%m/%d')"
if [ -r "$VNS_STORE/${TODAY}.gpg" ]; then
vns_edit "${TODAY}"
else
VNS_TITLE="Daily Journal for $TODAY" vns_create "${TODAY}"
fi
} }
vns_import () { vns_import () {
@@ -220,33 +299,39 @@ vns_import () {
# If src is the path to a file, and dest is a valid note name, # If src is the path to a file, and dest is a valid note name,
# import src dest copies an encrypted version of src to the note store # import src dest copies an encrypted version of src to the note store
if [ -z "${*:1:1}" ]; then if [ "$#" -lt 2 ]; then
vns_raise "No source file specified" 90 printf "usage: %s %s\n" "$(basename "$0")" "-i (source) (destination)"
return
fi
elif [ -z "${*:2:2}" ]; then if [ ! -f "$1" ]; then
vns_raise "No destination name specified" 91
elif [ ! -f "$1" ]; then
vns_raise "Cannot read $1" 92 vns_raise "Cannot read $1" 92
elif [ -f "$VNS_STORE/$2" ]; then elif [ -f "$VNS_STORE/$2" ]; then
printf "%s" "Note already exists. Overwrite? (Y/N) " printf "%s" "Note already exists. Overwrite? (Y/N) "
local response; read -r response local response=''; read -r response
case "$response" in case "$response" in
Yy) Y|y)
rm "$VNS_STORE/$2";; rm "$VNS_STORE/$2";;
*) *)
vns_raise "User declined overwrite" 0;; vns_raise "User declined overwrite" 0;;
esac esac
fi fi
printf "%s:" "Specify GPG Public Key: " #printf "%s:" "Specify GPG Public Key: "
local gpg_key; read -r gpg_key #local gpg_key=''; read -r gpg_key
gpg2 -r "$gpg_key" -o "$VNS_STORE/$2.gpg" -e "$1" # Create any necessary directories
mkdir -p "$VNS_STORE/$(dirname "$2.gpg")"
git add "$VNS_STORE/$2.gpg" if [ "${1##*.}" == "gpg" ]; then
git commit -m "Imported file $1 as $2" gpg2 --batch --decrypt "$1" | gpg2 --batch "$(vns_gpgid)" -o "$VNS_STORE/$2.gpg" --encrypt
else
gpg2 --batch "$(vns_gpgid)" -o "$VNS_STORE/$2.gpg" --encrypt "$1"
fi
vns_git add "$VNS_STORE/$2.gpg"
vns_git commit -m "Imported file $1 as $2"
} }
@@ -256,11 +341,17 @@ vns_print () {
# print the given note to stdout # print the given note to stdout
# Verify $1 is bound # Verify $1 is bound
if [ -z "${*:1:1}" ]; then vns_raise "Insufficient arguments" 11; fi if [ "$#" -lt 1 ]; then
vns_raise "Insufficient arguments" 11
# Verify $1 exists
elif ! [ -r "$VNS_STORE/$1.gpg" ]; then
vns_raise "Could not read $1" 12
else
# Decrypt the specified note # Decrypt the specified note
gpg2 -d "$VNS_STORE/$1.gpg" gpg2 --batch -d "$VNS_STORE/$1.gpg"
fi
} }
vns_mv () { vns_mv () {
@@ -268,11 +359,21 @@ vns_mv () {
# mv (src) (dest) # mv (src) (dest)
# If (src) is a note in the vns store, mv src dest moves src to dest # If (src) is a note in the vns store, mv src dest moves src to dest
if [ -z "${*:2}" ]; then vns_raise "Insufficient arguments" 70; fi # Ensure two arguments were provided
if [ "$#" -lt 2 ]; then vns_raise "Insufficient arguments" 70; fi
# Ensure source can be read
if [ ! -r "$VNS_STORE/$1.gpg" ]; then vns_raise "Cannot read $1" 71; fi if [ ! -r "$VNS_STORE/$1.gpg" ]; then vns_raise "Cannot read $1" 71; fi
# Refuse to overwrite existing notes
if [ -r "$VNS_STORE/$2.gpg" ]; then vns_raise "Note $2 already exists" 72; fi if [ -r "$VNS_STORE/$2.gpg" ]; then vns_raise "Note $2 already exists" 72; fi
git mv "$VNS_STORE/$1.gpg" "$VNS_STORE/$2.gpg" # Create any necessary directories
mkdir -p "$VNS_STORE/$(dirname "$2.gpg")"
# Rename the note
vns_git mv "$VNS_STORE/$1.gpg" "$VNS_STORE/$2.gpg"
vns_git commit -am "Renamed $1 -> $2"
} }
@@ -281,90 +382,160 @@ vns_merge () {
# merge (output) (notes[]) # merge (output) (notes[])
# If notes[] is an array of note names and output is a new note name, # If notes[] is an array of note names and output is a new note name,
# merge (output) (notes[]) concatenates notes[] into output. # merge (output) (notes[]) concatenates notes[] into output.
if [ "$#" -lt 2 ]; then
printf "usage: %s %s\n" "$(basename "$0")" "-m (output) (notes...)"
return
fi
if [ -z "${*:1}" ]; then vns_raise "No output specified" 81; fi
if [ -z "${*:2}" ]; then vns_raise "No inputs specified" 84; fi
if [ -r "$VNS_STORE/$1.gpg" ]; then vns_raise "Output file already exists." 82; fi if [ -r "$VNS_STORE/$1.gpg" ]; then vns_raise "Output file already exists." 82; fi
# Make output file
if [ ! -r "$VNS_STORE/$2.gpg" ]; then vns_raise "Could not read $2" 83; fi if [ ! -r "$VNS_STORE/$2.gpg" ]; then vns_raise "Could not read $2" 83; fi
cp "$VNS_STORE/$2.gpg" "$VNS_STORE/$1.gpg"
local -r GPG_RECIP="$(gpg --list-only -v -d "$VNS_STORE/$1.gpg" 2>&1 | cut -f 5 -d " ")" local -r NOTE_NAME="$1"
local -r OUTPUT="${VNS_STORE}/${1}.gpg"
shift
for note in "${@:3}"; do vns_gpgcat () {
for note in "$@"; do
if [ ! -r "$VNS_STORE/$note.gpg" ]; then if [ ! -r "$VNS_STORE/$note.gpg" ]; then
rm "$VNS_STORE/$1.gpg" rm "$VNS_STORE/$1.gpg"
vns_raise "Could not read $note" 83; vns_raise "Could not read $note" 83;
fi fi
gpg2 --batch --yes -r "$GPG_RECIP" -o "$VNS_STORE/$1.gpg" -e <<< "$(gpg2 -d "$VNS_STORE/$1.gpg") $(gpg2 -d "$VNS_STORE/$note.gpg")" printf "File: %s\n" "$note"
gpg2 --batch -d "$VNS_STORE/$note.gpg" 2>/dev/null
printf "\n"
done done
}
for note in "${@:2}"; do vns_gpgcat "$@" | gpg2 --batch --yes "$(vns_gpgid)" --encrypt -o "$OUTPUT"
git rm "$VNS_STORE/$note.gpg"
done
git add "$VNS_STORE/$1.gpg" printf "%s" "Remove old notes? (y/N) "
local response=''; read -r response
git commit -m "merged files ${*:2} into $1" case "$response" in
Y|y)
for note in "$@"; do
vns_git rm "$VNS_STORE/$note.gpg"
done;;
esac
vns_git add "$OUTPUT" >/dev/null 2>&1
vns_git commit -m "merged files $* into $NOTE_NAME" >/dev/null 2>&1
vns_report "Successfully merged files $* into $NOTE_NAME"
} }
vns_duplicate () { vns_duplicate () {
if [ -z "${*:1:1}" ]; then
vns_raise "No source note specified" 100
elif [ -z "${*:2:2}" ]; then if [ "$#" -lt 2 ]; then
vns_raise "No destination name specified" 101 vns_report "usage: $(basename "$0") -u (source) (destination)"
return
fi
elif [ ! -f "$VNS_STORE/$1" ]; then if [ ! -f "$VNS_STORE/$1.gpg" ]; then
vns_raise "Cannot read $1" 102 vns_raise "Cannot read $1" 102
elif [ -f "$VNS_STORE/$2" ]; then elif [ -f "$VNS_STORE/$2.gpg" ]; then
printf "%s" "Note already exists. Overwrite? (Y/N) " printf "%s" "Note already exists. Overwrite? (Y/N) "
local response; read -r response response=''; read -r response
case "$response" in case "$response" in
Yy) Y|y)
rm "$VNS_STORE/$2";; rm "$VNS_STORE/$2.gpg";;
*) *)
vns_raise "User declined overwrite" 0;; vns_raise "User declined overwrite" 0;;
esac esac
fi fi
mkdir -p "$VNS_STORE/$(dirname $2)"
cp "$VNS_STORE/$1.gpg" "$VNS_STORE/$2.gpg" cp "$VNS_STORE/$1.gpg" "$VNS_STORE/$2.gpg"
vns_git add "$VNS_STORE/$2.gpg"
git add "$VNS_STORE/$2"
} }
vns_query () {
# query EXPR
# Iterate through notes and find all instances of regular expression EXPR
if [ "$#" -lt 1 ]; then
vns_report "usage: $(basename "$0") -q EXPR"
return
fi
local -r VNS_ULNE="$(tput setaf smul)"
local -r VNS_="$(tput setaf rmul)"
# For each note, grep for QUERY
find "$VNS_STORE" -name "*.gpg" -not -name ".*" | while read -r note; do
# Remove VNS_STORE path and file extension for reporting
note_name="$(sed -e "s#$VNS_STORE/##" -e "s/.gpg//" -e "s#:#\\:#g" <<< "$note")"
# Decrypt note and perform the actual query
local query="$(gpg -d "$note" 2>/dev/null | grep -C 1 --color=always -nE "$1" )"
# Report only matches
if [ -n "${query:-}" ]; then
printf "$(tput smul)%s$(tput rmul)\n" "$note_name"
printf "%s\n" "$query"
fi
done
}
vns_git () {
# Simple passthrough for executing git commands in the VNS store
git -C "$VNS_STORE" "$@"
}
vns () { vns () {
# Bypass sanity check if told to initialize store # Bypass sanity check if told to initialize store
if [ "$*" != "-i" ]; then if [ "$1" != "-I" ]; then
vns_sanityCheck; vns_sanityCheck;
# Change Directory to Store for Git passthrough
cd "$VNS_STORE" || exit;
fi fi
primary_arg="$1"
# Default action is to list all notes shift
if [ -z "${*:1:1}" ]; then vns_list ""; exit 0; fi case "$primary_arg" in
"-c")
# List of valid arguments vns_create "$@"
declare -A -r ACTIONS=( ["-c"]="vns_create" ["-d"]="vns_rm"\ ;;
["-e"]="vns_edit" ["-l"]="vns_list"\ "-d")
["-h"]="vns_printHelp" ["-I"]="vns_init"\ vns_rm "$@"
["-i"]="vns_import" ["-m"]="vns_merge"\ ;;
["-p"]="vns_print" ["-r"]="vns_mv"\ "-e")
["-u"]="vns_duplicate" ["git"]="git" ) vns_edit "$@"
;;
# If given an invalid argument, inform the user and exit on code 10 "-l")
# Otherwise, perform the corresponding action vns_list "$@"
if ! test "${ACTIONS["$1"]+isset}"; then ;;
vns_raise "Invalid argument: $1" 10 "-h")
else vns_printHelp "$@"
"${ACTIONS["$1"]}" "${@:2}" ;;
fi "-I")
vns_init "$@"
;;
"-i")
vns_import "$@"
;;
"-j")
vns_journal "$@"
;;
"-m")
vns_merge "$@"
;;
"-p")
vns_print "$@"
;;
"-q")
vns_query "$@"
;;
"-r")
vns_mv "$@"
;;
"-u")
vns_duplicate "$@"
;;
"git")
vns_git "$@"
;;
*)
vns_list "$@"
esac
exit 0; exit 0;
} }
vns "$@" vns "$@"

72
zsh/site-functions/_vns Normal file
View File

@@ -0,0 +1,72 @@
#compdef vns
#autoload
# Modified from _pass zsh completion, with the following copyright information
# Copyright (C) 2012 - 2014:
# Johan Venant <jvenant@invicem.pro>
# Brian Mattern <rephorm@rephorm.com>
# Jason A. Donenfeld <Jason@zx2c4.com>.
# All Rights Reserved.
# This file is licensed under the GPLv2+. Please see COPYING for more information.
_vns () {
local cmd
if (( CURRENT > 2)); then
cmd=${words[2]}
# Set the context for the subcommand.
curcontext="${curcontext%:*:*}:vns-$cmd"
# Narrow the range of words we are looking at to exclude `vns'
(( CURRENT-- ))
shift words
# Run the completion for the subcommand
case "${cmd}" in
-e|-p|-r|-d|-c)
_vns_complete_notes
;;
#-c)
# _vns_complete_notebooks
# ;;
-l)
_vns_complete_notes
;;
*)
if [ "${cmd[0]}" != '-' ] && (( CURRENT > 2)); then
_vns_complete_notebooks
fi
;;
esac
else
local -a subcommands
subcommands=(
"-c:Create note"
"-d:Delete note"
"-e:Edit note"
"-h:Display help message"
"-i:Import a note"
"-I:Initialize a new VNS store"
"-l:List notes"
"-m:Merge notes"
"-p:Print note to console"
"-r:Rename/move a note"
)
_describe -t commands 'vns' subcommands
_vns_complete_notebooks
fi
}
_vns_complete_entries_helper () {
local IFS=$'\n'
local prefix
zstyle -s ":completion:${curcontext}:" prefix prefix || prefix="${VNS_STORE_DIR:-$HOME/.vns}"
_values -C 'notes' ${$(find -L ${prefix} -mindepth 1 -name .git -prune -o $@ -print | sed -e "s#${prefix}/##" -e "s/.gpg//" -e "s#:#\\:#g" | sort):-""}
}
_vns_complete_notebooks () {
_vns_complete_entries_helper -type d
}
_vns_complete_notes () {
_vns_complete_entries_helper -type f
}
_vns