[PATCH] paste external command output



I crafted a little patch for mc-4.5.55
The only thing it does is let you paste output
of a command (basically anything that produces 
output when run from shell) to the internal 
editor. Merge it or burn it ;-) or criticize
if you find it lousy. 

please cc me, I am not on the list.

Regards
-- 
Michał 'Mikey' Szwaczko
Developer/Troubleshooter

Never trust an operating system.
diff -Nur mc-4.5.55-orig/edit/edit_key_translator.c mc-4.5.55/edit/edit_key_translator.c
--- mc-4.5.55-orig/edit/edit_key_translator.c	Sun Aug 12 20:04:17 2001
+++ mc-4.5.55/edit/edit_key_translator.c	Sun Apr 27 22:57:36 2003
@@ -57,6 +57,7 @@
      KEY_F (15), CK_Insert_File,
      XCTRL ('f'), CK_Save_Block, KEY_F (1), CK_Help,
      ALT ('t'), CK_Sort, ALT ('m'), CK_Mail,
+     ALT ('u'), CK_ExtCmd,
      XCTRL ('z'), CK_Word_Left, XCTRL ('x'), CK_Word_Right,
      KEY_F (4), CK_Replace, KEY_F (7), CK_Find, KEY_F (14), CK_Replace_Again,
      XCTRL ('h'), CK_BackSpace, ALT ('l'), CK_Goto, ALT ('L'), CK_Goto, XCTRL ('y'), CK_Delete_Line,
@@ -75,6 +76,7 @@
      KEY_F (2), CK_Save, ALT ('p'), CK_Paragraph_Format,
 
      ALT ('t'), CK_Sort,
+     ALT ('u'), CK_ExtCmd,
 
      XCTRL ('a'), CK_Home, XCTRL ('e'), CK_End,
      XCTRL ('b'), CK_Left, XCTRL ('f'), CK_Right,
diff -Nur mc-4.5.55-orig/gtkedit/edit.c mc-4.5.55/gtkedit/edit.c
--- mc-4.5.55-orig/gtkedit/edit.c	Sun Aug 12 20:02:56 2001
+++ mc-4.5.55/gtkedit/edit.c	Sun Apr 27 22:56:23 2003
@@ -2609,6 +2609,9 @@
     case CK_Sort:
 	edit_sort_cmd (edit);
 	break;
+    case CK_ExtCmd:
+	edit_ext_cmd (edit);
+	break;
     case CK_Mail:
 	edit_mail_dialog (edit);
 	break;
@@ -2620,6 +2623,7 @@
 /* These commands are not handled and must be handled by the user application */
 #ifndef MIDNIGHT
     case CK_Sort:
+    case CK_ExtCmd:
     case CK_Mail:
     case CK_Find_File:
     case CK_Ctags:
diff -Nur mc-4.5.55-orig/gtkedit/edit.h mc-4.5.55/gtkedit/edit.h
--- mc-4.5.55-orig/gtkedit/edit.h	Sun Aug 19 19:01:01 2001
+++ mc-4.5.55/gtkedit/edit.h	Sun Apr 27 23:00:32 2003
@@ -426,6 +426,7 @@
 void edit_word_wrap (WEdit * edit);
 unsigned char *edit_get_block (WEdit * edit, long start, long finish, int *l);
 int edit_sort_cmd (WEdit * edit);
+int edit_ext_cmd (WEdit * edit);
 void edit_help_cmd (WEdit * edit);
 void edit_left_word_move (WEdit * edit, int s);
 void edit_right_word_move (WEdit * edit, int s);
diff -Nur mc-4.5.55-orig/gtkedit/editcmd.c mc-4.5.55/gtkedit/editcmd.c
--- mc-4.5.55-orig/gtkedit/editcmd.c	Thu Aug 23 19:21:13 2001
+++ mc-4.5.55/gtkedit/editcmd.c	Sun Apr 27 23:01:17 2003
@@ -2944,6 +2944,31 @@
     return 0;
 }
 
+int edit_ext_cmd (WEdit * edit) 
+{
+     char *exp;
+     int e;
+ 
+     exp = ""; 
+     exp = input_dialog(_(" Paste output of external command "),
+     _(" Enter shell command(s): "),exp);
+
+     if (!exp) return 1;
+	
+	e = system (catstrs (exp, " "," > ", home_dir, TEMP_FILE, 0));
+	
+     if (e) {
+	    edit_error_dialog (_(" External "), 
+	    get_sys_error (_(" Error trying to execute command ")));
+	    return -1;
+     }
+
+     edit->force |= REDRAW_COMPLETELY;
+
+     edit_printf(edit,catstrs("sh> ",exp,"\n",0));
+     edit_insert_file (edit, catstrs (home_dir, TEMP_FILE, 0));
+     return 0;
+}
 /* if block is 1, a block must be highlighted and the shell command
    processes it. If block is 0 the shell command is a straight system
    command, that just produces some output which is to be inserted */
diff -Nur mc-4.5.55-orig/gtkedit/editcmddef.h mc-4.5.55/gtkedit/editcmddef.h
--- mc-4.5.55-orig/gtkedit/editcmddef.h	Sun Aug 12 20:02:56 2001
+++ mc-4.5.55/gtkedit/editcmddef.h	Sun Apr 27 22:55:38 2003
@@ -91,6 +91,7 @@
 #define CK_Match_Bracket	421
 #define CK_Terminal		422
 #define CK_Terminal_App		423
+#define CK_ExtCmd		424
 
 #define CK_User_Menu		425
 /* application control */
diff -Nur mc-4.5.55-orig/gtkedit/editmenu.c mc-4.5.55/gtkedit/editmenu.c
--- mc-4.5.55-orig/gtkedit/editmenu.c	Sun Aug 12 20:02:56 2001
+++ mc-4.5.55/gtkedit/editmenu.c	Sun Apr 27 22:59:21 2003
@@ -108,6 +108,7 @@
 void menu_c_form_cmd (void)		{ menu_key (KEY_F (19)); }
 void menu_ispell_cmd (void)		{ menu_cmd (CK_Pipe_Block (1)); }
 void menu_sort_cmd (void)		{ menu_cmd (CK_Sort); }
+void menu_ext_cmd (void)		{ menu_cmd (CK_ExtCmd); }
 void menu_date_cmd (void)		{ menu_cmd (CK_Date); }
 void menu_undo_cmd (void)		{ menu_cmd (CK_Undo); }
 void menu_beginning_cmd (void)		{ menu_cmd (CK_Beginning_Of_Text); }
@@ -228,6 +229,7 @@
     {' ', N_("format p&Aragraph        M-p"), 'A', menu_format_paragraph},
     {' ', N_("'ispell' s&Pell check    C-p"), 'P', menu_ispell_cmd},
     {' ', N_("sor&T...                 M-t"), 'T', menu_sort_cmd},
+    {' ', N_("Paste o&utput of ...     M-u"), 'U', menu_ext_cmd},
     {' ', N_("E&xternal Formatter      F19"), 'C', menu_c_form_cmd},
     {' ', N_("&Mail...                    "), 'M', menu_mail_cmd}
 };
@@ -251,6 +253,7 @@
     {' ', N_("format p&Aragraph        M-p"), 'a', menu_format_paragraph},
     {' ', N_("'ispell' s&Pell check    M-$"), 'P', menu_ispell_cmd},
     {' ', N_("sor&T...                 M-t"), 'T', menu_sort_cmd},
+    {' ', N_("Paste o&utput of ...     M-u"), 'U', menu_ext_cmd},
     {' ', N_("E&xternal Formatter      F19"), 'C', menu_c_form_cmd}
 };
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]