From b5b1d77dfd83853b5f4a945e02fbc9269114fe05 Mon Sep 17 00:00:00 2001 From: epoch Date: Fri, 19 Aug 2022 01:24:02 -0500 Subject: limit a prompt to 64 characters --- choose | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/choose b/choose index 763c71c..aa191e7 100755 --- a/choose +++ b/choose @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash ### this script is meant to take a \n delimited list of things ### then give the user a way of selecting on of them. ### it should output the selection on a line by itself. @@ -11,6 +11,13 @@ if [ "$1" ];then else prompt="< $0 >" fi + +if [ "${prompt}" != "${prompt:0:64}" ];then + prompt="${prompt:0:64}..." +else + prompt="${prompt}" +fi + if [ $DISPLAY ];then #usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor] # [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid] -- cgit v1.2.3 From 511ebda349763dbdbaeb64fea5732e7953726bd3 Mon Sep 17 00:00:00 2001 From: epoch Date: Fri, 19 Aug 2022 02:11:19 -0500 Subject: added the ability to use blank match lines to match anything --- urigetline.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/urigetline.c b/urigetline.c index 4c5c7b4..92b4de7 100644 --- a/urigetline.c +++ b/urigetline.c @@ -80,6 +80,7 @@ int main(int argc,char *argv[]) {//argument needs to be the URI rule=MATCH_PATTERN; j=0; switch(a[0]) { + case 0: j=1; goto match; break; case '-': j=1; rule=MATCH_PATTERN; break; case 'n': j=1; rule=MATCH_UNEXIST; break; case 'r': j=1; rule=MATCH_REVERSE; break; @@ -120,6 +121,7 @@ int main(int argc,char *argv[]) {//argument needs to be the URI a=c; } if(matches) { +match: //printf("comm: %s\n",command); printf("%s\n",command); if(!all) return ret;//bail early if we only need first match -- cgit v1.2.3 From 96adcfcc7775e89f8a8d084215a07d3f2662c6a0 Mon Sep 17 00:00:00 2001 From: epoch Date: Fri, 19 Aug 2022 02:16:49 -0500 Subject: didn't actually need a goto. found a way to do it with one less line anyway --- urigetline.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/urigetline.c b/urigetline.c index 92b4de7..2de0126 100644 --- a/urigetline.c +++ b/urigetline.c @@ -77,10 +77,10 @@ int main(int argc,char *argv[]) {//argument needs to be the URI a=line; matches=1; for(;a;) { + if(!*a) break; rule=MATCH_PATTERN; j=0; switch(a[0]) { - case 0: j=1; goto match; break; case '-': j=1; rule=MATCH_PATTERN; break; case 'n': j=1; rule=MATCH_UNEXIST; break; case 'r': j=1; rule=MATCH_REVERSE; break; @@ -121,7 +121,6 @@ int main(int argc,char *argv[]) {//argument needs to be the URI a=c; } if(matches) { -match: //printf("comm: %s\n",command); printf("%s\n",command); if(!all) return ret;//bail early if we only need first match -- cgit v1.2.3 From 03762afa63c63f21c3e035aced349fb87d0352fb Mon Sep 17 00:00:00 2001 From: epoch Date: Fri, 19 Aug 2022 18:57:38 -0500 Subject: even less lines --- urigetline.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/urigetline.c b/urigetline.c index 2de0126..71d2149 100644 --- a/urigetline.c +++ b/urigetline.c @@ -76,8 +76,7 @@ int main(int argc,char *argv[]) {//argument needs to be the URI } a=line; matches=1; - for(;a;) { - if(!*a) break; + for(;a && *a;) { rule=MATCH_PATTERN; j=0; switch(a[0]) { -- cgit v1.2.3 From 994e230b637fa0be9ee2f949737ac1754d985704 Mon Sep 17 00:00:00 2001 From: epoch Date: Fri, 2 Sep 2022 01:30:50 -0500 Subject: urigetline now uses malloc()d space for its struct uri --- urigetline.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/urigetline.c b/urigetline.c index 71d2149..4963a84 100644 --- a/urigetline.c +++ b/urigetline.c @@ -35,7 +35,7 @@ int match(signed char rule,char *part,char *arg) { int main(int argc,char *argv[]) {//argument needs to be the URI int j; int ret=1; - struct uri u; + struct uri *u = malloc(sizeof(struct uri)); char matches; signed char rule=MATCH_PATTERN; char *line=malloc(LINE_LENGTH); @@ -57,9 +57,10 @@ int main(int argc,char *argv[]) {//argument needs to be the URI } if(argc < 2) { fprintf(stderr,"usage: urigetline [-a] uri < uristart.conf\n"); + free(u); return 1; } - urifromline(&u,argv[1]);//only argv[1] is a URI? + urifromline(u,argv[1]);//only argv[1] is a URI? for(;fgets(line,LINE_LENGTH-1,stdin);) {//each line comes from the config. we need to split it on spaces. if(strchr(line,'\r')) *strchr(line,'\r')=0; if(strchr(line,'\n')) *strchr(line,'\n')=0; @@ -90,6 +91,7 @@ int main(int argc,char *argv[]) {//argument needs to be the URI if(rule != MATCH_UNEXIST) { if(!(b=strchr(a,' '))) { fprintf(stderr,"argument '%s' wants a value in the next argument and didn't get it. throwing a fit. (pass -v to urigetline to help debug)\n",a); + free(u); return 2; } *b=0; b++; @@ -102,17 +104,18 @@ int main(int argc,char *argv[]) {//argument needs to be the URI } } switch(a[j]) { - case 's': if(!match(rule,u.scheme,b)) { matches=0;} break; - case 'u': if(!match(rule,u.username,b)) { matches=0;} break; - case 'k': if(!match(rule,u.password,b)) { matches=0;} break; - case 'd': if(!match(rule,u.domain,b)) { matches=0;} break; - case 'P': if(!match(rule,u.port,b)) { matches=0;} break; - case 'p': if(!match(rule,u.path,b)) { matches=0;} break; - case 'q': if(!match(rule,u.query_string,b)) { matches=0;} break; - case 'f': if(!match(rule,u.fragment_id,b)) { matches=0;} break; + case 's': if(!match(rule,u->scheme,b)) { matches=0;} break; + case 'u': if(!match(rule,u->username,b)) { matches=0;} break; + case 'k': if(!match(rule,u->password,b)) { matches=0;} break; + case 'd': if(!match(rule,u->domain,b)) { matches=0;} break; + case 'P': if(!match(rule,u->port,b)) { matches=0;} break; + case 'p': if(!match(rule,u->path,b)) { matches=0;} break; + case 'q': if(!match(rule,u->query_string,b)) { matches=0;} break; + case 'f': if(!match(rule,u->fragment_id,b)) { matches=0;} break; break; default: fprintf(stderr,"unknown url part letter! %s\n",a); + free(u); return 3; } //if(b) printf("two: %s %s\n",a,b); @@ -122,8 +125,12 @@ int main(int argc,char *argv[]) {//argument needs to be the URI if(matches) { //printf("comm: %s\n",command); printf("%s\n",command); - if(!all) return ret;//bail early if we only need first match + if(!all) { + free(u); + return ret;//bail early if we only need first match + } } } + free(u); return ret; } -- cgit v1.2.3