Skip to content

Instantly share code, notes, and snippets.

@PanJarda
Created November 25, 2016 18:27
Show Gist options
  • Save PanJarda/58ade7dc90ac58e6b273066bde17e382 to your computer and use it in GitHub Desktop.
Save PanJarda/58ade7dc90ac58e6b273066bde17e382 to your computer and use it in GitHub Desktop.
#!/bin/sh
DATA=~/shell/todo.csv
h(){
echo 'h - help\np - print\nl - last\ni - insert\nd - delete\nw - write\nq - quit'
}
q(){
exit
}
p(){
printf '%2s %1s %-42s %-4s %-6s\n' 'id' 'p' 'polozka' 'doba' 'termin'
hr
awk -F ';' '{printf "%d;%d;%s;%d;%s\n",NR,$1,$2,$3,$4}' $DATA | \
sort -t ';' -k 2,2n -k 5.4,5.5n -k 5.1,5.2n -k 4,4n | \
awk -F ';' '{printf "%2d %1d %-42s %4d %-6s\n",$1,$2,$3,$4,$5}'
}
l(){
p | sed '3q;d'
}
i(){
echo "item: ";read item
echo 'priority [1-3]: ';read prior
[ $prior -gt 3 ] && prior=3 || { [ $prior -lt 1 ] && prior=1; }
echo -n 'duration (m): ';read duration
echo -n 'date: ';read max_date
echo "$prior;$item;$duration;$max_date" >> $DATA
}
w(){
[ $# -ne 0 ] && p > $1 || echo '?'
}
d(){
[ $# -eq 0 ] && ( echo -n 'id: ';read id ) || id=$1
sed -i '' "${id}d" $DATA
}
hr(){
echo '-----------------------------------------------------------'
}
while [ : ]
do
read cmd
case $cmd in
[hipqwdl]*) $cmd;;
*) echo '?';;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment