Update some scripts
This commit is contained in:
parent
83fb9a083a
commit
697c7e105f
|
@ -1,14 +1,21 @@
|
||||||
#!/bin/zsh
|
#!/bin/zsh
|
||||||
versions=$(curl -L https://api.github.com/repos/lihaoyi/Ammonite/releases/latest)
|
versions=$(curl -sL https://api.github.com/repos/lihaoyi/Ammonite/releases/latest)
|
||||||
|
|
||||||
download-version() {
|
download-version() {
|
||||||
(
|
version=$(jq ".assets | map(select(.name | startswith(\"$1\")))[0]" <<<$versions)
|
||||||
echo "#/usr/bin/env python --version sh" && \
|
target=$(jq -r ".browser_download_url" <<<$version)
|
||||||
curl -L $( echo -E $versions \
|
timestamp=$(jq -r ".updated_at" <<<$version)
|
||||||
| jq -r ".assets | map(select(.name | startswith(\"$1\")))[0].browser_download_url")
|
|
||||||
) > $2
|
if [[ $1 == "-n" ]]; then
|
||||||
|
echo $target
|
||||||
|
elif [[ $(date -d $timestamp +%s) -lt $(date -r $2 +%s) ]]; then
|
||||||
|
echo "No update for $1"
|
||||||
|
else
|
||||||
|
echo "Updating $1 to $(jq .name <<<$version)"
|
||||||
|
curl -L $target > $2
|
||||||
chmod +x $2
|
chmod +x $2
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
download-version 2.13 $(which amm)2.13
|
download-version 2.13 $(which amm)2.13
|
||||||
download-version 2.12 $(which amm)2.12
|
download-version 2.12 $(which amm)2.12
|
||||||
download-version 3.1 $(which amm)3
|
download-version 3.2 $(which amm)3
|
||||||
|
|
|
@ -31,7 +31,7 @@ notify() {
|
||||||
|
|
||||||
|
|
||||||
events=$(khal list now 1h)
|
events=$(khal list now 1h)
|
||||||
if [[ $events == "no events" ]]; then
|
if [[ $events == "No events" ]]; then
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
notify "Upcoming events" "$(tail -n +2 <<<"$events"| awk '{printf("%s%s", sep, $0); sep="<br>"} END {print ""}')" "$(find /usr/share/icons/ -ipath \*48x48/\*appointment-soon.\* | head -n 1)"
|
notify "Upcoming events" "$(tail -n +2 <<<"$events"| awk '{printf("%s%s", sep, $0); sep="<br>"} END {print ""}')" "$(find /usr/share/icons/ -ipath \*48x48/\*appointment-soon.\* | head -n 1)"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env amm
|
#!/usr/bin/env amm
|
||||||
|
|
||||||
import $ivy.`com.sun.mail:javax.mail:1.6.2`
|
import $ivy.`com.sun.mail:javax.mail:1.6.2`
|
||||||
import $ivy.`com.lihaoyi::os-lib:0.7.1`
|
import $ivy.`com.lihaoyi::os-lib:0.8.1`
|
||||||
|
|
||||||
import javax.mail.internet._
|
import javax.mail.internet._
|
||||||
import os.up
|
import os.up
|
||||||
|
@ -12,25 +12,29 @@ val icon = "/usr/share/icons/Adwaita/48x48/actions/mail-message-new.png"
|
||||||
val cacheFile = envPath("XDG_CACHE_HOME", os.home/".cache") / "seen-mails"
|
val cacheFile = envPath("XDG_CACHE_HOME", os.home/".cache") / "seen-mails"
|
||||||
val maildir = envPath("MAILDIR", os.home/"Mail")
|
val maildir = envPath("MAILDIR", os.home/"Mail")
|
||||||
|
|
||||||
|
def from(msg: MimeMessage): String =
|
||||||
|
msg.getFrom.headOption
|
||||||
|
.map(_.asInstanceOf[InternetAddress])
|
||||||
|
.map(addr => Option(addr.getPersonal).map(_.replace("&", "&")).getOrElse(addr.getAddress))
|
||||||
|
.getOrElse("unknown")
|
||||||
|
|
||||||
|
|
||||||
case class MailInfo(from: String, subject: String, mailbox: String)
|
case class MailInfo(from: String, subject: String, mailbox: String)
|
||||||
object MailInfo {
|
object MailInfo:
|
||||||
def fromPath(p: os.Path, maildir: os.Path) = {
|
def fromPath(p: os.Path, maildir: os.Path) =
|
||||||
val msg = readMessage(p)
|
val msg = readMessage(p)
|
||||||
val address = msg.getFrom.head.asInstanceOf[InternetAddress]
|
val address = msg.getFrom.head.asInstanceOf[InternetAddress]
|
||||||
MailInfo(
|
MailInfo(
|
||||||
Option(address.getPersonal).map(_.replace("&", "&")).getOrElse(address.getAddress),
|
from(msg),
|
||||||
msg.getSubject.replace("&", "&"),
|
msg.getSubject.replace("&", "&"),
|
||||||
(p/up/up relativeTo maildir).toString
|
(p/up/up relativeTo maildir).toString
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val session = javax.mail.Session.getDefaultInstance(new java.util.Properties)
|
val session = javax.mail.Session.getDefaultInstance(new java.util.Properties)
|
||||||
|
|
||||||
def readMessage(path: os.Path) = {
|
def readMessage(path: os.Path): MimeMessage =
|
||||||
val in = os.read.inputStream(path)
|
val in = os.read.inputStream(path)
|
||||||
new MimeMessage(session, in)
|
new MimeMessage(session, in)
|
||||||
}
|
|
||||||
|
|
||||||
def envPath(envVar: String, default: os.Path): os.Path =
|
def envPath(envVar: String, default: os.Path): os.Path =
|
||||||
sys.env.get(envVar).map(s => os.Path(s)).getOrElse(default)
|
sys.env.get(envVar).map(s => os.Path(s)).getOrElse(default)
|
||||||
|
@ -45,9 +49,8 @@ val unseenMailPaths = newMailPaths &~ cache
|
||||||
|
|
||||||
val unseenMails = unseenMailPaths.map(p => MailInfo.fromPath(os.Path(p), maildir))
|
val unseenMails = unseenMailPaths.map(p => MailInfo.fromPath(os.Path(p), maildir))
|
||||||
|
|
||||||
if (!unseenMails.isEmpty) {
|
if !unseenMails.isEmpty then
|
||||||
val markup = unseenMails.map(msg => s"<b>${msg.from}:</b> ${msg.subject}<br>").mkString
|
val markup = unseenMails.map(msg => s"<b>${msg.from}:</b> ${msg.subject}<br>").mkString
|
||||||
os.proc("notify-send", s"--icon=$icon", "Mails", markup).call()
|
os.proc("notify-send", s"--icon=$icon", "Mails", markup).call()
|
||||||
}
|
|
||||||
|
|
||||||
os.write.over(cacheFile, newMailPaths.mkString("", "\n", "\n"))
|
os.write.over(cacheFile, newMailPaths.mkString("", "\n", "\n"))
|
||||||
|
|
|
@ -5,11 +5,10 @@
|
||||||
if [[ $2 ]]; then
|
if [[ $2 ]]; then
|
||||||
encoding=$2
|
encoding=$2
|
||||||
else
|
else
|
||||||
encoding=$(chardetect "$1" | grep -oP '(?<=: )\S*')
|
encoding='utf-8'
|
||||||
|
#encoding=$(chardetect "$1" | grep -op '(?<=: )\s*')
|
||||||
fi
|
fi
|
||||||
if ! iconv -f $encoding <<<"" &> /dev/null; then
|
if [[ $encoding != 'UTF-8' ]]; then
|
||||||
cat "$1"
|
|
||||||
elif [[ $encoding != 'utf-8' ]]; then
|
|
||||||
iconv -f $encoding -t 'utf-8' < "$1" | mdcat /dev/stdin
|
iconv -f $encoding -t 'utf-8' < "$1" | mdcat /dev/stdin
|
||||||
else
|
else
|
||||||
mdcat $1
|
mdcat $1
|
||||||
|
|
Loading…
Reference in a new issue