~mapperr/tsk

ee4bc0a577fde018ee688f51480dc5b668d77d26 — mapperr 1 year, 9 months ago 07779ae
WIP Move task
1 files changed, 42 insertions(+), 0 deletions(-)

M tsk
M tsk => tsk +42 -0
@@ 26,6 26,9 @@ $name edit | e task_id
$name rm | r task_id
    removes a task

$name mv | m task_id to_task_id
    moves a task to another id, shifting ids of other tasks

$name git | g [git_args]
    runs 'git git_args' in the task directory



@@ 122,6 125,19 @@ get_new_id() {
    fi
}

compact_ids() {
    id_list=`get_task_id_list | sort -n`
    counter=1
    cd $taskdir
    for id_ in $id_list; do
        if [ $id_ -ne $counter ]; then
            mv $id_.md $counter.md
        fi
        counter=`expr $counter + 1`
    done
    cd - >/dev/null 2>&1
}

add_task() {
    newid=`get_new_id`
    newfile=$taskdir/$newid.md


@@ 146,12 162,29 @@ remove_task() {
    read c
    if test "$c" = "y" || test "$c" = "Y"; then
        rm -f $task_file
        compact_ids
        echo "task $task_id removed"
    else
        echo "aborted"
    fi
}

move_task() {
    local from="$1"
    local to="$2"

    id_list=`get_task_id_list | sort -n`
    for id_ in $id_list; do
        if test "$id_" = "$to"; then
            cd $taskdir
            mv $to.md $to-moving.md
            mv $from.md $to.md
            mv $to-moving.md $from.md
            cd - >/dev/null 2>&1
        fi
    done
}

clean_tasks() {
    echo -n "delete all tasks (y/n)? "
    read c


@@ 177,6 210,15 @@ elif [ "$cmd" = "edit" ] || [ "$cmd" = "e" ]; then
elif [ "$cmd" = "rm" ] || [ "$cmd" = "r" ]; then
    remove_task $1

elif [ "$cmd" = "mv" ] || [ "$cmd" = "m" ]; then
    from="$1"
    to="$2"
    if test -z "$from" || test -z "$to"; then
        helpmsg
        exit 1
    fi
    move_task $from $to

elif [ "$cmd" = "git" ] || [ "$cmd" = "g" ]; then
    cd $taskdir
    git $@