elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Security Series.XSS. [Cross Site Scripting]


+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting
| | |-+  [Bash] TODO list
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: [Bash] TODO list  (Leído 2,189 veces)
leogtz
. . .. ... ..... ........ ............. .....................
Colaborador
***
Desconectado Desconectado

Mensajes: 3.069


/^$/


Ver Perfil WWW
[Bash] TODO list
« en: 14 Junio 2011, 23:12 pm »

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
Código
  1. #!/bin/bash
  2.  
  3. #===============================================================================
  4. #
  5. #          FILE:  todo.sh
  6. #
  7. #         USAGE:  ./todo.sh OPTIONS
  8. #
  9. #   DESCRIPTION:  TODO List, nos permite hacer anotaciones sobre acciones que haremos en un futuro.
  10. #
  11. #       OPTIONS:  ./todo -h|H
  12. #  REQUIREMENTS:  ---
  13. #          BUGS:  ---
  14. #         NOTES:  ---
  15. #        AUTHOR: Leo Gutiérrez R. (), leorocko13@hotmail.com | leogutierrez@elhacker.net
  16. #       COMPANY:
  17. #       CREATED: 13/06/11 16:45:05 MDT
  18. #      REVISION:  ---
  19. #===============================================================================
  20.  
  21. FILE=~/.todo/todo
  22.  
  23. source functions
  24. # Checar que exista la carpeta y archivo de lista.
  25.  
  26. [ ! -d ~/.todo ] && {
  27. ask "No existe la carpeta, desea crearla ?" && {
  28. mkdir ~/.todo
  29. echo -e "Creando archivo \"todo\" en ~/.todo";
  30. touch ~/.todo/todo
  31. } || {
  32. echo -e "Saliendo . . .";
  33. exit 0
  34. }
  35. }
  36.  
  37. [ $# = 0 ] && usage;
  38.  
  39. while getopts “hHr:R:lLn:N:d:D:be:E:g:G:kKs:S:” OPTION
  40. do
  41.     case $OPTION in
  42.         h|H)
  43.             usage
  44.             exit 1
  45.             ;;
  46.         n|N)
  47.             TEST=$OPTARG
  48.  
  49.             # Actualizar el archivo :
  50.             updateList;
  51.  
  52.             #echo -e "Opción n, valor : ${TEST}";
  53.             echo -e "$(tput bold)$(tput setaf 2)TODO : [$[ $(cat $FILE | wc -l) + 1 ]] ${TEST}";
  54.             echo -e "[$[ $(cat $FILE | wc -l) + 1 ]] ${TEST}" >> $FILE
  55.             tput sgr0;
  56.             exit 0;
  57.             ;;
  58.  
  59.         g|G)
  60.  
  61. (( $OPTARG > $(cat $FILE | wc -l) )) && {
  62. echo -e "$(tput bold)$(tput setaf 1)ERROR, tarea inexistente, consulte las tareas con -L ó -l"
  63. tput sgr0;
  64. exit 1;
  65. }
  66.  
  67. read -p "Texto : " texto
  68.  
  69. sed -i "${OPTARG}s/^\(.*\)$/\1 $texto/g" $FILE
  70. updateList;
  71.  
  72. exit 0;
  73.  
  74. ;;
  75.  
  76.         d|D)
  77.  
  78.             # Cercionarnos que elija una TODO hecha.
  79.  
  80.             (( $OPTARG > $(cat $FILE | wc -l) )) && {
  81. echo -e "$(tput bold)$(tput setaf 1)ERROR, tarea inexistente, consulte las tareas con -L ó -l"
  82. tput sgr0;
  83. exit 1;
  84. }
  85.  
  86.             sed -i "${OPTARG}d" $FILE
  87.             updateList;
  88.  
  89.             exit 0;
  90.  
  91.             ;;
  92.  
  93.         k|K)
  94.  
  95.         [ ! -e ~/.todo/todo ] && {
  96. echo -e "$(tput bold)$(tput setaf 1)No existe el archivo \"todo\" en ~/.todo/";
  97.  
  98. ask "Desea crearlo? " && {
  99. touch $FILE
  100. }
  101. tput sgr0;
  102. exit 1;
  103. }
  104.  
  105. cp $FILE ${FILE}.bkp
  106. echo -e "\n$(tput bold)$(tput setaf 1)Archivo de respaldo creado\n";
  107. tput sgr0;
  108. exit 0;
  109.  
  110. ;;
  111.         r|R)
  112.  
  113.             (( $OPTARG > $(cat $FILE | wc -l) )) && {
  114. echo -e "$(tput bold)$(tput setaf 1)ERROR, tarea inexistente, consulte las tareas con -L ó -l"
  115. tput sgr0;
  116. exit 1;
  117. }
  118.  
  119. read -p "Texto : " texto
  120.  
  121. # Detectar status
  122. sed -n "${OPTARG}p" $FILE | grep "^\[.*\] \[.*\] " &> /dev/null && {
  123. sed -i "2s/.*\(\[.*\]\)\s\(\[.*\]\)\s\(.*\)/\1 \2 $texto/g" $FILE
  124. } || {
  125. sed -i "${OPTARG}s/.*\(\[.*\]\)\s\(.*\)/\1 $texto/g" $FILE
  126. }
  127. updateList;
  128.  
  129. exit 0;
  130.  
  131.             ;;
  132.  
  133.         # -lL Mostrar, listar tareas.
  134.         l|L)
  135.  
  136. (( $(cat $FILE | wc -l) == 0 )) && {
  137. echo -e "$(tput bold)$(tput setaf 1)TODO List vacía, agregue nuevas tareas.";
  138. tput sgr0;
  139. exit 0;
  140. }
  141.  
  142. updateList;
  143.  
  144. while read line
  145. do
  146. echo -e "$(tput bold)$(tput setaf 1)${line}";
  147.  
  148. done < $FILE
  149.  
  150. tput sgr0;
  151.  
  152. exit 0;
  153. ;;
  154.  
  155. b|B)
  156.  
  157. ask "$(tput bold)$(tput setaf 1)Esto borrará todas las tareas, desea continuar? " && {
  158. sed -i '1,$d' $FILE
  159. }
  160.  
  161. tput sgr0;
  162. exit 0;
  163. ;;
  164.  
  165. s|S)
  166.  
  167. (( $(cat $FILE | wc -l) == 0 )) && {
  168. echo -e "$(tput bold)$(tput setaf 1)TODO List vacía, agregue nuevas tareas.";
  169. tput sgr0;
  170. exit 0;
  171. }
  172.  
  173. read -p "Estado de tarea : " status
  174.  
  175. sed -n "${OPTARG}p" $FILE | grep "^\[.*\] \[.*\] " &> /dev/null && {
  176.  
  177. sed -i "${OPTARG}s/.*\(\[.*\]\)\s\(\[.*\]\)\s\(.*\)/\1 [$status] \3/g" $FILE
  178.  
  179. } || {
  180.  
  181. sed -i "${OPTARG}s/^\(\[.*\]\)\s\(.*\)$/\1 [$status] \2/g" $FILE
  182.  
  183. }
  184.  
  185. ;;
  186.  
  187.         ?)
  188.             usage
  189.             exit
  190.             ;;
  191.     esac
  192. done
  193.  

