elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
29 Mayo 2012, 06:52  


Tema destacado: Recuperar cuenta de Google, GMail, Youtube

+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting (Moderadores: Novlucker, Leo Gutiérrez., EleKtro H@cker)
| | |-+  [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 686 veces)
Leo Gutiérrez.
. . .. ... ..... ........ ............. .....................
Moderador
***
Desconectado Desconectado

Mensajes: 2.968


/^$/


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

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
#!/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
Código
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 por Leo Gutiérrez. » En línea

Código
(( 1 / 0 )) &> /dev/null || {
echo -e "stderrrrrrrrrrrrrrrrrrr";
}
 

leorocko13@hotmail.com
https://github.com/leogtzr/
WaAYa HaCK

Desconectado Desconectado

Mensajes: 262


import ehn / #include <ehn.h>


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

Vaya, perfecto!
Ya he encontrado la forma de organizar mis tareas, y desde la consola!

Muchísimas gracias, Leo!!!  ;-)


En línea



Leo Gutiérrez.
. . .. ... ..... ........ ............. .....................
Moderador
***
Desconectado Desconectado

Mensajes: 2.968


/^$/


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

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
#!/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

Código
(( 1 / 0 )) &> /dev/null || {
echo -e "stderrrrrrrrrrrrrrrrrrr";
}
 

leorocko13@hotmail.com
https://github.com/leogtzr/
Leo Gutiérrez.
. . .. ... ..... ........ ............. .....................
Moderador
***
Desconectado Desconectado

Mensajes: 2.968


/^$/


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

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 / 0 )) &> /dev/null || {
echo -e "stderrrrrrrrrrrrrrrrrrr";
}
 

leorocko13@hotmail.com
https://github.com/leogtzr/
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines