Advertisement
Frannoe

IntBasHistory

Oct 14th, 2012
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.77 KB | None | 0 0
  1. #!/bin/bash
  2. #--------------------------------------
  3. # intbashistory 1.0
  4. # Script(Gui)para añadir comandos al historial del intérprete de comandos Bash (.bash_history)
  5. # Posibilita añadir (sin necesidad de ser ejecutado) comandos para su posterior utilización
  6. # tanto en modo Usuario cómo en modo Root. Permite ver y limpiar las lista del historial Bash.
  7. # Requiere de YAD (>= 0.25.1) y gksu
  8. # By Frannoe@gmail.com (Francisco Luque)
  9. # Tienes más información aquí: http://frannoe.blogspot.com.es/2012/10/la-memoria-del-terminal.html
  10. # Esta es una herramienta gratuita y libre que pretende facilitar el acceso a los comandos vía Terminal.
  11. #--------------------------------------
  12.  
  13. #####User#####
  14. function user_op1 () {
  15.  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
  16. echo $usuario1 >> $HOME/.bash_history
  17.  
  18. 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). "
  19.      fi
  20. }
  21.  
  22. function user_op2 () {
  23. 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
  24. QUES="$?"
  25.  
  26. if [ $QUES = 1 ]; then
  27. sort -u $HOME/.bash_history | sed '/^$/d'  > $HOME/.temphistory
  28.  
  29. QUES=""
  30. 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
  31. QUES="$?"
  32.  
  33. if [ $QUES = 1 ]; then
  34. mv $HOME/.temphistory $HOME/.bash_history
  35. 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. "
  36. else
  37. rm $HOME/.temphistory
  38. fi
  39. else
  40. exit
  41. fi
  42. }
  43.  
  44.  
  45. function user_op3 () {
  46. 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
  47. echo "" > $HOME/.bash_history
  48. yad --info --fixed --width=350 --button="Ok":0 --title "Historial Usuario ($login)..." --text-align=center --text " Historial Bash-Usuario ($login) limpiado. "
  49.      fi
  50. }
  51. #####User//////
  52.  
  53. #####User_Root#####
  54.  
  55. function root_op1 () {
  56. 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
  57.  (gksu "echo $root1 >> /root/.bash_history")
  58. 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. "
  59.      fi
  60.  
  61. }
  62.  
  63. function root_op2 () {
  64. (gksu cp /root/.bash_history /tmp/.bash_history)
  65. 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
  66. QUES="$?"
  67. if [ $QUES = 1 ]; then
  68. (gksu "sort -u /root/.bash_history | sed '/^$/d'  > /tmp/.bash_history")
  69.  
  70. QUES=""
  71. 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
  72. QUES="$?"
  73.  
  74. if [ $QUES = 1 ]; then
  75. (gksu "mv /tmp/.bash_history /root/.bash_history")
  76. yad --info --fixed --width=350 --buttons-layout=center --button="Ok" --title "Historial Root..." --text-align=center --text " Archivo de historial Bash-Root remplazado. "
  77. else
  78. (gksu "rm /tmp/.bash_history")
  79.      exit
  80. fi
  81. else
  82. exit
  83. fi
  84.  
  85. }
  86.  
  87. function root_op3 () {
  88. 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
  89.  (gksu "echo "" > /root/.bash_history")
  90. yad --info --fixed --width=350 --buttons-layout=center --button="Ok":0 --title "Historial Root..." --text-align=center --text " Historial Bash-Root ha sido limpiado. "
  91.      
  92.      fi
  93.  
  94. }
  95. #####User_Root//////
  96.  
  97. export -f user_op1
  98. export -f user_op2
  99. export -f user_op3
  100. export -f root_op1
  101. export -f root_op2
  102. export -f root_op3
  103. export login=`whoami`
  104. `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. " \
  105. --form \
  106. --field="<b>Opciones a nivel Usuario</b>":LBL '' \
  107. --field=:LBL '' \
  108. --field="Añadir comando en modo Usuario":BTN 'bash -c "user_op1"' \
  109. --field=:LBL '' \
  110. --field="Ver archivo historial Usuario":BTN  'bash -c "user_op2"' \
  111. --field=:LBL '' \
  112. --field="Limpiar archivo historial Usuario":BTN 'bash -c "user_op3"' \
  113. --field=:LBL '' \
  114. --field="<b>Opciones a nivel Root</b>":LBL '' \
  115. --field=:LBL '' \
  116. --field="Añadir comando en modo Root":BTN 'bash -c "root_op1"' \
  117. --field=:LBL '' \
  118. --field="Ver archivo historial Root":BTN  'bash -c "root_op2"' \
  119. --field=:LBL '' \
  120. --field="Limpiar archivo historial Root":BTN 'bash -c "root_op3"' \
  121. --field=:LBL ''`
  122.  
  123. if [ $? = 1 ]; then
  124. exit
  125. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement