小雨宙

Let's debug the world.

todo.sh

随手写的一个命令行计划管理脚本 https://github.com/rains31/todo.sh


#!/bin/bash
# Author: rain31(at)gmail.com

umask 0177
TODO=$HOME/todo.txt
[ -f $TODO ] || touch $TODO 
case $1 in
    "-a"|"--add")
        shift
        echo "[ ] $*" >> "$TODO"
        echo add "'$*'" into todo.txt.
        ;;

    "-d"|"--done")
        [ -z $2 ] && echo "Usage: $0 $1 lineNum[,toLineNum]" && exit
        sed -i "$2s/\[ \]/\[x\]/" "$TODO"
        ;;

    "-u"|"--undo")
        [ -z $2 ] && echo "Usage: $0 $1 lineNum[,toLineNum]" && exit
        sed -i "$2s/\[x\]/\[ \]/" "$TODO"
        ;;

    "-D"|"--del"|"--delete")
        [ -z $2 ] && echo "Usage: $0 $1 lineNum[,toLineNum]" && exit
        sed -i "$2d" "$TODO"
        ;;

    "-r"|"--recycle")
        sed -i '/^\[x\]/d' "$TODO"
        ;;

    "-l"|"--list"|"")
        cat "$TODO" | awk '{printf("\033[%d;37m"NR" "$0"\033[m\n",$1=="[x]"?9:1);}' 
        ;;
    "-h"|"--help")
        echo -e "Usage:\n\t" \
                "$0 -a add\n\t" \
                "$0 -d done\n\t" \
                "$0 -D delete\n\t" \
                "$0 -r recycle\n\t" \
                "$0 -l list\n\t" \
                "$0 -h this help"
        ;;

    *)
        $0 -a "$*"
        ;;
esac

博文最后更新时间:


评论

  • 暂无评论

发表评论

博客统计

访问量:3615

博文总数:9 评论总数:1

原创9 翻译0 转载0