Autor
|
Tema: [Bash] TODO list (Leído 2,189 veces)
|
leogtz
. . .. ... ..... ........ ............. .....................
Colaborador
Desconectado
Mensajes: 3.069
/^$/
|
Hola a todos, acabo de hacer esta pequeña herramienta, es un script en Bash que me sirve para tener una lista organizada de lo que tengo que hacer, y pues como paso un 30% de mi tiempo en la consola, pues me es de gran utilidad y quiero compartirlo. todo.sh #!/bin/bash #=============================================================================== # # FILE: todo.sh # # USAGE: ./todo.sh OPTIONS # # DESCRIPTION: TODO List, nos permite hacer anotaciones sobre acciones que haremos en un futuro. # # OPTIONS: ./todo -h|H # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: Leo Gutiérrez R. (), leorocko13@hotmail.com | leogutierrez@elhacker.net # COMPANY: # CREATED: 13/06/11 16:45:05 MDT # REVISION: --- #=============================================================================== FILE=~/.todo/todo source functions # Checar que exista la carpeta y archivo de lista. [ ! -d ~/.todo ] && { ask "No existe la carpeta, desea crearla ?" && { mkdir ~/.todo echo -e "Creando archivo \"todo\" en ~/.todo"; touch ~/.todo/todo } || { echo -e "Saliendo . . ."; exit 0 } } [ $# = 0 ] && usage; while getopts “hHr:R:lLn:N:d:D:be:E:g:G:kKs:S:” OPTION do case $OPTION in h|H) usage exit 1 ;; n|N) TEST=$OPTARG # Actualizar el archivo : updateList; #echo -e "Opción n, valor : ${TEST}"; echo -e "$(tput bold)$(tput setaf 2)TODO : [$[ $(cat $FILE | wc -l) + 1 ]] ${TEST}"; echo -e "[$[ $(cat $FILE | wc -l) + 1 ]] ${TEST}" >> $FILE tput sgr0; exit 0; ;; g|G) (( $OPTARG > $(cat $FILE | wc -l) )) && { echo -e "$(tput bold)$(tput setaf 1)ERROR, tarea inexistente, consulte las tareas con -L ó -l" tput sgr0; exit 1; } read -p "Texto : " texto sed -i "${OPTARG}s/^\(.*\)$/\1 $texto/g" $FILE updateList; exit 0; ;; d|D) # Cercionarnos que elija una TODO hecha. (( $OPTARG > $(cat $FILE | wc -l) )) && { echo -e "$(tput bold)$(tput setaf 1)ERROR, tarea inexistente, consulte las tareas con -L ó -l" tput sgr0; exit 1; } sed -i "${OPTARG}d" $FILE updateList; exit 0; ;; k|K) [ ! -e ~/.todo/todo ] && { echo -e "$(tput bold)$(tput setaf 1)No existe el archivo \"todo\" en ~/.todo/"; ask "Desea crearlo? " && { touch $FILE } tput sgr0; exit 1; } cp $FILE ${FILE}.bkp echo -e "\n$(tput bold)$(tput setaf 1)Archivo de respaldo creado\n"; tput sgr0; exit 0; ;; r|R) (( $OPTARG > $(cat $FILE | wc -l) )) && { echo -e "$(tput bold)$(tput setaf 1)ERROR, tarea inexistente, consulte las tareas con -L ó -l" tput sgr0; exit 1; } read -p "Texto : " texto # Detectar status sed -n "${OPTARG}p" $FILE | grep "^\[.*\] \[.*\] " &> /dev/null && { sed -i "2s/.*\(\[.*\]\)\s\(\[.*\]\)\s\(.*\)/\1 \2 $texto/g" $FILE } || { sed -i "${OPTARG}s/.*\(\[.*\]\)\s\(.*\)/\1 $texto/g" $FILE } updateList; exit 0; ;; # -lL Mostrar, listar tareas. l|L) (( $(cat $FILE | wc -l) == 0 )) && { echo -e "$(tput bold)$(tput setaf 1)TODO List vacía, agregue nuevas tareas."; tput sgr0; exit 0; } updateList; while read line do echo -e "$(tput bold)$(tput setaf 1)${line}"; done < $FILE tput sgr0; exit 0; ;; b|B) ask "$(tput bold)$(tput setaf 1)Esto borrará todas las tareas, desea continuar? " && { sed -i '1,$d' $FILE } tput sgr0; exit 0; ;; s|S) (( $(cat $FILE | wc -l) == 0 )) && { echo -e "$(tput bold)$(tput setaf 1)TODO List vacía, agregue nuevas tareas."; tput sgr0; exit 0; } read -p "Estado de tarea : " status sed -n "${OPTARG}p" $FILE | grep "^\[.*\] \[.*\] " &> /dev/null && { sed -i "${OPTARG}s/.*\(\[.*\]\)\s\(\[.*\]\)\s\(.*\)/\1 [$status] \3/g" $FILE } || { sed -i "${OPTARG}s/^\(\[.*\]\)\s\(.*\)$/\1 [$status] \2/g" $FILE } ;; ?) usage exit ;; esac done
functions function usage() { tput bold tput setaf 6 cat << EOF Uso: $0 options TODO List v1.0 | leorocko13@hotmail.com OPTIONS: -h|H Muestra este mensaje -n|N [#TAREA] Nueva tarea -l|L Listar tareas -d|D [#TAREA] Eliminar tarea -r|R [#TAREA] Reemplazar tarea -b|B Borrar todas las tareas -g|G [#TAREA] Agregar a una tarea -k|K Crear respaldo de tareas -s|S [#TAREA] Agregar estado de la tarea EOF tput sgr0; } function ask() { echo -n "$@" '[y/n] '; read ans; case "$ans" in y*|Y*) return 0 ;; *) return 1 ;; esac } # Detectar status # sed -n "${OPTARG}p" $FILE | grep "^\[.*\] \[.*\] " &> /dev/null && { # sed -i "2s/.*\(\[.*\]\)\s\(\[.*\]\)\s\(.*\)/\1 \2 $texto/g" $FILE # } || { # sed -i "${OPTARG}s/.*\(\[.*\]\)\s\(.*\)/\1 $texto/g" $FILE # } function updateList() { rm -f /tmp/todo_temp # Checamos si la lista no está vacía. (( $(cat $FILE | wc -l) == 0 )) && { return; } ((contador = 1)); while read line do echo -e "$line" | grep "^\[.*\] \[.*\] " &> /dev/null && { echo -e "[$contador] $(echo -e "$line" | sed "s/^\(\[.*\]\)\s\(\[.*\]\)\s\(.*\)/\2 \3/g")" >> /tmp/todo_temp } || { echo -e "[$contador] $(echo -e "$line" | sed "s/^\(\[.*\]\)\s\(.*\)/\2/g")" >> /tmp/todo_temp } ((contador++)); done < $FILE cp /tmp/todo_temp $FILE }
Aquí algunas capturas:
|
|
« Última modificación: 14 Junio 2011, 23:19 pm por Leo Gutiérrez. »
|
En línea
|
|
|
|
WaAYa HaCK
Desconectado
Mensajes: 292
Arduino, Android and music
|
Vaya, perfecto! Ya he encontrado la forma de organizar mis tareas, y desde la consola! Muchísimas gracias, Leo!!!
|
|
|
En línea
|
La cacatúa yoyó es nueva en el zoo!
|
|
|
leogtz
. . .. ... ..... ........ ............. .....................
Colaborador
Desconectado
Mensajes: 3.069
/^$/
|
Gracias, he hecho una pequeña modificación, agregar la opción -q|Q para eliminar las tareas que ya tengan el estado de "Hecho", aquí el código: #!/bin/bash #=============================================================================== # # FILE: todo.sh # # USAGE: ./todo.sh OPTIONS # # DESCRIPTION: TODO List, nos permite hacer anotaciones sobre acciones que haremos en un futuro. # # OPTIONS: ./todo -h|H # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: Leo Gutiérrez R. (), leorocko13@hotmail.com | leogutierrez@elhacker.net # COMPANY: # CREATED: 13/06/11 16:45:05 MDT # REVISION: --- #=============================================================================== FILE=~/.todo/todo source functions # Checar que exista la carpeta y archivo de lista. [ ! -d ~/.todo ] && { ask "No existe la carpeta, desea crearla ?" && { mkdir ~/.todo echo -e "Creando archivo \"todo\" en ~/.todo"; touch ~/.todo/todo } || { echo -e "Saliendo . . ."; exit 0 } } [ $# = 0 ] && usage; while getopts “hHr:R:lLn:N:d:D:be:E:g:G:kKs:S:qQ” OPTION do case $OPTION in h|H) usage exit 1 ;; n|N) TEST=$OPTARG # Actualizar el archivo : updateList; #echo -e "Opción n, valor : ${TEST}"; echo -e "$(tput bold)$(tput setaf 2)TODO : [$[ $(cat $FILE | wc -l) + 1 ]] ${TEST}"; echo -e "[$[ $(cat $FILE | wc -l) + 1 ]] ${TEST}" >> $FILE tput sgr0; exit 0; ;; g|G) (( $OPTARG > $(cat $FILE | wc -l) )) && { echo -e "$(tput bold)$(tput setaf 1)ERROR, tarea inexistente, consulte las tareas con -L ó -l" tput sgr0; exit 1; } read -p "Texto : " texto sed -i "${OPTARG}s/^\(.*\)$/\1 $texto/g" $FILE updateList; exit 0; ;; d|D) # Cercionarnos que elija una TODO hecha. (( $OPTARG > $(cat $FILE | wc -l) )) && { echo -e "$(tput bold)$(tput setaf 1)ERROR, tarea inexistente, consulte las tareas con -L ó -l" tput sgr0; exit 1; } sed -i "${OPTARG}d" $FILE updateList; exit 0; ;; k|K) [ ! -e ~/.todo/todo ] && { echo -e "$(tput bold)$(tput setaf 1)No existe el archivo \"todo\" en ~/.todo/"; ask "Desea crearlo? " && { touch $FILE } tput sgr0; exit 1; } cp $FILE ${FILE}.bkp echo -e "\n$(tput bold)$(tput setaf 1)Archivo de respaldo creado\n"; tput sgr0; exit 0; ;; r|R) (( $OPTARG > $(cat $FILE | wc -l) )) && { echo -e "$(tput bold)$(tput setaf 1)ERROR, tarea inexistente, consulte las tareas con -L ó -l" tput sgr0; exit 1; } read -p "Texto : " texto # Detectar status sed -n "${OPTARG}p" $FILE | grep "^\[.*\] \[.*\] " &> /dev/null && { sed -i "2s/.*\(\[.*\]\)\s\(\[.*\]\)\s\(.*\)/\1 \2 $texto/g" $FILE } || { sed -i "${OPTARG}s/.*\(\[.*\]\)\s\(.*\)/\1 $texto/g" $FILE } updateList; exit 0; ;; # -lL Mostrar, listar tareas. l|L) (( $(cat $FILE | wc -l) == 0 )) && { echo -e "$(tput bold)$(tput setaf 1)TODO List vacía, agregue nuevas tareas."; tput sgr0; exit 0; } updateList; while read line do echo -e "$(tput bold)$(tput setaf 1)${line}"; done < $FILE tput sgr0; exit 0; ;; b|B) ask "$(tput bold)$(tput setaf 1)Esto borrará todas las tareas, desea continuar? " && { sed -i '1,$d' $FILE } tput sgr0; exit 0; ;; q|Q) sed -i "/\[Hecho\]/d" $FILE updateList; exit 0; ;; s|S) (( $(cat $FILE | wc -l) == 0 )) && { echo -e "$(tput bold)$(tput setaf 1)TODO List vacía, agregue nuevas tareas."; tput sgr0; exit 0; } read -p "Estado de tarea : " status sed -n "${OPTARG}p" $FILE | grep "^\[.*\] \[.*\] " &> /dev/null && { sed -i "${OPTARG}s/.*\(\[.*\]\)\s\(\[.*\]\)\s\(.*\)/\1 [$status] \3/g" $FILE } || { sed -i "${OPTARG}s/^\(\[.*\]\)\s\(.*\)$/\1 [$status] \2/g" $FILE } ;; ?) usage exit ;; esac done
Saludos.
|
|
|
En línea
|
|
|
|
leogtz
. . .. ... ..... ........ ............. .....................
Colaborador
Desconectado
Mensajes: 3.069
/^$/
|
Descubrí un plugin excelente para las todo list: Funciona perfecto. http://www.vim.org/scripts/script.php?script_id=3089
|
|
|
En línea
|
|
|
|
|
Mensajes similares |
|
Asunto |
Iniciado por |
Respuestas |
Vistas |
Último mensaje |
|
|
help con list
Programación Visual Basic
|
dark_soul
|
3
|
1,464
|
18 Septiembre 2006, 17:57 pm
por SheKeL_C$
|
|
|
de un txt a un list
Programación Visual Basic
|
sp26
|
9
|
2,588
|
21 Noviembre 2006, 15:51 pm
por ranslsad
|
|
|
List :S wtf!!!
Programación Visual Basic
|
schumacher
|
3
|
1,666
|
29 Diciembre 2007, 15:41 pm
por schumacher
|
|
|
Aplicacion en Batch y Bash de VBoxManage list
Scripting
|
Hekaly
|
0
|
2,251
|
27 Octubre 2010, 11:18 am
por Hekaly
|
|
|
[Bash script] equivalente de goto en batch para bash (SOLUCIONADO)
Scripting
|
moikano→@
|
4
|
16,138
|
4 Noviembre 2010, 15:58 pm
por moikano→@
|
|