Hi,

this little patch adds the possibility to mrxvt to paste the contents
of a file to the currently active tab (documentation included).

---
Mrxvt.macro.Ctrl+Shift+x:  PasteFile ~/ms-env/data/cut-and-paste-profile
---

I added this feature because i`m a sysadmin and I own logins to various 
systems. I paste this profile everytime i login to a server or change 
a user with "su - <user>".
This patch uses "wordexp" to expand/glob defined filenames.

I would be happy to see this modification in mrxvt-head.

Apply this patch by executing:
---
cd mrxvt05b
patch -p0 -u < ../mrxvt_paste_file.diff
---

Best regards
Marc Schöchlin
Index: src/rxvtlib.h
===================================================================
--- src/rxvtlib.h	(revision 265)
+++ src/rxvtlib.h	(working copy)
@@ -787,6 +787,7 @@
     MacroFnScroll,
     MacroFnCopy,
     MacroFnPaste,
+    MacroFnPasteFile,
     MacroFnToggleSubwin,
     MacroFnFont,
     MacroFnToggleVeryBold,
Index: src/screen.c
===================================================================
--- src/screen.c	(revision 265)
+++ src/screen.c	(working copy)
@@ -37,6 +37,7 @@
 # include <xftacs.h>
 #endif
 
+#include <wordexp.h>
 
 /* ------------------------------------------------------------------------- */
 #ifdef MULTICHAR_SET
@@ -5051,6 +5052,53 @@
 
 /* ------------------------------------------------------------------------- */
 /*
+ * Paste the content of the file specified by filename to the 
+ * currently active tab 
+ * EXT: button 2 release
+ */
+/* EXTPROTO */
+void
+rxvt_paste_file(rxvt_t* r, int page, Time tm, int x, int y, char* filename)
+{
+  rxvt_dbgmsg ((DBG_DEBUG, DBG_SCREEN, "rxvt_paste_file %d (%lu, %d, %d) %s\n", page, tm, x, y, filename ));
+
+    if (x < 0 || x >= VT_WIDTH(r) || y < 0 || y >= VT_HEIGHT(r))
+	return;		/* outside window */
+
+  char buffer[256];
+  char TAINTED * str;
+  FILE * fdpaste;
+  wordexp_t p;
+  int wordexp_result;
+
+  /* perform a shell-like expansion of the provided filename */
+  wordexp_result = wordexp(filename, &p, 0);
+  if (wordexp_result == 0){
+   filename = *p.we_wordv;
+  }else{
+    rxvt_dbgmsg ((DBG_VERBOSE, DBG_SCREEN, 
+      "rxvt_paste_file : wordexp error code '%i ',problems on shell-like expansion of '%s' \n", 
+      filename, wordexp_result));
+  }
+
+  if (NOT_NULL(fdpaste = fopen( filename , "r"))){
+   while (NOT_NULL(str = fgets(buffer, sizeof(buffer), fdpaste)))
+   {
+	  rxvt_paste_str( r, page, (const unsigned char*) str , STRLEN(str));
+   }
+   fclose(fdpaste);
+  }else{
+    rxvt_dbgmsg ((DBG_VERBOSE, DBG_SCREEN, "rxvt_paste_file : unable to open file '%s'\n", filename));
+  }
+
+  wordfree(&p);
+  return;
+}
+
+
+
+/* ------------------------------------------------------------------------- */
+/*
  * Clear all selected text
  * EXT: SelectionClear
  */
Index: src/macros.c
===================================================================
--- src/macros.c	(revision 265)
+++ src/macros.c	(working copy)
@@ -41,6 +41,7 @@
     "Scroll",		    /* Scroll up/down */
     "Copy",		    /* Copy selection */
     "Paste",		    /* Paste selection */
+    "PasteFile",		    /* Paste the content of a file */
     "ToggleSubwin",	    /* Toggle subwindows (scroll / menu / tabbar) */
     "ResizeFont",	    /* Resize terminal font */
     "ToggleVeryBold",	    /* Toggle use of bold font for colored text */
@@ -1055,6 +1056,22 @@
 	    break;
   }
 
+	case MacroFnPasteFile:
+  {
+     if (NOT_NULL(ev)){
+        if( NOT_NULL(astr) && *astr ){
+         rxvt_paste_file (r, ATAB(r), ev->xkey.time, 0, 0, astr);
+        }else{
+         break;
+        }
+      }
+     else{
+       retval = -1;
+      }
+     break;
+  }
+
+
 	case MacroFnToggleSubwin:
 	    rxvt_toggle_subwin( r, (unsigned char*) astr);
 	    break;
Index: src/protos.h
===================================================================
--- src/protos.h	(revision 265)
+++ src/protos.h	(working copy)
@@ -280,6 +280,7 @@
 void             rxvt_selection_click             __PROTO((rxvt_t* r, int page, int clicks, int x, int y));
 void             rxvt_selection_extend            __PROTO((rxvt_t* r, int page, int x, int y, int flag));
 void             rxvt_selection_rotate            __PROTO((rxvt_t* r, int page, int x, int y));
+void             rxvt_paste_file                  __PROTO((rxvt_t* r, int page, Time tm, int x, int y, char* filename));
 void             rxvt_process_selectionrequest    __PROTO((rxvt_t* r, int page, const XSelectionRequestEvent *rq));
 void             rxvt_pixel_position              __PROTO((rxvt_t* r, int *x, int *y));
 /* End prototypes of screen.c */
Index: share/mrxvtrc
===================================================================
--- share/mrxvtrc	(revision 265)
+++ share/mrxvtrc	(working copy)
@@ -184,7 +184,12 @@
 
 # Pasting
 Mrxvt.macro.Ctrl+Shift+v:		Paste
-# A slection buffer can be added as an argument (PRIMARY,SECONDARY, CLIPBOARD)
+
+# Paste contents of a file to active tab 
+# (i.e. a collection of shell settings like aliases, environment variables, ...)
+Mrxvt.macro.Ctrl+Shift+w:   PasteFile ~/my-favourite-bash-settings
+
+# A selection buffer can be added as an argument (PRIMARY,SECONDARY, CLIPBOARD)
 Mrxvt.macro.Ctrl+Shift+c:		Paste CLIPBOARD
 
 Mrxvt.macro.Shift+Delete:		SetTitle
Index: share/default.menu
===================================================================
--- share/default.menu	(revision 265)
+++ share/default.menu	(working copy)
@@ -39,9 +39,13 @@
 {Toggle Fullscreen}			ToggleFullscreen
 {Toggle Macros}				ToggleMacros
 {-}
-{Paste}					Paste
-{Paste secondary buffer}					Paste SECONDRAY
-{Paste clipboard buffer}					Paste CLIPBOARD
+{Paste}                           Paste
+{Paste secondary buffer}          Paste SECONDRAY
+{Paste clipboard buffer}          Paste CLIPBOARD
+{Paste Solaris Profile}           PasteFile ~/.solaris-profile
+{Paste AIX Profile}               PasteFile $HOME/.aix-profile
+{Paste Linux Profile}             PasteFile $HOME/.linux-profile
+
 [read:submenus;selection]
 {-}
 [read:submenus;tabsmenu]
Index: doc/mrxvt.1
===================================================================
--- doc/mrxvt.1	(revision 265)
+++ doc/mrxvt.1	(working copy)
@@ -1696,6 +1696,14 @@
 Paste selection into active tab. The value
 .Ar selection-buffer 
 specifies the name of the buffer to be pasted. If not specified the first used buffer in the order PRIMARY, SECONDARY and CLIPBOARD  will be used.
+.\" ------------------------------------------------------------
+.It Ic PasteFile Ar filename
+Paste the content of the file specified by 
+.Ar filename
+to the currently active tab. This can be used to input text-snippets to a shell
+or any other terminal based program (i.e. somthing like a bash-profile
+or sequence of administration commands).
+.\" ------------------------------------------------------------
 .It Ic ToggleSubwin Op Oo Ar + Ns | Ns Ar - Oc Ns Op Ar b Ns | Ns Ar m Ns | Ns Ar s Ns | Ns Ar t
 Toggle visibility of sub-windows. If the argument begins with a
 .Sq +
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Materm-devel mailing list
Materm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/materm-devel
mrxvt home page: http://materm.sourceforge.net

Reply via email to