diff options
| author | A Farzat <a@farzat.xyz> | 2024-10-24 23:02:13 +0900 | 
|---|---|---|
| committer | A Farzat <a@farzat.xyz> | 2024-11-04 23:02:13 +0900 | 
| commit | 510b0481e3dd2668783b4f664772d242b8d4abba (patch) | |
| tree | 84ee18219aea4bb73e70ad2d94c6e02dea81353b /bin/dmenu/mailtohandler | |
| parent | c68ac8e8d7524dcb448b7970ab7dacef93c47a4a (diff) | |
| download | dotfiles-510b0481e3dd2668783b4f664772d242b8d4abba.tar.gz dotfiles-510b0481e3dd2668783b4f664772d242b8d4abba.zip | |
Add dmenu scripts to handle links and emails
Diffstat (limited to 'bin/dmenu/mailtohandler')
| -rwxr-xr-x | bin/dmenu/mailtohandler | 68 | 
1 files changed, 68 insertions, 0 deletions
| diff --git a/bin/dmenu/mailtohandler b/bin/dmenu/mailtohandler new file mode 100755 index 0000000..b6af091 --- /dev/null +++ b/bin/dmenu/mailtohandler @@ -0,0 +1,68 @@ +#!/usr/bin/env bash + +cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}/mailtohandler" +store_file="$cache_dir/store" +[ -d "$cache_dir" ] || mkdir -p "$cache_dir" +if [ -f "$store_file" ]; then +	mapfile -d '' store_urls < "$store_file" +	urls=( "${store_urls[@]}" "$@" ) +else +	urls=( "$@" ) +fi + +command="$(dmenu -p "${#urls[@]} emails $(printf "%.50s" "${1#mailto:}")..." <<OPTIONS +neomutt +clipsep +clipmline +abook_add +store +store_clear +OPTIONS +)" + +case "$command" in +	neomutt) +		tmux neww -t social: neomutt -- "${urls[@]}" +		;; +	clipmline) +		for link in "${urls[@]}" +		do printf "%s\n" "${link#mailto:}" +		done | xclip -sel clip +		;; +	clipsep) +		for link in "${urls[@]}"; do +			printf "%s" "${link#mailto:}" | xclip -sel clip +			sleep 0.1 +		done +		;; +	abook_add) +		abook_file="$HOME/.abook/addressbook" +		abook_index="$(grep -E '^\[[0-9]+\]$' "$abook_file" | tail -n 1)" +		abook_index="${abook_index#[}" +		abook_index="${abook_index%]}" +		for link in "${urls[@]}" +		do +			abook_index=$((abook_index+1)) +			abook_name="$(dmenu -p "Name for ${link#mailto:}:" < /dev/null)" +			[ -n "$abook_name" ] && cat >> "$abook_file" <<ENTRY +[$abook_index] +name=$abook_name +email=${link#mailto:} + +ENTRY +		done +		;; +	store) +		for link in "${urls[@]}" +		do printf "%s\0" "$link" +		done > "$store_file" +		exit +		;; +	store_clear) +		;; +	*) +		exit +esac + +[ -f "$store_file" ] && rm "$store_file" +exit 0 | 
