Small changes
This commit is contained in:
parent
a07678ca1a
commit
0d68560bb9
3 changed files with 68 additions and 1 deletions
60
bin/.bin/todo
Executable file
60
bin/.bin/todo
Executable file
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Simple todo list
|
||||
|
||||
FILE="$HOME/.todo"
|
||||
|
||||
function is_int() {
|
||||
return $(test "$@" -eq "$@" > /dev/null 2>&1);
|
||||
}
|
||||
|
||||
function list(){
|
||||
if [ -f "$FILE" ]; then
|
||||
awk '{printf("%5d : %s\n", NR,$0)}' "$FILE"
|
||||
else
|
||||
echo "$FILE does not exist"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function add(){
|
||||
echo "$@" >> "$FILE"
|
||||
}
|
||||
|
||||
function delete(){
|
||||
while [ -n "$1" ]; do
|
||||
if is_int "$1"; then
|
||||
sed -i "${1}d" "$FILE"
|
||||
fi
|
||||
shift
|
||||
done
|
||||
exit
|
||||
}
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
while [ -n "$1" ]; do
|
||||
case "$1" in
|
||||
"list"|"l")
|
||||
shift
|
||||
list "$@"
|
||||
exit 0
|
||||
;;
|
||||
"add"|"a")
|
||||
shift
|
||||
add "$@"
|
||||
exit 0
|
||||
;;
|
||||
"delete"|"del"|"d")
|
||||
shift
|
||||
delete "$@"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Command $1 unknown"
|
||||
exit 1
|
||||
esac
|
||||
done
|
||||
else
|
||||
list
|
||||
fi
|
||||
exit
|
Loading…
Add table
Add a link
Reference in a new issue