dotfiles

My collection of dotfiles
git clone git://git.noxz.tech/dotfiles
Log | Files | Refs

dmenu_todo (759B)


      1 #!/bin/sh
      2 
      3 choice=""
      4 existing=""
      5 filename="$1"; shift;
      6 args=" $@"
      7 options=""
      8 
      9 [ ! -f "$filename" ] && exit 1
     10 
     11 while true; do
     12 	# get current todo with line numbering
     13 	options="$(awk '{print NR,$0}' "$filename")"
     14 
     15 	# get choice
     16 	choice="$(printf "$options" | dmenu_vtc${args})"
     17 	[ "$choice" = "" ] && exit 1
     18 
     19 	# get existing record
     20 	existing="$(printf "$options" | grep "^${choice}$")"
     21 
     22 	# check if existing or new
     23 	if [ "$existing" != "" ] && [ "${existing%%\ *}" -eq "${existing%%\ *}" ]; then
     24 		case "$(printf 'copy\ndelete' | dmenu_vtc${args})" in
     25 		copy)
     26 			printf "${existing#*\ }" | \
     27 				xclip -i -sel p -f | \
     28 				xclip -i -sel c
     29 			exit ;;
     30 		delete)
     31 			sed -i "${existing%%\ *}d" "$filename" ;;
     32 		esac
     33 	else
     34 		echo "${choice}" >> "$filename"
     35 	fi
     36 done