diff --git a/Makefile b/Makefile index 4647efe..7e33b31 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,9 @@ OS = $(shell uname -s) ifeq ($(OS), Darwin) - PREFIX = /usr/local + PREFIX ?= /usr/local else - PREFIX = /usr + PREFIX ?= /usr endif MANPREFIX = $(PREFIX)/share/man @@ -18,10 +18,7 @@ install: for shared in share/*; do \ cp -f $$shared $(DESTDIR)$(PREFIX)/share/mutt-wizard; \ done - if [ "$(OS)" = "Darwin" ]; then \ - sed -iba 's/\/usr\//\/usr\/local\//' $(DESTDIR)$(PREFIX)/share/mutt-wizard/mutt-wizard.muttrc; \ - rm $(DESTDIR)$(PREFIX)/share/mutt-wizard/mutt-wizard.muttrcba; \ - fi + sed -i 's,/usr,$(PREFIX),' $(DESTDIR)$(PREFIX)/share/mutt-wizard/mutt-wizard.muttrc; mkdir -p $(DESTDIR)$(MANPREFIX)/man1 cp -f mw.1 $(DESTDIR)$(MANPREFIX)/man1/mw.1 @@ -30,5 +27,6 @@ uninstall: rm -f $(DESTDIR)$(PREFIX)/$$script; \ done rm -rf $(DESTDIR)$(PREFIX)/share/mutt-wizard + rm -rf $(DESTDIR)$(MANPREFIX)/man1/mw.1 .PHONY: install uninstall diff --git a/bin/mw b/bin/mw index 461b382..385af66 100755 --- a/bin/mw +++ b/bin/mw @@ -1,14 +1,16 @@ #!/bin/sh -if [ -z "$prefix" ]; then - case "$(uname)" in - Linux) prefix="/usr" ;; - *) prefix="/usr/local" ;; - esac -fi - VERSION="2.0" +if [ "${BASH_SOURCE[0]}" = "${0}" ]; then + prefix=${0} +else + prefix="$BASH_SOURCE" +fi +[ ! ${prefix::1} = "/" ] && prefix="$PWD/$prefix" +prefix="${prefix%/bin/*}" +mwbin="$prefix/bin/mw" + _MW_="mutt-wizard" _MW_generated="mutt-wizard-generated" @@ -428,7 +430,7 @@ _mwcron() { read -r mwcronminutes printf "\033[0m" done - (crontab -l; echo "*/$mwcronminutes * * * * export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus; export DISPLAY=:0; $(type mw | cut -d' ' -f3) sync") \ + (crontab -l; echo "*/$mwcronminutes * * * * export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus; export DISPLAY=:0; $mwbin sync") \ | crontab - && echo "mw cronjob added. Mail will sync every $mwcronminutes minutes. Be sure you have your cron manager running." } @@ -645,7 +647,7 @@ _mwsyncandnotify() { else $mwmbsyncbin $mwaddr fi - [ -z "$mwnono" ] && return + [ -n "$mwnono" ] && return mwlastrun="$mwaccmaildir/.mw.lastrun" mwnew=$(find "$mwaccmaildir/INBOX/new/" "$mwaccmaildir/Inbox/new/" "$mwaccmaildir/inbox/new/" -type f -newer "$mwlastrun" 2> /dev/null) newcount=$(echo "$mwnew" | sed '/^\s*$/d' | wc -l) diff --git a/test/dotests b/test/dotests index 2087252..6d96ebb 100755 --- a/test/dotests +++ b/test/dotests @@ -7,9 +7,7 @@ bats --tap test_mw.bats echo echo "Integration tests need working email $mwaddr" -echo "CTRL-C to skip" -#modify if [ -z "$MAILDIR" ] || [ -z "$mwaddr" ]; then echo "First do:" [ -z "$MAILDIR" ] && echo "export MAILDIR=..." @@ -17,11 +15,15 @@ if [ -z "$MAILDIR" ] || [ -z "$mwaddr" ]; then exit fi -cd .. && sudo make install && OK="OK" +export PREFIX=$PWD/mwtesttmp +export PATH=$PATH:$PREFIX/bin + +cd .. && make install && OK="OK" if [ "$OK" = "OK" ]; then echo "Warning: Out with CTRL-C if your mail (config) files are important here." + read export mwmaildir=$MAILDIR export mwname='r n' @@ -34,6 +36,7 @@ if [ "$OK" = "OK" ]; then [ -f "${PASSWORD_STORE_DIR:-~/.password-store}/$mwpass.gpg" ] || pass insert $mwpass echo "= Test 1 =" + echo $PATH mwtype=online mw add echo "=> In another prompt, start mutt and verify that mails are shown" echo "=> Then answer with N" @@ -53,3 +56,6 @@ if [ "$OK" = "OK" ]; then fi cd $CD + +rm -rf $PREFIX + diff --git a/test/test_mw.bats b/test/test_mw.bats index f1c12a6..5d0ac8b 100644 --- a/test/test_mw.bats +++ b/test/test_mw.bats @@ -20,7 +20,6 @@ setup() XDG_CONFIG_HOME=mwtesttmp/config \ MAILDIR=mwtesttmp/share/mail \ XDG_CACHE_HOME=mwtesttmp/cache \ - prefix="$PWD" \ source ../bin/mw export NOTMUCH_CONFIG=mwtesttmp/config/notmuch-config export mwname="real name"