functions
Código
  1. function usage()
  2. {
  3. tput bold
  4. tput setaf 6
  5. cat << EOF
  6. Uso: $0 options
  7.  
  8. TODO List v1.0 | leorocko13@hotmail.com
  9.  
  10. OPTIONS:
  11.    
  12.    -h|H        Muestra este mensaje
  13.    -n|N [#TAREA]    Nueva tarea
  14.    -l|L          Listar tareas
  15.    -d|D [#TAREA]    Eliminar tarea
  16.    -r|R [#TAREA]    Reemplazar tarea
  17.    -b|B            Borrar todas las tareas
  18.    -g|G [#TAREA]    Agregar a una tarea
  19.    -k|K            Crear respaldo de tareas
  20.    -s|S [#TAREA]    Agregar estado de la tarea
  21.    
  22. EOF
  23. tput sgr0;
  24. }
  25.  
  26. function ask()
  27. {
  28. echo -n "$@" '[y/n] ';
  29. read ans;
  30. case "$ans" in
  31. y*|Y*)
  32. return 0 ;;
  33. *)
  34. return 1 ;;
  35. esac
  36. }
  37.  
  38. # Detectar status
  39. # sed -n "${OPTARG}p" $FILE | grep "^\[.*\] \[.*\] " &> /dev/null && {
  40. # sed -i "2s/.*\(\[.*\]\)\s\(\[.*\]\)\s\(.*\)/\1 \2 $texto/g" $FILE
  41. # } || {
  42. # sed -i "${OPTARG}s/.*\(\[.*\]\)\s\(.*\)/\1 $texto/g" $FILE
  43. # }
  44.  
  45. function updateList()
  46. {
  47. rm -f /tmp/todo_temp
  48.  
  49. # Checamos si la lista no está vacía.
  50. (( $(cat $FILE | wc -l) == 0 )) && {
  51. return;
  52. }
  53.  
  54. ((contador = 1));
  55. while read line
  56. do
  57. echo -e "$line" | grep "^\[.*\] \[.*\] " &> /dev/null && {
  58. echo -e "[$contador] $(echo -e "$line" | sed "s/^\(\[.*\]\)\s\(\[.*\]\)\s\(.*\)/\2 \3/g")" >> /tmp/todo_temp
  59. } || {
  60. echo -e "[$contador] $(echo -e "$line" | sed "s/^\(\[.*\]\)\s\(.*\)/\2/g")" >> /tmp/todo_temp
  61. }
  62. ((contador++));
  63. done < $FILE
  64.  
  65. cp /tmp/todo_temp $FILE
  66.  
  67. }

Aquí algunas capturas:


« Última modificación: 14 Junio 2011, 23:19 pm por Leo Gutiérrez. » En línea

Código
  1. (( 1 / 0 )) &> /dev/null || {
  2. echo -e "stderrrrrrrrrrrrrrrrrrr";
  3. }
  4.  
http://leonardogtzr.wordpress.com/
leogutierrezramirez@gmail.com
WaAYa HaCK

Desconectado Desconectado

Mensajes: 292


Arduino, Android and music


Ver Perfil
Re: [Bash] TODO list
« Respuesta #1 en: 15 Junio 2011, 12:30 pm »

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 Desconectado

Mensajes: 3.069


/^$/


Ver Perfil WWW
Re: [Bash] TODO list
« Respuesta #2 en: 15 Junio 2011, 23:48 pm »

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:

Código
  1. #!/bin/bash
  2.  
  3. #===============================================================================
  4. #
  5. #          FILE:  todo.sh
  6. #
  7. #         USAGE:  ./todo.sh OPTIONS
  8. #
  9. #   DESCRIPTION:  TODO List, nos permite hacer anotaciones sobre acciones que haremos en un futuro.
  10. #
  11. #       OPTIONS:  ./todo -h|H
  12. #  REQUIREMENTS:  ---
  13. #          BUGS:  ---
  14. #         NOTES:  ---
  15. #        AUTHOR: Leo Gutiérrez R. (), leorocko13@hotmail.com | leogutierrez@elhacker.net
  16. #       COMPANY:
  17. #       CREATED: 13/06/11 16:45:05 MDT
  18. #      REVISION:  ---
  19. #===============================================================================
  20.  
  21. FILE=~/.todo/todo
  22.  
  23. source functions
  24. # Checar que exista la carpeta y archivo de lista.
  25.  
  26. [ ! -d ~/.todo ] && {
  27. ask "No existe la carpeta, desea crearla ?" && {
  28. mkdir ~/.todo
  29. echo -e "Creando archivo \"todo\" en ~/.todo";
  30. touch ~/.todo/todo
  31. } || {
  32. echo -e "Saliendo . . .";
  33. exit 0
  34. }
  35. }
  36.  
  37. [ $# = 0 ] && usage;
  38.  
  39. while getopts “hHr:R:lLn:N:d:D:be:E:g:G:kKs:S:qQ” OPTION
  40. do
  41.     case $OPTION in
  42.         h|H)
  43.             usage
  44.             exit 1
  45.             ;;
  46.         n|N)
  47.             TEST=$OPTARG
  48.  
  49.             # Actualizar el archivo :
  50.             updateList;
  51.  
  52.             #echo -e "Opción n, valor : ${TEST}";
  53.             echo -e "$(tput bold)$(tput setaf 2)TODO : [$[ $(cat $FILE | wc -l) + 1 ]] ${TEST}";
  54.             echo -e "[$[ $(cat $FILE | wc -l) + 1 ]] ${TEST}" >> $FILE
  55.             tput sgr0;
  56.             exit 0;
  57.             ;;
  58.  
  59.         g|G)
  60.  
  61. (( $OPTARG > $(cat $FILE | wc -l) )) && {
  62. echo -e "$(tput bold)$(tput setaf 1)ERROR, tarea inexistente, consulte las tareas con -L ó -l"
  63. tput sgr0;
  64. exit 1;
  65. }
  66.  
  67. read -p "Texto : " texto
  68.  
  69. sed -i "${OPTARG}s/^\(.*\)$/\1 $texto/g" $FILE
  70. updateList;
  71.  
  72. exit 0;
  73.  
  74. ;;
  75.  
  76.         d|D)
  77.  
  78.             # Cercionarnos que elija una TODO hecha.
  79.  
  80.             (( $OPTARG > $(cat $FILE | wc -l) )) && {
  81. echo -e "$(tput bold)$(tput setaf 1)ERROR, tarea inexistente, consulte las tareas con -L ó -l"
  82. tput sgr0;
  83. exit 1;
  84. }
  85.  
  86.             sed -i "${OPTARG}d" $FILE
  87.             updateList;
  88.  
  89.             exit 0;
  90.  
  91.             ;;
  92.  
  93.         k|K)
  94.  
  95.         [ ! -e ~/.todo/todo ] && {
  96. echo -e "$(tput bold)$(tput setaf 1)No existe el archivo \"todo\" en ~/.todo/";
  97.  
  98. ask "Desea crearlo? " && {
  99. touch $FILE
  100. }
  101. tput sgr0;
  102. exit 1;
  103. }
  104.  
  105. cp $FILE ${FILE}.bkp
  106. echo -e "\n$(tput bold)$(tput setaf 1)Archivo de respaldo creado\n";
  107. tput sgr0;
  108. exit 0;
  109.  
  110. ;;
  111.         r|R)
  112.  
  113.             (( $OPTARG > $(cat $FILE | wc -l) )) && {
  114. echo -e "$(tput bold)$(tput setaf 1)ERROR, tarea inexistente, consulte las tareas con -L ó -l"
  115. tput sgr0;
  116. exit 1;
  117. }
  118.  
  119. read -p "Texto : " texto
  120.  
  121. # Detectar status
  122. sed -n "${OPTARG}p" $FILE | grep "^\[.*\] \[.*\] " &> /dev/null && {
  123. sed -i "2s/.*\(\[.*\]\)\s\(\[.*\]\)\s\(.*\)/\1 \2 $texto/g" $FILE
  124. } || {
  125. sed -i "${OPTARG}s/.*\(\[.*\]\)\s\(.*\)/\1 $texto/g" $FILE
  126. }
  127. updateList;
  128.  
  129. exit 0;
  130.  
  131.             ;;
  132.  
  133.         # -lL Mostrar, listar tareas.
  134.         l|L)
  135.  
  136. (( $(cat $FILE | wc -l) == 0 )) && {
  137. echo -e "$(tput bold)$(tput setaf 1)TODO List vacía, agregue nuevas tareas.";
  138. tput sgr0;
  139. exit 0;
  140. }
  141.  
  142. updateList;
  143.  
  144. while read line
  145. do
  146. echo -e "$(tput bold)$(tput setaf 1)${line}";
  147.  
  148. done < $FILE
  149.  
  150. tput sgr0;
  151.  
  152. exit 0;
  153. ;;
  154.  
  155. b|B)
  156.  
  157. ask "$(tput bold)$(tput setaf 1)Esto borrará todas las tareas, desea continuar? " && {
  158. sed -i '1,$d' $FILE
  159. }
  160.  
  161. tput sgr0;
  162. exit 0;
  163. ;;
  164.  
  165. q|Q)
  166.  
  167. sed -i "/\[Hecho\]/d" $FILE
  168. updateList;
  169. exit 0;
  170. ;;
  171.  
  172.  
  173. s|S)
  174.  
  175. (( $(cat $FILE | wc -l) == 0 )) && {
  176. echo -e "$(tput bold)$(tput setaf 1)TODO List vacía, agregue nuevas tareas.";
  177. tput sgr0;
  178. exit 0;
  179. }
  180.  
  181. read -p "Estado de tarea : " status
  182.  
  183. sed -n "${OPTARG}p" $FILE | grep "^\[.*\] \[.*\] " &> /dev/null && {
  184.  
  185. sed -i "${OPTARG}s/.*\(\[.*\]\)\s\(\[.*\]\)\s\(.*\)/\1 [$status] \3/g" $FILE
  186.  
  187. } || {
  188.  
  189. sed -i "${OPTARG}s/^\(\[.*\]\)\s\(.*\)$/\1 [$status] \2/g" $FILE
  190.  
  191. }
  192.  
  193. ;;
  194.  
  195.         ?)
  196.             usage
  197.             exit
  198.             ;;
  199.     esac
  200. done
  201.  

