sites

mirror of git://git.suckless.org/sites
Log | Files | Refs

right_click_to_plumb.diff (1543B)


      1 diff --git a/st.c b/st.c
      2 index ae93ade..ff531a3 100644
      3 --- a/st.c
      4 +++ b/st.c
      5 @@ -218,6 +218,8 @@ char *opt_line  = NULL;
      6  char *opt_name  = NULL;
      7  char *opt_title = NULL;
      8  int oldbutton   = 3; /* button event on startup: 3 = release */
      9 +char *cwd = NULL;
     10 +char *plumber_cmd = plumber;
     11  
     12  static CSIEscape csiescseq;
     13  static STREscape strescseq;
     14 @@ -1858,6 +1860,9 @@ strhandle(void)
     15  	switch (strescseq.type) {
     16  	case ']': /* OSC -- Operating System Command */
     17  		switch (par) {
     18 +		case 7:
     19 +			if (narg > 1 && access(strescseq.args[1], X_OK) != -1)
     20 +				cwd = strescseq.args[1];
     21  		case 0:
     22  		case 1:
     23  		case 2:
     24 diff --git a/x.c b/x.c
     25 index fbfd350..02ba92d 100644
     26 --- a/x.c
     27 +++ b/x.c
     28 @@ -140,6 +140,9 @@ static DC dc;
     29  static XWindow xw;
     30  static XSelection xsel;
     31  
     32 +extern char *cwd;
     33 +extern char *plumber_cmd;
     34 +
     35  /* Font Ring Cache */
     36  enum {
     37  	FRC_NORMAL,
     38 @@ -512,6 +515,9 @@ xsetsel(char *str, Time t)
     39  void
     40  brelease(XEvent *e)
     41  {
     42 +	pid_t child;
     43 +	char cmd[100 + strlen(cwd)];
     44 +
     45  	if (IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
     46  		mousereport(e);
     47  		return;
     48 @@ -519,6 +525,15 @@ brelease(XEvent *e)
     49  
     50  	if (e->xbutton.button == Button2) {
     51  		xselpaste();
     52 +	} else if (e->xbutton.button == Button3) {
     53 +		switch(child = fork()) {
     54 +			case -1: 
     55 +				return;
     56 +			case 0: 
     57 +				sprintf(cmd, "(cd %s ; %s %s)", cwd, plumber_cmd, sel.primary);
     58 +				execvp( "sh", (char *const []){ "/bin/sh", "-c", cmd, 0 });
     59 +				exit(127);
     60 +		}
     61  	} else if (e->xbutton.button == Button1) {
     62  		if (sel.mode == SEL_READY) {
     63  			getbuttoninfo(e);