bm (1836 bytes)
1 #!/bin/sh 2 3 # Don't forget to set $BOOKMARKS and $USERTAGS to files somewhere. 4 # TODO: 5 # - prevent duplicate URLs 6 # - make the top tag a null tag so a user accidentally pressing ENTER twice doesn't close out the tag dialogue 7 8 DMENULINES=15 9 10 check () { 11 [ -z "$1" ] && exit 1 12 } 13 14 help () { 15 printf 'Call without an argument to be prompted with dmenu.\n' 16 printf 'Flags:\n-h, --help\n-c, --copy\n-a, --add\n-e, --edit\n' 17 } 18 19 copy () { 20 sort -t2 "$BOOKMARKS" | dmenu -i -l $DMENULINES -p "bookmark:" | cut -f 1 -d ' ' | xclip -i -selection clipboard 21 } 22 23 add () { 24 url="$(xclip -o | dmenu -p 'url: ')" 25 check "$url" 26 desc="$(printf "" | dmenu -p 'description: ')" 27 tag="" 28 tags="" 29 while [ "$tag" != "done" ] ; do 30 tags="$tags $tag" 31 tag="$(printf "done | (choose when done)\n$(cat $USERTAGS)" \ 32 | dmenu -i -l $DMENULINES -p 'tags: ' | sed 's/ *|.*$//')" 33 done 34 tags="$(printf "$tags" | tr ' ' '\n' | sort | uniq | tr '\n' ' ' \ 35 | sed 's/ $//')" 36 37 printf "%s %s | %s\\n" "$url" "$desc" "$tags" >> "$BOOKMARKS" 38 } 39 40 edit () { 41 echo "Not implemented. Edit \$BOOKMARKS yourself at $BOOKMARKS." && exit 1 42 } 43 44 plumb () { 45 echo "Not implemented" && exit 1 46 } 47 48 promptflag () { 49 action="$(printf 'copy\nadd\nedit (not implemented)\nplumb (not implemented)' | dmenu -l 4 -p 'action:')" 50 [ "$action" = "copy" ] && copy 51 [ "$action" = "edit" ] && edit 52 [ "$action" = "add" ] && add 53 [ "$action" = "plumb" ] && plumb 54 55 exit 0 56 } 57 58 [ "$1" = '-h' ] || [ "$1" = '--help' ] && help 59 [ "$1" = '-c' ] || [ "$1" = '--copy' ] && copy 60 [ "$1" = '-a' ] || [ "$1" = '--add' ] && add 61 [ "$1" = '-e' ] || [ "$1" = '--edit' ] && edit 62 [ "$1" = '-e' ] || [ "$1" = '--plumb' ] && plumb 63 [ -z "$1" ] && promptflag 64 [ -n "$2" ] && echo "Too many arguments: use one or none." && exit 1