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.

73 lines
1.6 KiB

4 years ago
4 years ago
4 years ago
  1. #!/bin/sh
  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. -s Select Menu
  9. -a Add an entry
  10. -h Print help
  11. EOF
  12. }
  13. update_items(){
  14. [ "$(date -r "$itemcache" "+%d-%m-%Y %H")" = "$(date '+%d-%m-%Y') %H" ] ||
  15. wallabag list | head -n -1 | tail -n +2 > $itemcache
  16. }
  17. list_entries() {
  18. update_items
  19. items="$(cat $itemcache)"
  20. selection=$(echo -e "$items\n~SYNC~" | dmenu -l 10 -p "Choose an article:")
  21. if [ "$selection" = "~SYNC~" ]; then
  22. wallabag list | head -n -1 | tail -n +2 > $itemcache
  23. items="$(cat $itemcache)"
  24. selection=$(echo "$items" | dmenu -l 10 -p "Choose an article:")
  25. fi
  26. if [ "$selection" = "" ]; then
  27. exit
  28. fi
  29. selection=$(echo "$selection" | cut -d" " -f1)
  30. wallabag update --read $selection
  31. wallabag open $selection
  32. wallabag list | head -n -1 | tail -n +2 > $itemcache
  33. }
  34. add_entry() {
  35. url=$(echo -n "" | dmenu -p "Enter URL:")
  36. if [ "$url" = "" ]; then
  37. exit
  38. fi
  39. wallabag add $url
  40. wallabag list | head -n -1 | tail -n +2 > $itemcache
  41. }
  42. select_mode() {
  43. menu="Read\nAdd"
  44. action=$(echo -e "$menu" | dmenu -p "Select action: ")
  45. if [ "$action" = "" ]; then
  46. return
  47. fi
  48. if [ "$action" = "Read" ];then
  49. list_entries
  50. else
  51. add_entry
  52. fi
  53. }
  54. while getopts ':lahs' opt; do
  55. case "$opt" in
  56. l) list_entries ;;
  57. s) select_mode;;
  58. a) add_entry ;;
  59. h) usage && exit;;
  60. /?) echo "Unrecognized command: $OPTARG";;
  61. esac
  62. done