Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.3 KiB

4 years ago
4 years ago
4 years ago
  1. #!/bin/bash
  2. itemcache="${XDG_DATA_HOME:-$HOME/.cache}/wallabag-dmenu"
  3. DMENU=${DMENU:-dmenu}
  4. usage() {
  5. cat <<-EOF
  6. usage: dmenu-wallabag [-lah]
  7. -l List Entries
  8. -a Add an entry
  9. -h Print help
  10. EOF
  11. }
  12. update_items(){
  13. [ "$(date -r "$itemcache" "+%d-%m-%Y %H")" = "$(date '+%d-%m-%Y') %H" ] ||
  14. wallabag list | head -n -1 | tail -n +2 > $itemcache
  15. }
  16. list_entries() {
  17. update_items
  18. items="$(cat $itemcache)"
  19. selection=$(echo -e "$items\n~SYNC~" | dmenu -l 10 -p "Choose an article:")
  20. if [ "$selection" = "~SYNC~" ]; then
  21. wallabag list | head -n -1 | tail -n +2 > $itemcache
  22. items="$(cat $itemcache)"
  23. selection=$(echo "$items" | dmenu -l 10 -p "Choose an article:")
  24. fi
  25. if [ "$selection" = "" ]; then
  26. exit
  27. fi
  28. selection=$(echo "$selection" | cut -d" " -f1)
  29. wallabag update --read $selection
  30. wallabag open $selection
  31. wallabag list | head -n -1 | tail -n +2 > $itemcache
  32. }
  33. add_entry() {
  34. url=$(echo -n "" | dmenu -p "Enter URL:")
  35. if [ "$url" = "" ]; then
  36. exit
  37. fi
  38. wallabag add $url
  39. wallabag list | head -n -1 | tail -n +2 > $itemcache
  40. }
  41. while getopts ':lah' opt; do
  42. case "$opt" in
  43. l) list_entries ;;
  44. a) add_entry ;;
  45. h) usage && exit;;
  46. /?) echo "Unrecognized command: $OPTARG";;
  47. esac
  48. done