Changed the way notes get pushed to git.
This commit is contained in:
49
notestorm
49
notestorm
@@ -26,10 +26,27 @@
|
||||
export TEXTDOMAIN=notestorm
|
||||
export TEXTDOMAINDIR=/usr/share/locale
|
||||
source gettext.sh
|
||||
# Track modifications to notes
|
||||
unset modified
|
||||
|
||||
|
||||
# Functions section
|
||||
|
||||
cleanup() {
|
||||
if [[ ${#modified} -lt 1 ]]; then
|
||||
exit 0
|
||||
fi
|
||||
if [[ ! -d "$xdgPath/notestorm/notes/.git" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
if [[ "$(yesno "Push changes to git?")" == "No" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
git -C "$xdgPath/notestorm/notes" add -A :/
|
||||
git -C "$xdgPath/notestorm/notes" commit -m "$(gettext "Automatic push from notestorm, ${modified}.")"
|
||||
git -C "$xdgPath/notestorm/notes" push
|
||||
}
|
||||
|
||||
infobox() {
|
||||
# Returns: None
|
||||
# Shows the provided message on the screen with no buttons.
|
||||
@@ -106,13 +123,15 @@ add_note() {
|
||||
((noteName++))
|
||||
done
|
||||
$editor "${xdgPath}/notestorm/notes/${noteName}.md"
|
||||
newName="$(head -n 1 "${xdgPath}/notestorm/notes/${noteName}.md")"
|
||||
newName="${newName//[[:space:]]/_}"
|
||||
if [[ ! -e "${xdgPath}/notestorm/notes/${newName}.md" ]]; then
|
||||
mv "${xdgPath}/notestorm/notes/${noteName}.md" "${xdgPath}/notestorm/notes/${newName}.md"
|
||||
noteName="${newName}"
|
||||
fi
|
||||
if [ -f "${xdgPath}/notestorm/notes/${noteName}.md" ]; then
|
||||
modified="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 ; } | dialog --progressbox "$(gettext "Pushing to git...")" -1 -1
|
||||
fi
|
||||
else
|
||||
infobox "Note canceled."
|
||||
fi
|
||||
@@ -139,9 +158,8 @@ delete_note() {
|
||||
rm -f "$1"
|
||||
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 ; } | dialog --progressbox "$(gettext "Pushing to git...")" -1 -1
|
||||
git -C "$xdgPath/notestorm/notes" rm -f "$1" &&
|
||||
modified="note deleted"
|
||||
fi
|
||||
else
|
||||
infobox "$(gettext "Action canceled.")"
|
||||
@@ -172,11 +190,7 @@ edit_note() {
|
||||
local newMd5="$(md5sum "$1")"
|
||||
if [ "$oldMd5" != "$newMd5" ]; then
|
||||
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 ; } | dialog --progressbox "$(gettext "Pushing to git...")" -1 -1
|
||||
fi
|
||||
modified="note updated"
|
||||
else
|
||||
infobox "$(gettext "Changes discarded.")"
|
||||
fi
|
||||
@@ -197,12 +211,7 @@ encrypt_note() {
|
||||
if gpg -o "${1%/*}/${noteName%.md*}.md.gpg" -c "$1" ; then
|
||||
rm -f "$1"
|
||||
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 ; } | dialog --progressbox "$(gettext "Pushing to git...")" -1 -1
|
||||
fi
|
||||
modified="encrypted note added"
|
||||
return
|
||||
fi
|
||||
infobox "$(gettext "Encryption failed.")"
|
||||
@@ -330,6 +339,8 @@ while [ $# -gt 0 ]; do
|
||||
shift
|
||||
done
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
# If there were args, the program was controled by those and we do not need the menu.
|
||||
if [ $argNum -gt 0 ]; then
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user