From 5a68bfbec1878f4f1ad7b04970afbe2d798b2f03 Mon Sep 17 00:00:00 2001 From: amolinae06 Date: Sun, 22 Jun 2025 22:21:48 -0600 Subject: [PATCH] personal config --- .gitignore | 3 ++- Makefile | 4 +++- config.def.h | 3 +++ config.h | 22 ++++++++++++++++++++++ mew.1 | 6 +++++- mew.c | 20 +++++++++++++++++--- pinentry-mew | 16 ++++++++++++++++ 7 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 config.h create mode 100755 pinentry-mew diff --git a/.gitignore b/.gitignore index 55fd519..ddac529 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ mew -config.h *.o *-protocol.* +*.orig +*.rej diff --git a/Makefile b/Makefile index 6842ccc..86cb277 100644 --- a/Makefile +++ b/Makefile @@ -56,9 +56,10 @@ clean: install: all mkdir -p $(DESTDIR)$(PREFIX)/bin - cp -f mew mew-run $(DESTDIR)$(PREFIX)/bin + cp -f mew mew-run pinentry-mew $(DESTDIR)$(PREFIX)/bin chmod 755 $(DESTDIR)$(PREFIX)/bin/mew chmod 755 $(DESTDIR)$(PREFIX)/bin/mew-run + chmod 755 $(DESTDIR)$(PREFIX)/bin/pinentry-mew mkdir -p $(DESTDIR)$(MANPREFIX)/man1 sed "s/VERSION/$(VERSION)/g" < mew.1 > $(DESTDIR)$(MANPREFIX)/man1/mew.1 chmod 644 $(DESTDIR)$(MANPREFIX)/man1/mew.1 @@ -66,6 +67,7 @@ install: all uninstall: rm -f $(DESTDIR)$(PREFIX)/bin/mew \ $(DESTDIR)$(PREFIX)/bin/mew-run \ + $(DESTDIR)$(PREFIX)/bin/pinentry-mew \ $(DESTDIR)$(MANPREFIX)/man1/mew.1 .PHONY: all clean install uninstall diff --git a/config.def.h b/config.def.h index 3cfa4da..5e686cf 100644 --- a/config.def.h +++ b/config.def.h @@ -17,6 +17,9 @@ static const char *output_name = NULL; /* -l option; if nonzero, use vertical list with given number of lines */ static unsigned int lines = 0; +/* -p option; display input as asterisks */ +static int passwd = 0; + /* * Characters not considered part of a word while deleting words * for example: " /?\"&[]" diff --git a/config.h b/config.h new file mode 100644 index 0000000..e67efac --- /dev/null +++ b/config.h @@ -0,0 +1,22 @@ +/* See LICENSE file for copyright and license details. */ +/* Default settings; can be overriden by command line. */ + +static int top = 1; /* -b option; if 0, appear at bottom */ +static const char *fonts[] = { "Inconsolata:size=14" }; /* -f option overrides fonts[0] */ +static const char *prompt = NULL; /* -p option; prompt to the left of input field */ +#include "/home/amolinae/.cache/wal/colors-wal-mew.h" + +/* -m option; if provided, use that output instead of default output */ +static const char *output_name = NULL; + +/* -l option; if nonzero, use vertical list with given number of lines */ +static unsigned int lines = 0; + +/* -p option; display input as asterisks */ +static int passwd = 0; + +/* + * Characters not considered part of a word while deleting words + * for example: " /?\"&[]" + */ +static const char worddelimiters[] = " "; diff --git a/mew.1 b/mew.1 index 5c9b703..42b6bef 100644 --- a/mew.1 +++ b/mew.1 @@ -3,7 +3,7 @@ mew \- menu for wayland .SH SYNOPSIS .B mew -.RB [ \-beiv ] +.RB [ \-beivP ] .RB [ \-l .IR lines ] .RB [ \-o @@ -46,6 +46,10 @@ passing focus to the application ran. .B \-i matches menu items case insensitively. .TP +.B \-P +do not directly display the keyboard input, but instead replace it with asterisks. +All data from stdin will be ignored. +.TP .BI \-l " lines" lists item vertically, with the given number of lines. .TP diff --git a/mew.c b/mew.c index 44aaf89..87b0143 100644 --- a/mew.c +++ b/mew.c @@ -280,6 +280,7 @@ drawmenu(void) unsigned int curpos; struct item *item; int x = 0, y = 0, w; + char *censort; DrwBuf *buf; errno = 0; @@ -297,7 +298,13 @@ drawmenu(void) /* draw input field */ w = (lines > 0 || !matches) ? mw - x : inputw; drwl_setscheme(drw, colors[SchemeNorm]); - drwl_text(drw, x, 0, w, bh, lrpad / 2, text, 0); + if (passwd) { + censort = calloc(1, sizeof(text)); + memset(censort, '*', strlen(text)); + drwl_text(drw, x, 0, w, bh, lrpad / 2, censort, 0); + free(censort); + } else + drwl_text(drw, x, 0, w, bh, lrpad / 2, text, 0); curpos = TEXTW(text) - TEXTW(&text[cursor]); if ((curpos += lrpad / 2 - 1) < w) { @@ -908,6 +915,11 @@ readstdin(void) size_t i, itemsiz = 0, linesiz = 0; ssize_t len; + if (passwd) { + inputw = lines = 0; + return; + } + /* read each line from stdin and add it to the item list */ for (i = 0; (len = getline(&line, &linesiz, stdin)) != -1; i++) { if (i + 1 >= itemsiz) { @@ -1003,7 +1015,7 @@ setup(void) static void usage(void) { - die("usage: mew [-beiv] [-l lines] [-p prompt] [-f font] [-o output]\n" + die("usage: mew [-beivP] [-l lines] [-p prompt] [-f font] [-o output]\n" " [-nb color] [-nf color] [-sb color] [-sf color]"); } @@ -1024,7 +1036,9 @@ main(int argc, char *argv[]) else if (!strcmp(argv[i], "-i")) { fstrncmp = strncasecmp; fstrstr = cistrstr; - } else if (i + 1 == argc) + } else if (!strcmp(argv[i], "-P")) + passwd = 1; + else if (i + 1 == argc) usage(); else if (!strcmp(argv[i], "-l")) lines = atoi(argv[++i]); diff --git a/pinentry-mew b/pinentry-mew new file mode 100755 index 0000000..839ed14 --- /dev/null +++ b/pinentry-mew @@ -0,0 +1,16 @@ +#!/bin/sh +# ported from pinentry-dmenu + +echo 'OK Pleased to meet you' + +while read -r stdin; do + case $stdin in + *BYE*) exit ;; + *SETDESC*) KEYNAME=${stdin#*:%0A%22}; KEYNAME=${KEYNAME%\%22\%0A*}; KEYID=${stdin#*ID }; KEYID=${KEYID%,*} ;; + *GETPIN*) printf 'D %s\n' $(mew -P -p "pinentry: $KEYNAME ($KEYID) ${error:+$error }$prompt") ;; + *SETERROR*) error="${stdin#*\ }"; ;; + *SETPROMPT*) prompt="${stdin#*\ }"; ;; + esac + + echo OK +done