Added 'gen' command to renumber all task IDs
This commit is contained in:
parent
4752528d48
commit
4c29f1a4a0
66
t.sh
66
t.sh
|
@ -18,7 +18,7 @@ if [[ -z $HAVE_BASHTOOLS ]]; then
|
|||
fi
|
||||
|
||||
INFORMCOL="$GREEN"
|
||||
INFORMCOLB="$GREENBOLD"
|
||||
INFORMCOLB="$GREEN$BOLD"
|
||||
|
||||
brack="$CYAN"
|
||||
brackfold="$CYAN"
|
||||
|
@ -1705,6 +1705,7 @@ vdirsyncconfig="${vdirsyncdir}/config"
|
|||
printed=0
|
||||
rows=$(tput lines)
|
||||
|
||||
|
||||
addcmd "list" "list [id1] .. [idX]" "List [just the specified] tasks" "list|ls|show" SUPPORTS_ALL PASSIVE
|
||||
addcmd "fold" "fold <id>" "Fold a parent task (hide its children)" "fold|f|zc" SUPPORTS_ALL
|
||||
addcmd "unfold" "unfold <id>" "Unfold a parent task (show its children)" "unfold|u|zo" SUPPORTS_ALL
|
||||
|
@ -1728,6 +1729,7 @@ addcmd "push" "push" "Push all tasks to server" "push"
|
|||
addcmd "view" "view <id>" "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"
|
||||
addcmd "renumber" "renumber" "Re-generate IDs for all tasks with lowest possible numbers" "rn|gen"
|
||||
|
||||
[[ ! -e $cachedir ]] && mkdir -p "$cachedir"
|
||||
|
||||
|
@ -1848,6 +1850,67 @@ if [[ $mode == "sync" ]]; then
|
|||
elif [[ $mode == "push" ]]; then
|
||||
tasksync push
|
||||
exit $rv
|
||||
elif [[ $mode == "renumber" ]]; then
|
||||
idfilebackup="$idfile.bak.$(date +%Y%m%d%H%M%S)"
|
||||
idfilenew=$(mktemp /tmp/newid.XXXXXXXX)
|
||||
|
||||
# figure out what summing program to use
|
||||
sumprog=""
|
||||
for x in md5 md5sum; do
|
||||
which $x >/dev/null 2>&1
|
||||
if [[ $? -eq 0 ]]; then
|
||||
sumprog="$x"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [[ -n $sumprog ]]; then
|
||||
notify "Checking current task IDs"
|
||||
cat "$idfile" | awk 'BEGIN { id=1; FS=":"; } /.*:.*/{ print $1 ":" id++; } ' > "$idfilenew"
|
||||
md5old=$($sumprog "$idfile")
|
||||
md5new=$($sumprog "$idfilenew")
|
||||
if [[ $sumprog == "md5" ]]; then
|
||||
md5old=$(echo "$md5old" | awk '{ print $NF }')
|
||||
md5new=$(echo "$md5new" | awk '{ print $NF }')
|
||||
else
|
||||
md5old=$(echo "$md5old" | awk '{ print $1 }')
|
||||
md5new=$(echo "$md5new" | awk '{ print $1 }')
|
||||
fi
|
||||
ok
|
||||
if [[ $md5old == $md5new ]]; then
|
||||
inform "No changes required based on checksums."
|
||||
echo "old: $md5sumold"
|
||||
echo "new: $md5sumnew"
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
warn "No checksumming program found - install md5 or md5sum."
|
||||
fi
|
||||
oldmin=$(cat "$idfile" | cut -d: -f2 | sort -nr | tail -1)
|
||||
oldmax=$(cat "$idfile" | cut -d: -f2 | sort -n | tail -1)
|
||||
min=$(cat "$idfilenew" | cut -d: -f2 | sort -nr | tail -1)
|
||||
max=$(cat "$idfilenew" | cut -d: -f2 | sort -n | tail -1)
|
||||
if [[ $oldmin -eq $min && $newmin -eq $min ]]; then
|
||||
inform "No changes required based on task IDs."
|
||||
exit 0
|
||||
fi
|
||||
inform "This process will renumber all tasks:"
|
||||
inform " Current ID range: ^b$oldmin^p-^b$oldmax^p"
|
||||
inform " New ID range: ^b$min^p-^b$max^p"
|
||||
confirm "Really proceed"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
inform "Aborted."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
notify "Backing up mapping file to ^b$idfilebackup^p"
|
||||
cp -a "$idfile" "$idfilebackup"
|
||||
[[ $? -eq 0 ]] && ok || { fail; exit 1; }
|
||||
notify "Re-generating task IDs"
|
||||
mv -f "$idfilenew" "$idfile"
|
||||
[[ $? -eq 0 ]] && ok || { fail; exit 1; }
|
||||
|
||||
inform "Task ID renumbering complete."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
notify "Processing"
|
||||
|
@ -1855,7 +1918,6 @@ loadids || exit 1
|
|||
loadtasks || exit 1
|
||||
ok
|
||||
|
||||
|
||||
if [[ $MAINTMODE -eq 1 ]]; then
|
||||
# check for id mappings with missing tasks
|
||||
notify "Checking ID mappings"
|
||||
|
|
Loading…
Reference in New Issue