aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2020-05-05 09:57:50 +1200
committerTom Ryder <tom@sanctum.geek.nz>2020-05-05 09:57:50 +1200
commit6ce3785931e310e67be93ab373e2a153710b5807 (patch)
treec489d9c91f2a999ab71dc4db418becdf45330eee
parentAdd Bcc and terminating columns to Mutt pager hdrs (diff)
downloaddotfiles-6ce3785931e310e67be93ab373e2a153710b5807.tar.gz
dotfiles-6ce3785931e310e67be93ab373e2a153710b5807.zip
Add msc(1df)
-rw-r--r--.gitignore1
-rw-r--r--Makefile1
-rw-r--r--README.md1
-rwxr-xr-xbin/msc.sh12
-rw-r--r--man/man1/msc.1df12
5 files changed, 27 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 9b244d4d..b2601fbc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -73,6 +73,7 @@
/bin/mkvi
/bin/mode
/bin/motd
+/bin/msc
/bin/murl
/bin/mw
/bin/nlbr
diff --git a/Makefile b/Makefile
index 098907c8..498af984 100644
--- a/Makefile
+++ b/Makefile
@@ -160,6 +160,7 @@ BINS = bin/ap \
bin/mkvi \
bin/mode \
bin/motd \
+ bin/msc \
bin/murl \
bin/mw \
bin/nlbr \
diff --git a/README.md b/README.md
index b75c368f..6346c455 100644
--- a/README.md
+++ b/README.md
@@ -551,6 +551,7 @@ These scripts are installed by the `install-bin` target:
* `mkcp(1df)` creates a directory and copies preceding arguments into it.
* `mkmv(1df)` creates a directory and moves preceding arguments into it.
* `motd(1df)` shows the system MOTD.
+* `msc(1df)` crudely counts messages in an mbox.
* `mw(1df)` prints alphabetic space-delimited words from the input one per
line.
* `oii(1df)` runs a command on input only if there is any.
diff --git a/bin/msc.sh b/bin/msc.sh
new file mode 100755
index 00000000..feb39b14
--- /dev/null
+++ b/bin/msc.sh
@@ -0,0 +1,12 @@
+# Crudely but quickly count mail in the user's inbox, if we can find it
+username=$(id -nu)
+if [ "$#" -eq 0 ] ; then
+ set -- "$MAIL" /var/mail/"$username" /var/spool/mail/"$username"
+fi
+for path ; do
+ [ -e "$path" ] || continue
+ grep -ch -- '^From ' "$path"
+ exit
+done
+printf >&2 'Couldn'\''t find user mail spool; provide it as an argument...?\n'
+exit 1
diff --git a/man/man1/msc.1df b/man/man1/msc.1df
new file mode 100644
index 00000000..b8aadb11
--- /dev/null
+++ b/man/man1/msc.1df
@@ -0,0 +1,12 @@
+.TH MSC 1df "May 2020" "Manual page for msc"
+.SH NAME
+.B msc
+\- count the messages in a user's mail spool or other mbox
+.SH SYNOPSIS
+.B msc
+.SH DESCRIPTION
+.B msc
+counts the messages in the given mailboxes, or the user mail spool if not
+provided and it can be found in the MAIL env var or at common paths.
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>