diff --git a/t.sh b/t.sh index 4db1408..d1cd177 100755 --- a/t.sh +++ b/t.sh @@ -4,7 +4,6 @@ trap "exit 1" TERM export MYPID=$$ - . ${HOME}/code/bashtools/bashtools.sh if [[ -z $HAVE_BASHTOOLS ]]; then echo "ERROR: bashtools not installed download from https://git.nethack.net/rob/bashtools" >/dev/stderr @@ -1474,14 +1473,32 @@ EOF } function tasksync() { - local res upcount downcount noun + local res upcount downcount noun="Sync" mode="sync" - if [[ $1 == "-a" ]]; then - noun="Auto-sync" - else - noun="Sync" + while [[ $# -ge 1 ]]; do + if [[ $1 == "-a" ]]; then + noun="Auto-sync" + elif [[ $1 == "push" ]]; then + mode="push" + noun="Push" + elif [[ $1 == "pull" ]]; then + mode="pull" + noun="Pull" + fi + shift + done + notify "${noun}ing tasks" + + # adjust conflict resolution + ## remove existing setting + sed -i '/^conflict/ s/^/#/' $vdirsyncconfig + ## add new one + if [[ $mode == "push" ]]; then + sed -i '/conflict.*a wins/ s/^#\+//' $vdirsyncconfig + elif [[ $mode == "pull" ]]; then + sed -i '/conflict.*b wins/ s/^#\+//' $vdirsyncconfig fi - notify "Syncing tasks" + res=$(${VDIRSYNCER} sync 2>&1) rv=$? [[ $rv -eq 0 ]] && ok || fail @@ -1503,9 +1520,24 @@ function tasksync() { inform "$noun complete - $upcount change$upess pushed, $downcount change$downess pulled." fi else - error "$noun failed. Output:" - echo "$res" | sed -e 's/^/ /' + errmsg="$noun failed." + if [[ $mode == "sync" ]]; then + errmsg="${errmsg} Try ^bt push^p or ^bt pull^p." + fi + error "$errmsg" + if [[ $mode != "sync" ]]; then + cecho -s "$RED" "^bDetails:^p" + cecho -s "$RED" "$res" | sed -e 's/^/ /' + echo + cecho -s "$RED" "^bConflict settings:^p" + errmsg=$(grep "conflict" $vdirsyncconfig 2>&1) + cecho -s "$YELLOW" "$errmsg" | sed -e 's/^/ /' + fi fi + + ## remove conflict setting again + sed -i '/^conflict/ s/^/#/' $vdirsyncconfig + } function getcals() { # countvar arrayvar @@ -1634,6 +1666,7 @@ addcmd "note" "note " "Change notes for given task" "note|desc|descr addcmd "tag" "tag " "Add a tag to the given task" "tag|t" addcmd "untag" "untag " "Remove a tag from the given task" "untag|ut" addcmd "sync" "sync" "Sync tasks using vdirsyncer" "sync" +addcmd "push" "push" "Push all tasks to server" "push" addcmd "view" "view " "Show detailed info for given task" "v|view|info|vcal" PASSIVE addcmd "showcals" "showcals" "List available calendars" "cals|showcals|cls" PASSIVE addcmd "setcal" "setcal" "Set the default calendar." "setcal|sc" @@ -1745,6 +1778,9 @@ fi if [[ $mode == "sync" ]]; then tasksync exit $rv +elif [[ $mode == "push" ]]; then + tasksync push + exit $rv fi notify "Processing"