Saludos.
En línea

Código
  1. (( 1 / 0 )) &> /dev/null || {
  2. echo -e "stderrrrrrrrrrrrrrrrrrr";
  3. }
  4.  
http://leonardogtzr.wordpress.com/
leogutierrezramirez@gmail.com
leogtz
. . .. ... ..... ........ ............. .....................
Colaborador
***
Desconectado Desconectado

Mensajes: 3.069


/^$/


Ver Perfil WWW
Re: [Bash] TODO list
« Respuesta #3 en: 20 Junio 2011, 08:05 am »

Descubrí un plugin excelente para las todo list:

Funciona perfecto.

Código:
http://www.vim.org/scripts/script.php?script_id=3089
En línea

Código
  1. (( 1 / 0 )) &> /dev/null || {
  2. echo -e "stderrrrrrrrrrrrrrrrrrr";
  3. }
  4.  
http://leonardogtzr.wordpress.com/
leogutierrezramirez@gmail.com
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
help con list
Programación Visual Basic
dark_soul 3 1,464 Último mensaje 18 Septiembre 2006, 17:57 pm
por SheKeL_C$
de un txt a un list
Programación Visual Basic
sp26 9 2,588 Último mensaje 21 Noviembre 2006, 15:51 pm
por ranslsad
List :S wtf!!!
Programación Visual Basic
schumacher 3 1,666 Último mensaje 29 Diciembre 2007, 15:41 pm
por schumacher
Aplicacion en Batch y Bash de VBoxManage list
Scripting
Hekaly 0 2,251 Último mensaje 27 Octubre 2010, 11:18 am
por Hekaly
[Bash script] equivalente de goto en batch para bash (SOLUCIONADO)
Scripting
moikano→@ 4 16,138 Último mensaje 4 Noviembre 2010, 15:58 pm
por moikano→@
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines