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 TEXTDOMAIN=notestorm
|
||||||
export TEXTDOMAINDIR=/usr/share/locale
|
export TEXTDOMAINDIR=/usr/share/locale
|
||||||
source gettext.sh
|
source gettext.sh
|
||||||
|
# Track modifications to notes
|
||||||
|
unset modified
|
||||||
|
|
||||||
|
|
||||||
# Functions section
|
# 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() {
|
infobox() {
|
||||||
# Returns: None
|
# Returns: None
|
||||||
# Shows the provided message on the screen with no buttons.
|
# Shows the provided message on the screen with no buttons.
|
||||||
@@ -106,13 +123,15 @@ add_note() {
|
|||||||
((noteName++))
|
((noteName++))
|
||||||
done
|
done
|
||||||
$editor "${xdgPath}/notestorm/notes/${noteName}.md"
|
$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
|
if [ -f "${xdgPath}/notestorm/notes/${noteName}.md" ]; then
|
||||||
|
modified="note added"
|
||||||
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 ; } | dialog --progressbox "$(gettext "Pushing to git...")" -1 -1
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
infobox "Note canceled."
|
infobox "Note canceled."
|
||||||
fi
|
fi
|
||||||
@@ -139,9 +158,8 @@ delete_note() {
|
|||||||
rm -f "$1"
|
rm -f "$1"
|
||||||
infobox "$(gettext "Note deleted.")"
|
infobox "$(gettext "Note deleted.")"
|
||||||
if [[ -d "$xdgPath/notestorm/notes/.git" ]]; then
|
if [[ -d "$xdgPath/notestorm/notes/.git" ]]; then
|
||||||
{ git -C "$xdgPath/notestorm/notes" rm -f "$1"
|
git -C "$xdgPath/notestorm/notes" rm -f "$1" &&
|
||||||
git -C "$xdgPath/notestorm/notes" commit -m "$(gettext "Automatic push from notestorm, note deleted.")"
|
modified="note deleted"
|
||||||
git -C "$xdgPath/notestorm/notes" push ; } | dialog --progressbox "$(gettext "Pushing to git...")" -1 -1
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
infobox "$(gettext "Action canceled.")"
|
infobox "$(gettext "Action canceled.")"
|
||||||
@@ -172,11 +190,7 @@ 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
|
modified="note updated"
|
||||||
{ 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
|
|
||||||
else
|
else
|
||||||
infobox "$(gettext "Changes discarded.")"
|
infobox "$(gettext "Changes discarded.")"
|
||||||
fi
|
fi
|
||||||
@@ -197,12 +211,7 @@ 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
|
modified="encrypted note added"
|
||||||
{ 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
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
infobox "$(gettext "Encryption failed.")"
|
infobox "$(gettext "Encryption failed.")"
|
||||||
@@ -330,6 +339,8 @@ while [ $# -gt 0 ]; do
|
|||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
# If there were args, the program was controled by those and we do not need the menu.
|
# If there were args, the program was controled by those and we do not need the menu.
|
||||||
if [ $argNum -gt 0 ]; then
|
if [ $argNum -gt 0 ]; then
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
Reference in New Issue
Block a user