Initial work on adding git support for backups.
This commit is contained in:
@@ -108,6 +108,11 @@ add_note() {
|
|||||||
$editor "${xdgPath}/notestorm/notes/${noteName}.md"
|
$editor "${xdgPath}/notestorm/notes/${noteName}.md"
|
||||||
if [ -f "${xdgPath}/notestorm/notes/${noteName}.md" ]; then
|
if [ -f "${xdgPath}/notestorm/notes/${noteName}.md" ]; then
|
||||||
infobox "Note added."
|
infobox "Note added."
|
||||||
|
if [[ -d "$xdgPath/notestorm/notes/.git" ]]; then
|
||||||
|
{ git -C "$xdgPath/notestorm/notes" add -A
|
||||||
|
git -C "$xdgPath/notestorm/notes" commit -m "$(*gettext "Automatic push from notestorm, note added.")"
|
||||||
|
git -C "$xdgPath/notestorm/notes" push -q ; } | dialog --progressbox "$(gettext "Pushing to git...")" -1 -1
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
infobox "Note canceled."
|
infobox "Note canceled."
|
||||||
fi
|
fi
|
||||||
@@ -133,6 +138,11 @@ delete_note() {
|
|||||||
if [ "$answer" == "Yes" ]; then
|
if [ "$answer" == "Yes" ]; then
|
||||||
rm -f "$1"
|
rm -f "$1"
|
||||||
infobox "$(gettext "Note deleted.")"
|
infobox "$(gettext "Note deleted.")"
|
||||||
|
if [[ -d "$xdgPath/notestorm/notes/.git" ]]; then
|
||||||
|
{ git -C "$xdgPath/notestorm/notes" rm -f "$1"
|
||||||
|
git -C "$xdgPath/notestorm/notes" commit -m "$(*gettext "Automatic push from notestorm, note deleted.")"
|
||||||
|
git -C "$xdgPath/notestorm/notes" push -q ; } | dialog --progressbox "$(gettext "Pushing to git...")" -1 -1
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
infobox "$(gettext "Action canceled.")"
|
infobox "$(gettext "Action canceled.")"
|
||||||
fi
|
fi
|
||||||
@@ -162,6 +172,11 @@ edit_note() {
|
|||||||
local newMd5="$(md5sum "$1")"
|
local newMd5="$(md5sum "$1")"
|
||||||
if [ "$oldMd5" != "$newMd5" ]; then
|
if [ "$oldMd5" != "$newMd5" ]; then
|
||||||
infobox "$(gettext "Changes saved.")"
|
infobox "$(gettext "Changes saved.")"
|
||||||
|
if [[ -d "$xdgPath/notestorm/notes/.git" ]]; then
|
||||||
|
{ git -C "$xdgPath/notestorm/notes" add -A
|
||||||
|
git -C "$xdgPath/notestorm/notes" commit -m "$(*gettext "Automatic push from notestorm, note updated.")"
|
||||||
|
git -C "$xdgPath/notestorm/notes" push -q ii; } | dialog --progressbox "$(gettext "Pushing to git...")" -1 -1
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
infobox "$(gettext "Changes discarded.")"
|
infobox "$(gettext "Changes discarded.")"
|
||||||
fi
|
fi
|
||||||
@@ -182,6 +197,12 @@ encrypt_note() {
|
|||||||
if gpg -o "${1%/*}/${noteName%.md*}.md.gpg" -c "$1" ; then
|
if gpg -o "${1%/*}/${noteName%.md*}.md.gpg" -c "$1" ; then
|
||||||
rm -f "$1"
|
rm -f "$1"
|
||||||
infobox "$(gettext "Note encrypted.")"
|
infobox "$(gettext "Note encrypted.")"
|
||||||
|
if [[ -d "$xdgPath/notestorm/notes/.git" ]]; then
|
||||||
|
{ git -C "$xdgPath/notestorm/notes" add -A
|
||||||
|
git rm -f "$1"
|
||||||
|
git -C "$xdgPath/notestorm/notes" commit -m "$(*gettext "Automatic push from notestorm, note encrypted.")"
|
||||||
|
git -C "$xdgPath/notestorm/notes" push -q ; } | dialog --progressbox "$(gettext "Pushing to git...")" -1 -1
|
||||||
|
fi
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
infobox "$(gettext "Encryption failed.")"
|
infobox "$(gettext "Encryption failed.")"
|
||||||
@@ -195,6 +216,28 @@ list_notes() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initialize_git() {
|
||||||
|
local message
|
||||||
|
if [[ -d "$xdgPath/notestorm/notes/.git" ]]; then
|
||||||
|
message="$(gettext "A git configuration already exists.")"
|
||||||
|
infobox "$message"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
message="$(gettext "Please enter the url to your git repository for notes.")"
|
||||||
|
local gitURL="$(inputbox "$message")"
|
||||||
|
if [[ ${#gitURL} -lt 3 ]]; then
|
||||||
|
message="$(gettext "Invalid URL detected, exiting.")"
|
||||||
|
infobox "$message"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
{ git -C "$xdgPath/notestorm/notes" init
|
||||||
|
git -C "$xdgPath/notestorm/notes" remote add origin "$gitURL"
|
||||||
|
git -C "$xdgPath/notestorm/notes" add -A
|
||||||
|
git -C "$xdgPath/notestorm/notes" commit -m "Initial commit added by notestorm"
|
||||||
|
git -C "$xdgPath/notestorm/notes" push -u origin master ; } | dialog --progressbox "$(gettext "Setting up git...")" -1 -1
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
original_note() {
|
original_note() {
|
||||||
# If no notes are present this will try to copy the README.md file into the notes directory so the menu won't fail.
|
# If no notes are present this will try to copy the README.md file into the notes directory so the menu won't fail.
|
||||||
mapfile -t notes < <(find "$xdgPath/notestorm/notes" -type f -iname '*.md' -o -iname '*.gpg')
|
mapfile -t notes < <(find "$xdgPath/notestorm/notes" -type f -iname '*.md' -o -iname '*.gpg')
|
||||||
@@ -210,9 +253,11 @@ original_note() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Configuration section
|
# Configuration section
|
||||||
# Available arguments in both long and short versions stored in associative array.
|
# Available arguments in both long and short versions stored in associative array.
|
||||||
declare -A argList=(
|
declare -A argList=(
|
||||||
|
[g]="git"
|
||||||
[l]="list"
|
[l]="list"
|
||||||
[n]="new")
|
[n]="new")
|
||||||
# Make the args a continuous string.
|
# Make the args a continuous string.
|
||||||
@@ -262,6 +307,7 @@ fi
|
|||||||
# Parse non-numeric command line args.
|
# Parse non-numeric command line args.
|
||||||
if ! options=$(getopt -o "$short" -l "$long" -n "notestorm" -- "$@"); then
|
if ! options=$(getopt -o "$short" -l "$long" -n "notestorm" -- "$@"); then
|
||||||
gettext -e "Usage: notestorm launch interactive session.\n"
|
gettext -e "Usage: notestorm launch interactive session.\n"
|
||||||
|
gettext -e -- "-g or --git set up backups to git. Requires existing git repository with branch name \"master\".\n"
|
||||||
gettext -e -- "-n or --new add a new note without opening an interactive session.\n"
|
gettext -e -- "-n or --new add a new note without opening an interactive session.\n"
|
||||||
echo
|
echo
|
||||||
gettext -e "You can use markdown syntax in notes.\n"
|
gettext -e "You can use markdown syntax in notes.\n"
|
||||||
@@ -277,8 +323,9 @@ eval set -- "$options"
|
|||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
"-n"|"--new") add_note;;
|
"-g"|"--git") initialize_git;;
|
||||||
"-l"|"--list") list_notes;;
|
"-l"|"--list") list_notes;;
|
||||||
|
"-n"|"--new") add_note;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user