Advertisement
Guest User

remove_old_rc

a guest
Aug 31st, 2018
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # This script removes old rc files in $HOME/.config/xfce4/desktop/
  4. # It keeps only the latest created
  5.  
  6. # Get process id of all inotifywait procs watching
  7. # for moved_to events in $HOME/.config/xfce4/desktop/
  8.  
  9. notify_pid=`ps -eo pid,cmd | grep "inotifywait -m $HOME/.config/xfce4/desktop/ -e moved_to" | grep -v grep | awk '{print $1}'`
  10.  
  11. # kill any watching job if any
  12. for pid in $notify_pid; do
  13. kill -SIGKILL $pid
  14. wait $notify_pid >/dev/null 2>&1
  15. done
  16.  
  17. cd $HOME/.config/xfce4/desktop
  18.  
  19. sleep 2
  20.  
  21. # When the icons are moved, temp file is created and moved to rc file
  22.  
  23. # Watching for file moved_to event with inotify
  24. # inotifywait prints two lines, second one is ignored.
  25.  
  26. inotifywait -m $HOME/.config/xfce4/desktop/ -e moved_to \
  27. | while read path action file && read dummy
  28. do
  29.  
  30. # Nested loop lists all the rc files
  31. for rc_file in $HOME/.config/xfce4/desktop/*.rc
  32. do
  33. # echo "$rc_file" "${path}${file%.*}"
  34.  
  35. # If the file is not the latest moved removes it
  36. [[ "$rc_file" != "${path}${file%.*}" ]] && rm -v "${rc_file}"
  37. done
  38.  
  39. # makes the backup rc file
  40. # cp "${path}${file%.*}" "${path}${file%.*}.backup"
  41. # echo "${path}${file%.*}" >> last_file.log
  42. notify-send "icon position saved" "${path}${file%.*}" -i gtk-info -t 2000
  43. done
  44.  
  45. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement