bookmark (967B)
1 #!/bin/sh 2 3 # XXX: make this an env variable? 4 BMK_DIR="${HOME}/n/bookmarks/" 5 6 bmk_getfile() 7 { 8 bmkfile="${BMK_DIR}" 9 10 while [ -d ${bmkfile} ]; do 11 bmkfile="$( 12 find ${bmkfile} -maxdepth 1 | 13 sed 1d | 14 sort | 15 dmenu -i -l 10 -p "Choose a file" 16 )" || exit 1 17 done 18 test -f ${bmkfile} || exit 1 19 } 20 21 bmk_add() 22 { 23 local url=$(xclip -o) 24 25 if grep -q "^${url}" ${bmkfile}; then 26 echo "Already bookmarked" | nfy 27 else 28 printf "%s\t%s\n" \ 29 "${url}" "$(dmenu -p "Bookmark name" </dev/null)" >> \ 30 ${bmkfile} 31 echo "Bookmark added" | nfy 32 fi 33 } 34 35 bmk_fmt() 36 { 37 for i in $(find ${BMK_DIR} | sed 1d); do 38 sed 's/ */\t/' < ${i} | column -ts $'\t' > ${i}.tmp 39 mv -f ${i}.tmp ${i} 40 done 41 } 42 43 while getopts "af" arg; do 44 case "${arg}" in 45 a) bmk_getfile 46 bmk_add 47 bmk_fmt 48 exit 0 ;; 49 f) bmk_fmt 50 exit 0 ;; 51 *) echo "usage: ${0##*/} [-af]" 1>&2 52 exit 1 ;; 53 esac 54 done 55 56 bmk_getfile 57 58 cat ${bmkfile} | dmenu -i -l 50 | awk '{print $1}' | 59 xargs -r xdotool type --delay 0