scripts

Random scripts
git clone git://git.margiolis.net/scripts.git
Log | Files | Refs | README | LICENSE

bookmark (726B)


      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 -qx "^${url}" ${bmkfile}; then
     26 		echo "Already bookmarked" | nfy
     27 	else
     28 		echo ${url} >> ${bmkfile}
     29 		echo "Bookmark added" | nfy
     30 	fi
     31 }
     32 
     33 while getopts "af" arg; do
     34 case "${arg}" in
     35 	a)	bmk_getfile
     36 		bmk_add
     37 		exit 0 ;;
     38 	*)	echo "usage: ${0##*/} [-a]" 1>&2
     39 		exit 1 ;;
     40 esac
     41 done
     42 
     43 bmk_getfile
     44 
     45 cat ${bmkfile} | dmenu -i -l 50 | awk '{print $1}' |
     46 xargs -r xdotool type --delay 0