Add script to periodicaly watch imaps server. Some ergonomic improvements

This commit is contained in:
Jérémie SALVI
2024-12-20 12:14:08 +01:00
parent e209f50540
commit afbb56bd25
9 changed files with 74 additions and 10 deletions

1
.gitignore vendored
View File

@@ -1,4 +1,5 @@
scripts/variables
scripts/imap_creds
links/X11/.Xresources
links/dunst/dunstrc
links/polybar/colors.ini

7
icons/gmail.svg Normal file
View File

@@ -0,0 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="52 42 88 66">
<path fill="#4285f4" d="M58 108h14V74L52 59v43c0 3.32 2.69 6 6 6"/>
<path fill="#34a853" d="M120 108h14c3.32 0 6-2.69 6-6V59l-20 15"/>
<path fill="#fbbc04" d="M120 48v26l20-15v-8c0-7.42-8.47-11.65-14.4-7.2"/>
<path fill="#ea4335" d="M72 74V48l24 18 24-18v26L96 92"/>
<path fill="#c5221f" d="M52 51v8l20 15V48l-5.6-4.2c-5.94-4.45-14.4-.22-14.4 7.2"/>
</svg>

After

Width:  |  Height:  |  Size: 419 B

View File

@@ -16,13 +16,10 @@ scrollback_indicator_opacity 0.5
#Url
open_url_with firefox
underline_hyperlinks always
copy_on_select clipboard
select_by_word_characters @-./_~?&%+#
select_by_word_characters @-./_~?&%+#!
sync_to_monitor yes
# Layout
@@ -49,3 +46,6 @@ map alt+left previous_tab
map alt+right next_tab
map alt+tab next_tab
map alt+t set_tab_title
# Copy paste
map ctrl+alt+c copy_to_clipboard
map ctrl+alt+v paste_from_clipboard

View File

@@ -170,6 +170,24 @@ format-prefix-font = 2
format-prefix-padding-right = 5px
format-prefix-foreground=${colors.primary}
[module/watchdog]
type = custom/script
exec = /usr/local/share/dotfiles/scripts/mailbox.sh count
interval = 30
format = <label>
#format-prefix = "✗ "
format-prefix = " "
format-prefix-font = 2
format-prefix-padding-right = 5px
format-prefix-foreground=${colors.primary}
format-fail = <label-fail>
format-fail-prefix = "✗ "
format-fail-prefix-font = 0
format-fail-prefix-foreground=${colors.alert}
click-left = /usr/local/share/dotfiles/scripts/mailbox.sh fetch
[module/dateprefix]
type = custom/text

View File

@@ -18,6 +18,7 @@ padding-right = 0px
font-0 = ComicShannsMono Nerd Font:size=14;2
font-1 = ComicShannsMono Nerd Font:size=14;1
font-2 = ComicShannsMono Nerd Font:size=14;0
font-3 = DejaVuSansM Nerd Font:size=14;0
fixed-center = true
modules-left = arch separator cpu separator memory separator filesystemprefix filesystem separator eth separator ethspeed separator pulseaudio
@@ -49,11 +50,12 @@ padding-right = 0px
font-0 = ComicShannsMono Nerd Font:size=14;2
font-1 = ComicShannsMono Nerd Font:size=14;1
font-2 = ComicShannsMono Nerd Font:size=14;0
font-3 = DejaVuSansM Nerd Font:size=14;0
fixed-center = true
modules-left = arch separator cpu separator memory separator filesystemprefix filesystem separator eth separator ethspeed separator pulseaudio
modules-center = i3
modules-right = pacman separator xkeyboard separator dateprefix date systray
modules-right = watchdog separator pacman separator xkeyboard separator dateprefix date systray
cursor-click = pointer
cursor-scroll = ns-resize

View File

@@ -1,8 +1,8 @@
#!/bin/bash
export BROWSER="/usr/bin/firefox"
#export BROWSER="/usr/bin/firefox"
export EDITOR="nvim"
export TERMINAL="rxvt-unicode"
export TERM="xterm"
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_CACHE_HOME="$HOME/.cache"

View File

@@ -56,9 +56,6 @@ PATH=/games:/usr/local/sbin:/usr/local/bin:/usr/bin
HISTSIZE=1000
HISTTIMEFORMAT="%F %T "
# Term config
TERM=xterm
neofetch
if [ -z "$DISPLAY" ] && [ "$XDG_VTNR" = 1 ]; then

View File

@@ -0,0 +1,4 @@
_USER="user@example.com"
_PASSWD="mypassword"
_SERVER="example.com"
_FOLDER="INBOX"

35
scripts/mailbox.sh Executable file
View File

@@ -0,0 +1,35 @@
#!/bin/bash
set -e
cd -- "$(dirname -- "$0")"
_DIRNAME="$(pwd)"
source ./imap_creds
if [[ -n $1 ]] && [[ $1 == "count" ]]
then
_COUNT=$(curl -u "$_USER:$_PASSWD" "imaps://$_SERVER" -X "STATUS $_FOLDER (UNSEEN)" 2>/dev/null | \
sed -e 's/)\r//' -e 's/.*UNSEEN //')
printf "%s" "$_COUNT"
(( _COUNT == 0 )) && exit 0
exit 1
fi
if [[ -n $1 ]] && [[ $1 == "fetch" ]]
then
_UNSEEN="$(curl -u 'beastie:}q6658JD~{}{oiRWsb~Q{P@SV=Qsy,ae' "imaps://$_SERVER/$_FOLDER" -X "SEARCH UNSEEN" 2>/dev/null | \
sed -e "s/\\r//" -e "s/* SEARCH //" -e "s/ /,/g")"
_MAILS=$(curl -v -u "$_USER:$_PASSWD" "imaps://$_SERVER/$_FOLDER" -X "FETCH $_UNSEEN BODY.PEEK[HEADER.FIELDS (From Subject)]" 2>&1 | \
grep -E "From:|Subject:" | sed -e 's/< //' -e 's/Subject/\nSubject/')
dunstify -I ../icons/gmail.svg \
"" "$_MAILS"
printf "%s" "$_MAILS"
exit 0
fi
cat <<EOF
Usage:
mailbox.sh count => Count unseen mails in $_FOLDER
mailbox.sh fetch => Fetch "From:" and "Subject:" from unseen mails in $_FOLDER
EOF