Recent files

a guest Jan 14th, 2020 102 in 23 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. ### Recent files window- by PPC, 13/1/2020, for use with antiX and MX-fluxbox
  3. #GPL licence- do what you want with this, but please keep lines about the author, date and licence
  4. # works on any system with yad and xdg-open installed, optionally: exo-open (see exceptions to the general rule, when launching files, near the end.
  5. #
  6. #Parse the file that stores the recent used files, send output to recent0.txt
  7. awk -F"file://|\" " '/file:\/\// {print $2}' ~/.local/share/recently-used.xbel > ~/.recent0.txt
  8. #reverse contents order, so last file comes first, and so on...
  9. tac ~/.recent0.txt > ~/.recent.txt
  10. #function to decode file name (from %20 instead of spaces, etc, from
  11. urldecode() {
  12.     local url_encoded="${1//+/ }"
  13.     printf '%b' "${url_encoded//%/\\x}"
  14. }
  15. # Use a undecorated Yad window to select file to be executed
  16. EXEC=$(yad --title="Recent files" --undecorated --width=450 --height=400 --center --separator=" " --list  --column=Files < ~/.recent.txt)
  17. #do decoding on the file name, just in case it has spaces or special characters that come up as %xx
  18. decoded=$(urldecode $EXEC)
  19. # general rule: open selected file with the aplication used for its file type
  20. openwith=xdg-open
  21. ###Exceptions to the general rule: LibreOffice Writer ".odt" files - check extension and  force it to open with lowriter; also more exceptions: like open ".sh" files for edition and run ".desktop" files instead of editing them
  22. check=$(echo -n $EXEC | tail -c 3)
  23.     if [ "$check" == "odt" ]; then openwith=lowriter ; fi  #this solves bug opening odt files with spaces
  24.     if [ "$check" == ".sh" ]; then openwith=exo-open ; fi
  25.     if [ "$check" == "top" ]; then openwith=exo-open ; fi
  26. #add quotes to the file name, just in case it has spaces
  27. EXEC2="'"$decoded"'"
  28. #launch the selected file
  29. run=$(echo $openwith $EXEC2)
  30. eval $run
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand