From 338af44841e09e4e12155efd3333c90ed862716b Mon Sep 17 00:00:00 2001 From: Cuan Date: Thu, 7 Oct 2021 16:15:02 -0400 Subject: [PATCH] Added multi-line notes support --- bin/{rpass => rpass.py} | 67 +++++++++++++++++++++++++++++---------- share/doc/rpass/changelog | 19 +++++++---- 2 files changed, 62 insertions(+), 24 deletions(-) rename bin/{rpass => rpass.py} (92%) diff --git a/bin/rpass b/bin/rpass.py similarity index 92% rename from bin/rpass rename to bin/rpass.py index d98ccb2..962ee42 100755 --- a/bin/rpass +++ b/bin/rpass.py @@ -23,10 +23,10 @@ def term(cmd): def replace_line(file_name, line_num, text): - lines = open(file_name, 'r').readlines() - lines[line_num] = text + xlines = open(file_name, 'r').readlines() + xlines[line_num] = text out = open(file_name, 'w') - out.writelines(lines) + out.writelines(xlines) out.close() @@ -101,8 +101,8 @@ if argument == 'version' or argument == '-v': print('/ /') print('/ rpass Copyright (C) 2021 Randall Winkhart /') print('/ /') - print('/ Version 2021.10.08.mr5 /') - print('/ The Housekeeping Update (Pt. 2) /') + print('/ Version 2021.10.08.mr5 /') + print('/ The Notetaker Update /') print('/ /') print('////////////////////////////////////////////////////////\n') @@ -263,28 +263,30 @@ if argument == 'add note' or argument == 'add -n': try: clear() entryname = str(input('Name of note: ')) - notes = str(input('Contents of note: ')) except KeyboardInterrupt: entryname, notes = (0, 0) print('\n\nEntry add cancelled.\n') exit() shmfolder, shmentry = shmgen() + term('nano /dev/shm/' + shmfolder + '/' + shmentry + '-n') + with open('/dev/shm/' + shmfolder + '/' + shmentry + '-n', 'r') as file: + notes = file.read().replace('/n', '') try: if entryname.startswith('/'): # check if user input contains slashes if entryname.replace('/', '', 1).__contains__('/'): # create folder and entry if there are two slashes folder, sep, folderentry = entryname.replace('/', '', 1).partition('/') with open('/dev/shm/' + shmfolder + '/' + shmentry, 'w') as f: - f.writelines('\n\n\n' + notes + '\n\n') + f.writelines('\n\n\n\n' + notes + '\n\n') encryptfolder() term('gpg -d ' + directory + folder + '/' + "'" + folderentry + '.gpg' + "'") else: # create entry if there is only one slash with open('/dev/shm/' + shmfolder + '/' + shmentry, 'w') as f: - f.writelines('\n\n\n' + notes + '\n\n') + f.writelines('\n\n\n\n' + notes + '\n\n') encrypt() term('gpg -d ' + directory + "'" + entryname.replace('/', '', 1) + '.gpg' + "'") else: # create entry if there are no slashes with open('/dev/shm/' + shmfolder + '/' + shmentry, 'w') as f: - f.writelines('\n\n\n' + notes + '\n\n') + f.writelines('\n\n\n\n' + notes + '\n\n') encrypt() term('gpg -d ' + directory + "'" + entryname + '.gpg' + "'") except FileNotFoundError: @@ -301,28 +303,30 @@ if argument == 'add password' or argument == 'add -p': username = str(input('Username: ')) password = str(input('Password: ')) url = str(input('URL: ')) - notes = str(input('Additional notes: ')) except KeyboardInterrupt: entryname, username, password, url, notes = (0, 0, 0, 0, 0) print('\n\nEntry add cancelled.\n') exit() shmfolder, shmentry = shmgen() + term('nano /dev/shm/' + shmfolder + '/' + shmentry + '-n') + with open('/dev/shm/' + shmfolder + '/' + shmentry + '-n', 'r') as file: + notes = file.read().replace('/n', '') try: if entryname.startswith('/'): if entryname.replace('/', '', 1).__contains__('/'): folder, sep, folderentry = entryname.replace('/', '', 1).partition('/') with open('/dev/shm/' + shmfolder + '/' + shmentry, 'w') as f: - f.writelines(username + '\n' + password + '\n' + url + '\n' + notes + '\n\n') + f.writelines(username + '\n' + password + '\n' + url + '\n\n' + notes + '\n\n') encryptfolder() term('gpg -d ' + directory + folder + '/' + "'" + folderentry + '.gpg' + "'") else: with open('/dev/shm/' + shmfolder + '/' + shmentry, 'w') as f: - f.writelines(username + '\n' + password + '\n' + url + '\n' + notes + '\n\n') + f.writelines(username + '\n' + password + '\n' + url + '\n\n' + notes + '\n\n') encrypt() term('gpg -d ' + directory + "'" + entryname.replace('/', '', 1) + '.gpg' + "'") else: with open('/dev/shm/' + shmfolder + '/' + shmentry, 'w') as f: - f.writelines(username + '\n' + password + '\n' + url + '\n' + notes + '\n\n') + f.writelines(username + '\n' + password + '\n' + url + '\n\n' + notes + '\n\n') encrypt() term('gpg -d ' + directory + "'" + entryname + '.gpg' + "'") except FileNotFoundError: @@ -505,7 +509,6 @@ if argument == 'edit note' or argument == 'edit -n': term('cd ' + directory + '; ls -1 *') print() entryname = str(input('What file would you like to edit? ')) - notes = str(input('New Note: ')) except KeyboardInterrupt: entryname, notes = (0, 0) print('\n\nEdit cancelled.\n') @@ -517,20 +520,50 @@ if argument == 'edit note' or argument == 'edit -n': folder, sep, folderentry = entryname.replace('/', '', 1).partition('/') term('gpg -d --output /dev/shm/' + shmfolder + '/' + shmentry + ' ' + directory + folder + '/' + folderentry + '.gpg') - replace_line('/dev/shm/' + shmfolder + '/' + shmentry, 3, notes + '\n') + with open('/dev/shm/' + shmfolder + '/' + shmentry) as first: + lines = first.readlines() + with open('/dev/shm/' + shmfolder + '/' + shmentry, 'w') as first: + first.writelines(lines[0:3]) + with open('/dev/shm/' + shmfolder + '/' + shmentry + '-n', 'w') as second: + second.writelines(lines[4:-2]) + term('nano /dev/shm/' + shmfolder + '/' + shmentry + '-n') + with open('/dev/shm/' + shmfolder + '/' + shmentry + '-n') as second: + notes = second.read() + with open('/dev/shm/' + shmfolder + '/' + shmentry, 'a') as first: + first.write('\n' + notes + '\n\n') remove(directory + folder + '/' + folderentry + '.gpg') encryptfolder() term('gpg -d ' + directory + folder + '/' + "'" + folderentry + '.gpg' + "'") else: term('gpg -d --output /dev/shm/' + shmfolder + '/' + shmentry + ' ' + directory + entryname.replace('/', '', 1) + '.gpg') - replace_line('/dev/shm/' + shmfolder + '/' + shmentry, 3, notes + '\n') + with open('/dev/shm/' + shmfolder + '/' + shmentry) as first: + lines = first.readlines() + with open('/dev/shm/' + shmfolder + '/' + shmentry, 'w') as first: + first.writelines(lines[0:3]) + with open('/dev/shm/' + shmfolder + '/' + shmentry + '-n', 'w') as second: + second.writelines(lines[4:-2]) + term('nano /dev/shm/' + shmfolder + '/' + shmentry + '-n') + with open('/dev/shm/' + shmfolder + '/' + shmentry + '-n') as second: + notes = second.read() + with open('/dev/shm/' + shmfolder + '/' + shmentry, 'a') as first: + first.write('\n' + notes + '\n\n') remove(directory + entryname.replace('/', '', 1) + '.gpg') encrypt() term('gpg -d ' + directory + "'" + entryname.replace('/', '', 1) + '.gpg' + "'") else: term('gpg -d --output /dev/shm/' + shmfolder + '/' + shmentry + ' ' + directory + entryname + '.gpg') - replace_line('/dev/shm/' + shmfolder + '/' + shmentry, 3, notes + '\n') + with open('/dev/shm/' + shmfolder + '/' + shmentry) as first: + lines = first.readlines() + with open('/dev/shm/' + shmfolder + '/' + shmentry, 'w') as first: + first.writelines(lines[0:3]) + with open('/dev/shm/' + shmfolder + '/' + shmentry + '-n', 'w') as second: + second.writelines(lines[4:-2]) + term('nano /dev/shm/' + shmfolder + '/' + shmentry + '-n') + with open('/dev/shm/' + shmfolder + '/' + shmentry + '-n') as second: + notes = second.read() + with open('/dev/shm/' + shmfolder + '/' + shmentry, 'a') as first: + first.write('\n' + notes + '\n\n') remove(directory + entryname + '.gpg') encrypt() term('gpg -d ' + directory + "'" + entryname + '.gpg' + "'") diff --git a/share/doc/rpass/changelog b/share/doc/rpass/changelog index 0d68c5e..19383b2 100755 --- a/share/doc/rpass/changelog +++ b/share/doc/rpass/changelog @@ -2,27 +2,32 @@ rpass 2021.10.08.mr5 -The Housekeeping Update (Pt. 2) - Fifth main release of rpass +The Notetaker Update - Fifth main release of rpass This release focuses on user-facing polish and usability enhancements. New features: -**add new file list w/color and w/o extensions -**add support for multi-line notes (use text editor for notes) +- notes are now edited in nano and can be split across multiple lines Changes: - fixed issues with copying passwords with certain special characters, e.g. '"()| - auto-generated ssh key now uses ed25519, rather than rsa-3072 -**add more comments to code -**improve exceptions for unknown arguments -Planned for next update (The rcrypt Update): +Planned for next update (The Housekeeping Update Pt. 2): -- initial implementation of a data store for other applications (libsecret alt.) +- add new file list w/color and w/o extensions +- improve exceptions for unknown arguments - ability to pass entries as arguments for more functions - manpage +- add more comments to code +- simplify code from the Notetaker Update + +Planned for next update (The cryptpass Update): + +- initial implementation of a data store for other applications (libsecret alt.) +- modularize code in preparation for GUI frontends Planned, no timeline: