mail-xclip (2122 bytes)
1 #!/bin/sh 2 # depends on prompt-mail 3 4 DMENULINES=15 5 ALIASES="$(sed 's/[\\t ]*#.*//' "$XDG_CONFIG_HOME"/prompt-mail.conf | tr -d "\n" )" 6 7 help () { 8 echo "Call without an argument to be prompted with dmenu." 9 echo "Flags:" 10 printf "-h, --help\n-c, --copy\n-a, --add\n-e, --edit\n" 11 } 12 13 copy () { 14 prompt-mail | tr -d "\n" | xclip -i -selection clipboard 15 } 16 17 add () { 18 shrt="$(echo '' | dmenu -p 'short alias: ')" 19 [ -z "$shrt" ] && notify-send 'Need a short alias' && exit 1 20 grep -q "^alias $shrt" "$ALIASES" && notify-send 'That alias short name already exists' && exit 1 21 name="$(echo '' | dmenu -p 'real name: ')" 22 [ -z "$name" ] && notify-send 'Need a name' && exit 1 23 24 addr="$(echo "$($(xclip -o | grep '@') || echo '')" | dmenu -p 'address: ')" 25 [ -z "$addr" ] && notify-send 'Need an addr' && exit 1 26 echo "$addr" | grep -v '<\|>' && addr="<$addr>" 27 grep -q "$addr" "$ALIASES" && notify-send 'That alias already exists' && exit 1 28 29 comm="$(echo '' | dmenu -p 'comment: ')" 30 [ -n "$comm" ] && comm=" # $comm" 31 32 printf "alias %s %s %s %s\\n" "$shrt" "$name" "$addr" "$comm" >>"$ALIASES" 33 FAIL="$?" 34 [ $FAIL ] && notify-send "Successfully saved $shrt $name $addr $comm" 35 [ $FAIL ] || notify-send "Failed to save $shrt $name $addr $comm with status code $FAIL" 36 } 37 38 edit () { 39 echo "Not implemented. Edit \$ALIASES yourself at $ALIASES." && exit 1 40 } 41 42 plumb () { 43 echo "Not implemented" && exit 1 44 } 45 46 promptflag () { 47 action="$(printf 'copy\nadd\nedit (not implemented)\nplumb (not implemented)' | dmenu -l 4 -p 'action:')" 48 [ "$action" = "copy" ] && copy 49 [ "$action" = "edit" ] && edit 50 [ "$action" = "add" ] && add 51 [ "$action" = "plumb" ] && plumb 52 } 53 54 # Get the aliases location from the prompt-mail conf 55 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 64 [ -z "$1" ] && promptflag 65 [ -n "$2" ] && echo "Too many arguments: use one or none." && exit 1