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.

52 lines
1.2 KiB

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. selection=$(echo "$selection" | cut -d" " -f1)
  26. wallabag update --read $selection
  27. wallabag open $selection
  28. wallabag list | head -n -1 | tail -n +2 > $itemcache
  29. }
  30. add_entry() {
  31. url=$(echo -n "" | dmenu -p "Enter URL:")
  32. wallabag add $url
  33. wallabag list | head -n -1 | tail -n +2 > $itemcache
  34. }
  35. while getopts ':lah' opt; do
  36. case "$opt" in
  37. l) list_entries ;;
  38. a) add_entry ;;
  39. h) usage && exit;;
  40. /?) echo "Unrecognized command: $OPTARG";;
  41. esac
  42. done