Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #--------------------------------------
- # intbashistory 1.0
- # Script(Gui)para añadir comandos al historial del intérprete de comandos Bash (.bash_history)
- # Posibilita añadir (sin necesidad de ser ejecutado) comandos para su posterior utilización
- # tanto en modo Usuario cómo en modo Root. Permite ver y limpiar las lista del historial Bash.
- # Requiere de YAD (>= 0.25.1) y gksu
- # By Frannoe@gmail.com (Francisco Luque)
- # Tienes más información aquí: http://frannoe.blogspot.com.es/2012/10/la-memoria-del-terminal.html
- # Esta es una herramienta gratuita y libre que pretende facilitar el acceso a los comandos vía Terminal.
- #--------------------------------------
- #####User#####
- function user_op1 () {
- if usuario1=$(yad --fixed --width=350 --buttons-layout=center --title "Añadir comando/s..." --entry-text "PONGA AQUÍ SU COMANDO/s" --entry --text-align=center --text "Escriba o pegue el comando que desea añadir al historial Bash-Usuario ($login)"); then
- echo $usuario1 >> $HOME/.bash_history
- yad --info --fixed --width=350 --buttons-layout=center --button="Ok":0 --title "Historial Usuario ($login)..." --text-align=center --text " Comando añadido al historial Bash-Usuario ($login). "
- fi
- }
- function user_op2 () {
- yad --text-info --buttons-layout=center --width=500 --height=500 --button="Eliminar líneas duplicadas":1 --button="Salir":0 --title "Historial Bash-Usuario" --text-align=center --text "Este es el contedido de su historial Bash ($login).\n<b>Total líneas:</b> `wc $HOME/.bash_history | awk '{print $1}'`\n <b>Total duplicadas:</b> `cat $HOME/.bash_history | uniq -c | grep -v "1 " | awk '{sum += $1} END { print sum }'`\nNota: Puede eliminar las líneas duplicadas pulsando el botón correspondiente" --filename=$HOME/.bash_history
- QUES="$?"
- if [ $QUES = 1 ]; then
- sort -u $HOME/.bash_history | sed '/^$/d' > $HOME/.temphistory
- QUES=""
- yad --text-info --buttons-layout=center --width=500 --height=500 --button="Mantener los cambios":1 --button="Abortar":0 --title "Historial Bash-Usuario ($login) corregido" --text-align=center --text "Historial Bash-Usuario ha sido ordenado y las lineas duplicadas y los espacios en blanco han sido eliminados en un archivo temporal.\n<b>Total líneas ahora:</b> `wc $HOME/.temphistory | awk '{print $1}'`\nEsto es una muestra del nuevo documento.\n¿Desea mantener los cambios?. " --filename=$HOME/.temphistory
- QUES="$?"
- if [ $QUES = 1 ]; then
- mv $HOME/.temphistory $HOME/.bash_history
- yad --info --fixed --width=350 --buttons-layout=center --button="Ok":0 --title "Historial Usuario..." --text-align=center --text " Archivo de historial Bash-Usuario ($login) remplazado. "
- else
- rm $HOME/.temphistory
- fi
- else
- exit
- fi
- }
- function user_op3 () {
- if yad --info --fixed --width=450 --buttons-layout=center --button="Ok":0 --button="No":1 --title "Historial Bash-Usuario..." --text-align=center --text "¿Desea limpiar el contenido del historial Bash-Usuario?:\n($login)"; then
- echo "" > $HOME/.bash_history
- yad --info --fixed --width=350 --button="Ok":0 --title "Historial Usuario ($login)..." --text-align=center --text " Historial Bash-Usuario ($login) limpiado. "
- fi
- }
- #####User//////
- #####User_Root#####
- function root_op1 () {
- if root1=$(yad --info --fixed --width=300 --buttons-layout=center --title "Añadir Comando..." --entry-text "PONGA AQUÍ SU COMANDO/s" --entry --text-align=center --text "Escriba o pegue el comando que desea añadir al historial Bash-Root"); then
- (gksu "echo $root1 >> /root/.bash_history")
- yad --info --fixed --width=350 --buttons-layout=center --button="Ok":0 --title "Historial Root..." --text-align=center --text " Comando añadido al historial Bash-Root. "
- fi
- }
- function root_op2 () {
- (gksu cp /root/.bash_history /tmp/.bash_history)
- yad --text-info --buttons-layout=center --width=500 --height=500 --button="Eliminar líneas duplicadas":1 --button="Salir":0 --title "Historial Bash-Usuario" --text-align=center --text "Este es el contedido de su historial Bash (Root).\n<b>Total líneas:</b> `wc /tmp/.bash_history | awk '{print $1}'`\n <b>Total duplicadas:</b> `cat /tmp/.bash_history | uniq -c | grep -v "1 " | awk '{sum += $1} END { print sum }'`\nNota: Puede eliminar las líneas duplicadas pulsando el botón correspondiente" --filename=/tmp/.bash_history
- QUES="$?"
- if [ $QUES = 1 ]; then
- (gksu "sort -u /root/.bash_history | sed '/^$/d' > /tmp/.bash_history")
- QUES=""
- yad --text-info --buttons-layout=center --width=500 --height=500 --button="Mantener cambios":1 --button="Abortar":0 --title "Historial Bash-Root (Root) corregido" --text-align=center --text "Historial Bash-Root ha sido ordenado y las lineas duplicadas y los espacios en blanco han sido eliminados en un archivo temporal.\n<b>Total líneas ahora: </b>`wc /tmp/.bash_history | awk '{print $1}'`\nEsto es una muestra del nuevo el documento.\n¿Desea mantener los cambios?." --filename=/tmp/.bash_history
- QUES="$?"
- if [ $QUES = 1 ]; then
- (gksu "mv /tmp/.bash_history /root/.bash_history")
- yad --info --fixed --width=350 --buttons-layout=center --button="Ok" --title "Historial Root..." --text-align=center --text " Archivo de historial Bash-Root remplazado. "
- else
- (gksu "rm /tmp/.bash_history")
- exit
- fi
- else
- exit
- fi
- }
- function root_op3 () {
- if yad --info --fixed --width=450 --buttons-layout=center --button="Ok":0 --button="No":1 --title "Historial Bash-Root..." --text-align=center --text " ¿Desea limpiar el contenido del historial Bash-Root?. "; then
- (gksu "echo "" > /root/.bash_history")
- yad --info --fixed --width=350 --buttons-layout=center --button="Ok":0 --title "Historial Root..." --text-align=center --text " Historial Bash-Root ha sido limpiado. "
- fi
- }
- #####User_Root//////
- export -f user_op1
- export -f user_op2
- export -f user_op3
- export -f root_op1
- export -f root_op2
- export -f root_op3
- export login=`whoami`
- `yad --fixed --buttons-layout=center --columns=2 --button="Salir":1 --text-align=center --text "Las opciones se encuentran divididas por igual tanto para el usuario ($login) como para el usuario Root.\nPulse la opción que le interese en cada momento. " \
- --form \
- --field="<b>Opciones a nivel Usuario</b>":LBL '' \
- --field=:LBL '' \
- --field="Añadir comando en modo Usuario":BTN 'bash -c "user_op1"' \
- --field=:LBL '' \
- --field="Ver archivo historial Usuario":BTN 'bash -c "user_op2"' \
- --field=:LBL '' \
- --field="Limpiar archivo historial Usuario":BTN 'bash -c "user_op3"' \
- --field=:LBL '' \
- --field="<b>Opciones a nivel Root</b>":LBL '' \
- --field=:LBL '' \
- --field="Añadir comando en modo Root":BTN 'bash -c "root_op1"' \
- --field=:LBL '' \
- --field="Ver archivo historial Root":BTN 'bash -c "root_op2"' \
- --field=:LBL '' \
- --field="Limpiar archivo historial Root":BTN 'bash -c "root_op3"' \
- --field=:LBL ''`
- if [ $? = 1 ]; then
- exit
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement