From a2755d82f7beae4d82f148b58f6273e3c83983fc Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Wed, 2 Feb 2022 09:02:13 -0500 Subject: [PATCH] Add p function --- home/lib/login_functions.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/home/lib/login_functions.sh b/home/lib/login_functions.sh index 75cfd1d..0ff4e86 100644 --- a/home/lib/login_functions.sh +++ b/home/lib/login_functions.sh @@ -1,5 +1,33 @@ # +## p : string -> unit +p() { + awk \ + -v _s="$1" \ + ' + BEGIN {_s = tolower(_s)} + + /^[a-zA-Z]/ && tolower($1) ~ _s && NF >= 2 { + s = $1 + p = $NF + if (NF == 2) { + e = "" + u = "" + } else if (NF == 3) { + e = $2 + u = "" + } else { + e = $2 + u = $3 + } # TODO What would NF > 4 mean? + printf("s:\"%s\", e:\"%s\", u:\"%s\"\n", s, e, u) > "/dev/stderr" + printf "%s", p # XXX Intentionally avoiding newline in the result. + } + ' \ + ~/._p/p \ + | xsel -i -b -t 30000 +} + ## web search ## ws : string -> unit ws() { -- 2.20.1