Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57345a790d | ||
|
|
7ecc9e0361 | ||
|
|
3a757e08c5 |
@@ -1,9 +0,0 @@
|
||||
v1.1
|
||||
Added merge, rename options
|
||||
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
|
||||
30
DEBUG
30
DEBUG
@@ -1,30 +0,0 @@
|
||||
Vim Note System, v1.2
|
||||
|
||||
The following is a table of exit codes
|
||||
|
||||
Code In Function Meaning
|
||||
-----------------------------------------------------
|
||||
10 vns Invalid argument given
|
||||
|
||||
20 sanityCheck Missing dependencies
|
||||
21 sanityCheck VNS store not initialized
|
||||
|
||||
30 rm Insufficient arguments
|
||||
31 rm Note does not exist
|
||||
|
||||
40 create Insufficient arguments
|
||||
41 create Note already exists
|
||||
|
||||
50 edit Insufficient arguments
|
||||
51 edit Note not found
|
||||
|
||||
60 print Insufficient arguments
|
||||
|
||||
70 mv Insufficient arguments
|
||||
71 mv Couldn't read source note
|
||||
72 mv Destination note already exists
|
||||
|
||||
81 merge No output specified
|
||||
82 merge Output file already exists.
|
||||
83 merge could not open note
|
||||
|
||||
339
LICENSE
Normal file
339
LICENSE
Normal file
@@ -0,0 +1,339 @@
|
||||
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.
|
||||
75
README.md
75
README.md
@@ -1,73 +1,8 @@
|
||||
Vim Note System
|
||||
Simple Note System
|
||||
==================
|
||||
|
||||
## About
|
||||
Vim Note System is a shell script partially inspired by [pass].
|
||||
vns stores notes as asymmetrically encrypted plaintext using the
|
||||
vim-gnupg plugin.
|
||||
|
||||
VNS, formerly SNS, was originally conceived one morning during an update
|
||||
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,
|
||||
but instead could use the tools already provided by the operating system.
|
||||
|
||||
usage: vns [-cdelpqr] <notebook/section/name>
|
||||
vns -I GPG_RECIPIENT (GPG_RECIPIENTS...)
|
||||
vns -h
|
||||
vns git ...
|
||||
|
||||
-c : Create note
|
||||
-d : Delete note(s)
|
||||
-e : Open note for editing
|
||||
-h : Display this message
|
||||
-i : import file as note
|
||||
-I : Initialize note store
|
||||
-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
|
||||
### Dependencies
|
||||
* vim
|
||||
* gpg2
|
||||
* tree
|
||||
* git
|
||||
|
||||
** Note: ** Install [vim-gnupg] before use. vns does not verify notes encrypt successfully.
|
||||
|
||||
To install, place `vns` in your path, and run `vns -I`.
|
||||
|
||||
vim note system will establish its note store under ~/.vns.
|
||||
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 ~/.vns
|
||||
|
||||
## Tips and Tricks
|
||||
* To list all notes in all notebooks, simply run `vns`.
|
||||
* Notes beginning with . will not appear in the listing
|
||||
|
||||
## Credits
|
||||
The code here is my own, however much of VNS's design and behavior was
|
||||
influenced by [pass].
|
||||
|
||||
ZSH Completion is heavily modified, but adapted from pass's zsh completion file
|
||||
as an example.
|
||||
|
||||
## License
|
||||
Vim Note System is licensed under the terms of the GNU General Public License
|
||||
Version 2, as detailed in `LICENSE`.
|
||||
|
||||
## Bugs and Feature Requests
|
||||
If something seems off, or just doesn't work, please open an issue and I'll look
|
||||
into it.
|
||||
|
||||
Feature requests should be submitted to xenami@xenami.net with [VNS Feature Request]
|
||||
in the subject line.
|
||||
|
||||
[pass]: http://passwordstore.org
|
||||
[vim-gnupg]:http://www.vim.org/scripts/script.php?script_id=3645
|
||||
Simple Note System, a script for managing notes inspired in part by "pass" is
|
||||
deprecated in favor of Vim Note System. This version 1.0 copy of Simple Note
|
||||
System is present under the legacy branch of Vim Note System for the purpose
|
||||
of helping convert old openssl-encrypted SNS notes to GPG format.
|
||||
|
||||
28
errors.md
28
errors.md
@@ -1,28 +0,0 @@
|
||||
# Simple Note System, version 2
|
||||
## Error Code Reference
|
||||
|
||||
### General Codes
|
||||
| Name | Code | Meaning |
|
||||
|--------------|------|---------------------------------------|
|
||||
| ERR_NO_STORE | 5 | the SNS store needs to be initialized |
|
||||
| | | |
|
||||
| ERR_NO_OPTS | 10 | No mode argument was specified |
|
||||
| | | |
|
||||
| ERR_NO_ARGS | 11 | A mode requiring an argument was |
|
||||
| | | specified without an argument |
|
||||
| | | |
|
||||
|
||||
### Encryption-related codes
|
||||
|Name | Code | Meaning |
|
||||
|------------|------|-----------------------------------------|
|
||||
| ERR_NO_GPG | 100 | Encryption is enabled, but GPG is not |
|
||||
| | | installed |
|
||||
| | | |
|
||||
| ERR_NO_KEY | 110 | Encryption is enabled, but no recipient |
|
||||
| | | was specified |
|
||||
|
||||
### Creation-related codes
|
||||
|Name | Code | Meaning |
|
||||
|-----------------|------|------------------------------------|
|
||||
| ERR_NOTE_EXiSTS | 200 | The specified note already exists |
|
||||
| ERR_NOTE_NO_READ| 205 | The specified note cannot be read |
|
||||
311
sns.sh
Normal file
311
sns.sh
Normal file
@@ -0,0 +1,311 @@
|
||||
#!/bin/bash
|
||||
#==========================================================
|
||||
# Simple Note System, v1.0
|
||||
# Copyright 2014, Xenese Labs/Sicron-Perion XNF
|
||||
#==========================================================
|
||||
|
||||
PROD_STR="Simple Note System"
|
||||
VER_STR=v1.0
|
||||
|
||||
#==============================================================================
|
||||
# Section: Helper Functions
|
||||
#==============================================================================
|
||||
function writeconf {
|
||||
cat > $HOME/.sns << EOF
|
||||
#==========================================================
|
||||
# Simple Note System Config, v1.0
|
||||
# Copyright 2014, Xenese Labs/Sicron-Perion XNF
|
||||
#==========================================================
|
||||
|
||||
#Directory where notes will be stored
|
||||
BASEDIR=$HOME/notes
|
||||
|
||||
#File extension to use (for listing notes)
|
||||
EXT=note
|
||||
|
||||
#Preferred Editor
|
||||
EDITOR=vim
|
||||
|
||||
#Encryption
|
||||
#WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST
|
||||
ENCRYPTION="FALSE"
|
||||
ENC_KEY=""
|
||||
EOF
|
||||
|
||||
chmod 600 $HOME/.sns
|
||||
}
|
||||
|
||||
function help {
|
||||
echo ""
|
||||
echo "usage: sns [-ce] NAME NOTEBOOK SECTION"
|
||||
echo " sns [-d ] NAME NOTEBOOK SECTION"
|
||||
echo " sns [-l ] NOTEBOOK"
|
||||
echo " sns [-w ]"
|
||||
|
||||
echo ""
|
||||
echo " -c | --create : Create note"
|
||||
echo " -d | --delete : Delete note"
|
||||
echo " -e | --edit : Open note for editing"
|
||||
echo " -l | --list : List all notes in NOTEBOOK"
|
||||
echo " -w | --wconf : Write default configuration to ~/.sns (useful for Encryption)"
|
||||
echo ""
|
||||
}
|
||||
|
||||
function pause {
|
||||
read -p " Press [Enter] to continue."
|
||||
echo ""
|
||||
}
|
||||
|
||||
#==============================================================================
|
||||
# End Section: Helper Functions
|
||||
#==============================================================================
|
||||
|
||||
#==============================================================================
|
||||
# Section: Configuration
|
||||
#==============================================================================
|
||||
if [ -r $HOME/.sns ]; then
|
||||
source $HOME/.sns
|
||||
else
|
||||
BASEDIR=$HOME/notes
|
||||
EDITOR=vim
|
||||
EXT=note
|
||||
fi
|
||||
|
||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||
if [ -z "$ENC_KEY" ]; then
|
||||
ERR_NO_KEY="TRUE"
|
||||
ENCRYPTION="FALSE"
|
||||
pause
|
||||
fi
|
||||
command -v openssl >/dev/null 2>&1 || { ERR_NO_SSL="TRUE"; ENCRYPTION="FALSE"; }
|
||||
fi
|
||||
|
||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||
PROD_STR="Simple Note System (Encryption Enabled)"
|
||||
EXT="$EXT.enc"
|
||||
if [ ! -d ~/.tmp ]; then
|
||||
mkdir -p ~/.tmp
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "$PROD_STR, $VER_STR"
|
||||
if [ -n "$ERR_NO_SSL" ]; then
|
||||
echo >&2 " Warning: OpenSSL not installed. Encryption disabled."
|
||||
fi
|
||||
if [ -n "$ERR_NO_KEY" ]; then
|
||||
echo " Warning: No encryption key was provided. Encryption disabled."
|
||||
fi
|
||||
|
||||
if [ -n "$ERR_NO_SSL" -o -n "$ERR_NO_KEY" ]; then
|
||||
pause
|
||||
fi
|
||||
|
||||
#==============================================================================
|
||||
# End Section: Read Configuration
|
||||
#==============================================================================
|
||||
|
||||
|
||||
#==============================================================================
|
||||
# Section: Argument Parsing
|
||||
#==============================================================================
|
||||
|
||||
NAME=""
|
||||
NOTEBOOK=""
|
||||
SECTION=""
|
||||
|
||||
if [ -z "$1" ]; then #If no input was given, print help
|
||||
help
|
||||
exit
|
||||
else #Assume the user wants to do something.
|
||||
ARGS=( "$@" )
|
||||
for ARG in ${ARGS[@]};do
|
||||
if [ "$ARG" = "-c" -o $ARG == "--create" ]; then
|
||||
CREATE="TRUE"
|
||||
elif [ "$ARG" = "-d" -o $ARG == "--delete" ]; then
|
||||
DELETE="TRUE"
|
||||
elif [ "$ARG" = "-e" -o $ARG == "--edit" ]; then
|
||||
EDIT="TRUE"
|
||||
elif [ "$ARG" = "-ce" -o $ARG == "-ec" ]; then
|
||||
EDIT="TRUE"
|
||||
CREATE="TRUE"
|
||||
elif [ "$ARG" == "-l" -o "$ARG" == "--list" ]; then #If user asks for list, print list
|
||||
LIST="TRUE"
|
||||
elif [ "$ARG" == "-h" -o "$ARG" == "--help" ]; then #If user asks for help, print help
|
||||
help
|
||||
exit
|
||||
elif [ "$ARG" == "-w" -o "$ARG" == "--wconf" ]; then #If user wants to write config, write config
|
||||
writeconf
|
||||
exit
|
||||
|
||||
else
|
||||
if [ -z "$NAME" -a -n $ARG ]; then
|
||||
NAME=$ARG
|
||||
echo "Name: $NAME"
|
||||
elif [ -z "$NOTEBOOK" -a -n $ARG ]; then
|
||||
NOTEBOOK=$ARG
|
||||
echo "Notebook: $NOTEBOOK"
|
||||
elif [ -z "$SECTION" -a -n $ARG ]; then
|
||||
SECTION=$ARG/
|
||||
echo "Section: $SECTION"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
|
||||
#==============================================================================
|
||||
# End Section: Argument Parsing
|
||||
#==============================================================================
|
||||
|
||||
#==============================================================================
|
||||
# Section: Main
|
||||
#==============================================================================
|
||||
|
||||
NOTEDIR=$BASEDIR/$NOTEBOOK/$SECTION
|
||||
NOTE=$NOTEDIR$NAME.$EXT
|
||||
|
||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||
NOTE=$NOTE.tmp
|
||||
fi
|
||||
|
||||
#==========================================================================
|
||||
# Subection: List
|
||||
#==========================================================================
|
||||
if [ -n "$LIST" ]; then
|
||||
NOTEBOOK="$NAME" #In case of a list command, arg parsing fails.
|
||||
if [ -z "$NOTEBOOK" ]; then
|
||||
echo " ERROR: Insufficient arguments"
|
||||
help
|
||||
exit
|
||||
else
|
||||
if [ -d "$BASEDIR"/"$NOTEBOOK" ]; then
|
||||
|
||||
echo ""
|
||||
printf "Notes in $(basename $NOTEBOOK):"
|
||||
echo ""
|
||||
#find $BASEDIR/$NOTEBOOK -name "*.$EXT" -print0 | sed s:$BASEDIR/$NOTEBOOK/:" ":g | sed -e s:$EXT::g | tr "." " "
|
||||
NOTES=( $(find $BASEDIR/$NOTEBOOK -name "*.$EXT" -print0 | sed s:$BASEDIR/$NOTEBOOK/:" ":g | sed -e s:$EXT::g | tr "." " " | tr "/" " ") )
|
||||
|
||||
let i=0
|
||||
for NOTE in ${NOTES[@]}; do
|
||||
if [ -d $BASEDIR/$NOTEBOOK/$NOTE ]; then
|
||||
if [ "$LAST_SECTION" != "$NOTE" ]; then
|
||||
printf " Section: $NOTE\n"
|
||||
fi
|
||||
LAST_SECTION=$NOTE
|
||||
else
|
||||
#if [ $(($i % 1)) -eq 0 ]; then
|
||||
# printf "\n "
|
||||
#fi
|
||||
printf " $NOTE\n"
|
||||
fi
|
||||
let i++
|
||||
done
|
||||
printf "\n"
|
||||
else
|
||||
echo ""
|
||||
echo "ERROR: Notebook $NOTEBOOK does not exist."
|
||||
echo ""
|
||||
fi
|
||||
fi
|
||||
exit
|
||||
fi
|
||||
#======================================================================
|
||||
# Sanity Check - Actions below require a valid $NAME and $NOTEBOOK
|
||||
#======================================================================
|
||||
if [ -z "$NAME" -o -z "$NOTEBOOK" ]; then
|
||||
if [ -z "$NAME" -o -z "$NOTEBOOK" ]; then
|
||||
echo " ERROR: Insufficient arguments"
|
||||
help
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
|
||||
#==========================================================================
|
||||
# Subection: Delete
|
||||
#==========================================================================
|
||||
if [ "$DELETE" == "TRUE" ]; then
|
||||
if [ -e $NOTE -o -e ${NOTE%.*} ]; then
|
||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||
rm ${NOTE%.*}
|
||||
else
|
||||
rm $NOTE
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Deleted note: $NOTEBOOK/$SECTION$NAME."
|
||||
exit
|
||||
else
|
||||
|
||||
echo ""
|
||||
echo "ERROR: Note $NOTEBOOK/$SECTION$NAME does not exist."
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
|
||||
#==========================================================================
|
||||
# Subection: Create
|
||||
#==========================================================================
|
||||
if [ -z "$CREATE" -a -z "$EDIT" ]; then #If no action specified, print help and exit
|
||||
help
|
||||
exit
|
||||
else
|
||||
|
||||
|
||||
if [ "$CREATE" == "TRUE" ]; then
|
||||
if [ -e $NOTE -o -e ${NOTE%.*} ]; then
|
||||
|
||||
echo ""
|
||||
echo "ERROR: Note already exists"
|
||||
echo "Hint: use -e to edit the note."
|
||||
echo ""
|
||||
exit
|
||||
else
|
||||
#Create any necessary folders
|
||||
mkdir -p $NOTEDIR
|
||||
|
||||
#Fill in title
|
||||
echo "TITLE: $NAME" > $NOTE
|
||||
#Fill the second line with the date
|
||||
echo "DATE: $(date)" >> $NOTE
|
||||
|
||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||
if [ $EDIT == "FALSE" ]; then
|
||||
openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
#==========================================================================
|
||||
# Subection: Edit
|
||||
#==========================================================================
|
||||
if [ "$EDIT" == "TRUE" ]; then
|
||||
if [ -r "$NOTE" -o -r ${NOTE%.*} ]; then
|
||||
if [ -z "$CREATE" ]; then
|
||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||
openssl enc -d -aes-256-cbc -in ${NOTE%.*} -pass pass:$ENC_KEY > $NOTE
|
||||
fi
|
||||
echo "" >> $NOTE
|
||||
echo "EDIT $(date)" >> $NOTE
|
||||
fi
|
||||
$EDITOR $NOTE
|
||||
if [ "$ENCRYPTION" == "TRUE" ]; then
|
||||
openssl enc -aes-256-cbc -salt -in $NOTE -out ${NOTE%.*} -pass pass:$ENC_KEY
|
||||
rm $NOTE
|
||||
fi
|
||||
|
||||
else
|
||||
|
||||
echo ""
|
||||
echo "ERROR: Note cannot be opened for editting."
|
||||
echo ""
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
|
||||
exit
|
||||
541
vns
541
vns
@@ -1,541 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Vim Note System, a simple script for managing encrypted plaintext notes
|
||||
|
||||
readonly VNS_STORE="${VNS_STORE:-$HOME/.vns}" # Where vns expects its note store
|
||||
GPG_TTY="$(tty)" # Sets up gpg-agent for use
|
||||
export GPG_TTY
|
||||
|
||||
vns_raise (){
|
||||
|
||||
# raise (message) (exit code)
|
||||
# Prints error (message) to stderr, then exits with (exit code)
|
||||
|
||||
local -r VNS_RED_COLOR='\033[0;31m'
|
||||
local -r VNS_RESET_COLOR='\033[0m'
|
||||
|
||||
printf "$VNS_RED_COLOR!$VNS_RESET_COLOR - %s\\n" "$1" 1>&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 (){
|
||||
|
||||
# checkDeps
|
||||
# Prints a list of missing dependencies
|
||||
# Currently these dependencies are {vim, tree, git}
|
||||
|
||||
for DEP in 'vim' 'tree' 'git'; do
|
||||
if ! command -v "$DEP" >/dev/null 2>&1; then
|
||||
printf "%s " "$DEP"
|
||||
fi
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
vns_sanityCheck () {
|
||||
|
||||
# sanityCheck
|
||||
# Terminates script if environment is not suitable for vns
|
||||
|
||||
# --- Dependencies ---
|
||||
# Get list of missing dependencies
|
||||
MISSING="$(vns_checkDeps)"
|
||||
|
||||
# Inform the user of missing dependencies and exit on code 20 if any were found
|
||||
if [ -n "$MISSING" ]; then
|
||||
vns_raise "Missing Dependencies: $MISSING" 20
|
||||
|
||||
# --- Store ---
|
||||
# Verify that the note store has been initialized
|
||||
elif [ ! -d "$VNS_STORE" ]; then
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
vns_init () {
|
||||
|
||||
# init (GPG recipients...)
|
||||
# Prepares $VNS_STORE for use
|
||||
|
||||
# Verify that recipients were specified
|
||||
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
|
||||
|
||||
# Store GPG Recipients for later note creation whether re-encrypting, or
|
||||
# initializing a new store
|
||||
|
||||
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"
|
||||
|
||||
}
|
||||
|
||||
vns_printHelp (){
|
||||
|
||||
# printHelp
|
||||
# Prints help information to stdout
|
||||
|
||||
printf "%s" "usage: vns [-cdelpqr] <notebook/section/name>"
|
||||
printf "\\n%s" " vns -I GPG_RECIPIENT (GPG_RECIPIENTS...)"
|
||||
printf "\\n%s" " vns -h"
|
||||
printf "\\n%s" " vns git ..."
|
||||
printf "\\n"
|
||||
printf "\\n%s" " -c : Create note"
|
||||
printf "\\n%s" " -d : Delete note(s)"
|
||||
printf "\\n%s" " -e : Open note for editing"
|
||||
printf "\\n%s" " -h : Display this message"
|
||||
printf "\\n%s" " -i : import file as note"
|
||||
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" " -m : Merge two or more notes"
|
||||
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"
|
||||
|
||||
}
|
||||
|
||||
vns_list () {
|
||||
|
||||
# list (notebook)
|
||||
# Prints a tree containing all notes in the notebook
|
||||
# If no notebook is specified, all notes are shown
|
||||
|
||||
# Check for default behavior
|
||||
if [ "$#" -lt 1 ]; then
|
||||
local -r "NOTEBOOK"=""
|
||||
printf "%s\\n" "vns"
|
||||
else
|
||||
readonly NOTEBOOK="$1"
|
||||
printf "%s\\n" "$1"
|
||||
fi
|
||||
|
||||
tree --noreport --prune "$VNS_STORE/$NOTEBOOK"\
|
||||
| tail -n +2\
|
||||
| sed s/\.gpg//g
|
||||
|
||||
}
|
||||
|
||||
vns_rm () {
|
||||
|
||||
# rm (note)
|
||||
# removes (note) from the store
|
||||
|
||||
# Verify notes were provided
|
||||
if [ "$#" -lt 1 ]; then
|
||||
vns_raise "Insufficient arguments" 30
|
||||
fi
|
||||
|
||||
while [ "$#" -gt 0 ]; do
|
||||
|
||||
# Verify the note exists
|
||||
if [ ! -r "$VNS_STORE/$1.gpg" ]; then
|
||||
vns_raise "Note does not exist" 31;
|
||||
fi
|
||||
|
||||
# Delete the Note
|
||||
vns_git rm "$VNS_STORE/$1.gpg" > /dev/null
|
||||
vns_git commit -m "Deleted $1" > /dev/null
|
||||
|
||||
# Report success
|
||||
vns_report "Deleted $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 () {
|
||||
|
||||
# create (note)
|
||||
# Create a new note and open it for editing
|
||||
|
||||
local -r VNS_RED_COLOR='\033[0;31m'
|
||||
local -r VNS_RESET_COLOR='\033[0m'
|
||||
local -a create_gpgid="($(vns_gpgid))"
|
||||
if [ "$#" -lt 1 ]; then
|
||||
printf "usage: %s %s\n" "$(basename "$0")" "-c [notebook/section/](name)"
|
||||
return
|
||||
fi
|
||||
|
||||
# Refuse to overwrite a note
|
||||
if [ -r "$VNS_STORE/$1.gpg" ]; then vns_raise "Note already exists" 41; fi
|
||||
|
||||
# If the note belongs to a new notebook, create the notebook
|
||||
if [ ! -d "$(dirname "$1")" ]; then mkdir -p "$VNS_STORE/$(dirname "$1")"; fi
|
||||
|
||||
# Create empty note
|
||||
mkdir -p "$(dirname "$VNS_STORE/$1.gpg")"
|
||||
if [ -n "${VNS_TITLE+isset}" ]; then
|
||||
vns_header "${VNS_TITLE}" | gpg2 --batch "${create_gpgid[@]}" --encrypt -o "$VNS_STORE/$1.gpg" 2>/dev/null
|
||||
else
|
||||
vns_header "$(basename "$1")" | gpg2 --batch "${create_gpgid[@]}" --encrypt -o "$VNS_STORE/$1.gpg" 2>/dev/null
|
||||
fi
|
||||
|
||||
# Edit the note
|
||||
vim "$VNS_STORE/$1.gpg"
|
||||
|
||||
# Update vns_git
|
||||
vns_git add "$VNS_STORE/$1.gpg" > /dev/null
|
||||
vns_git commit -m "Added $1" > /dev/null
|
||||
|
||||
}
|
||||
|
||||
vns_edit () {
|
||||
|
||||
# edit (note)
|
||||
# Open (note) for editing in Vim
|
||||
|
||||
# Verify $1 is bound
|
||||
if [ "$#" -lt 1 ]; then vns_raise "Insufficient arguments" 50; fi
|
||||
|
||||
# Refuse to edit non-existent notes
|
||||
if [ ! -r "$VNS_STORE/$1.gpg" ]; then vns_raise "Note not found: $1" 51; fi
|
||||
|
||||
# Edit the specified note
|
||||
vim "$VNS_STORE/$1.gpg"
|
||||
|
||||
# Update vns_git
|
||||
vns_git add "$VNS_STORE/$1.gpg" > /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 () {
|
||||
|
||||
# import (src) (dest)
|
||||
# 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
|
||||
|
||||
if [ "$#" -lt 2 ]; then
|
||||
printf "usage: %s %s\n" "$(basename "$0")" "-i (source) (destination)"
|
||||
return
|
||||
fi
|
||||
|
||||
if [ ! -f "$1" ]; then
|
||||
vns_raise "Cannot read $1" 92
|
||||
|
||||
elif [ -f "$VNS_STORE/$2" ]; then
|
||||
printf "%s" "Note already exists. Overwrite? (Y/N) "
|
||||
local response=''; read -r response
|
||||
case "$response" in
|
||||
Y|y)
|
||||
rm "$VNS_STORE/$2";;
|
||||
*)
|
||||
vns_raise "User declined overwrite" 0;;
|
||||
esac
|
||||
fi
|
||||
|
||||
#printf "%s:" "Specify GPG Public Key: "
|
||||
#local gpg_key=''; read -r gpg_key
|
||||
|
||||
# Create any necessary directories
|
||||
mkdir -p "$VNS_STORE/$(dirname "$2.gpg")"
|
||||
|
||||
if [ "${1##*.}" == "gpg" ]; then
|
||||
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"
|
||||
|
||||
}
|
||||
|
||||
vns_print () {
|
||||
|
||||
# print (note)
|
||||
# print the given note to stdout
|
||||
|
||||
# Verify $1 is bound
|
||||
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
|
||||
gpg2 --batch -d "$VNS_STORE/$1.gpg"
|
||||
fi
|
||||
}
|
||||
|
||||
vns_mv () {
|
||||
|
||||
# mv (src) (dest)
|
||||
# If (src) is a note in the vns store, mv src dest moves src to dest
|
||||
|
||||
# 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
|
||||
|
||||
# Refuse to overwrite existing notes
|
||||
if [ -r "$VNS_STORE/$2.gpg" ]; then vns_raise "Note $2 already exists" 72; fi
|
||||
|
||||
# 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"
|
||||
|
||||
}
|
||||
|
||||
vns_merge () {
|
||||
|
||||
# merge (output) (notes[])
|
||||
# If notes[] is an array of note names and output is a new note name,
|
||||
# merge (output) (notes[]) concatenates notes[] into output.
|
||||
if [ "$#" -lt 2 ]; then
|
||||
printf "usage: %s %s\n" "$(basename "$0")" "-m (output) (notes...)"
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -r "$VNS_STORE/$1.gpg" ]; then vns_raise "Output file already exists." 82; fi
|
||||
if [ ! -r "$VNS_STORE/$2.gpg" ]; then vns_raise "Could not read $2" 83; fi
|
||||
|
||||
local -r NOTE_NAME="$1"
|
||||
local -r OUTPUT="${VNS_STORE}/${1}.gpg"
|
||||
shift
|
||||
|
||||
vns_gpgcat () {
|
||||
for note in "$@"; do
|
||||
if [ ! -r "$VNS_STORE/$note.gpg" ]; then
|
||||
rm "$VNS_STORE/$1.gpg"
|
||||
vns_raise "Could not read $note" 83;
|
||||
fi
|
||||
|
||||
printf "File: %s\n" "$note"
|
||||
gpg2 --batch -d "$VNS_STORE/$note.gpg" 2>/dev/null
|
||||
printf "\n"
|
||||
done
|
||||
}
|
||||
|
||||
vns_gpgcat "$@" | gpg2 --batch --yes "$(vns_gpgid)" --encrypt -o "$OUTPUT"
|
||||
|
||||
printf "%s" "Remove old notes? (y/N) "
|
||||
local response=''; read -r response
|
||||
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 () {
|
||||
|
||||
if [ "$#" -lt 2 ]; then
|
||||
vns_report "usage: $(basename "$0") -u (source) (destination)"
|
||||
return
|
||||
fi
|
||||
|
||||
if [ ! -f "$VNS_STORE/$1.gpg" ]; then
|
||||
vns_raise "Cannot read $1" 102
|
||||
|
||||
elif [ -f "$VNS_STORE/$2.gpg" ]; then
|
||||
printf "%s" "Note already exists. Overwrite? (Y/N) "
|
||||
response=''; read -r response
|
||||
case "$response" in
|
||||
Y|y)
|
||||
rm "$VNS_STORE/$2.gpg";;
|
||||
*)
|
||||
vns_raise "User declined overwrite" 0;;
|
||||
esac
|
||||
fi
|
||||
mkdir -p "$VNS_STORE/$(dirname $2)"
|
||||
cp "$VNS_STORE/$1.gpg" "$VNS_STORE/$2.gpg"
|
||||
vns_git add "$VNS_STORE/$2.gpg"
|
||||
}
|
||||
|
||||
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 () {
|
||||
# Bypass sanity check if told to initialize store
|
||||
if [ "$1" != "-I" ]; then
|
||||
vns_sanityCheck;
|
||||
fi
|
||||
|
||||
primary_arg="$1"
|
||||
shift
|
||||
case "$primary_arg" in
|
||||
"-c")
|
||||
vns_create "$@"
|
||||
;;
|
||||
"-d")
|
||||
vns_rm "$@"
|
||||
;;
|
||||
"-e")
|
||||
vns_edit "$@"
|
||||
;;
|
||||
"-l")
|
||||
vns_list "$@"
|
||||
;;
|
||||
"-h")
|
||||
vns_printHelp "$@"
|
||||
;;
|
||||
"-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;
|
||||
}
|
||||
vns "$@"
|
||||
@@ -1,72 +0,0 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user