pasting from clipboard in bash
Chuck Bogorad
chuck@hysteria.spb.ru
Wed Mar 26 05:02:00 GMT 1997
i've always wanted to be able to press insert and get first line from the
clipboard into command line. so here it is. i diff'd (diff -crb) a 'clean'
b17.1-bash source (no patches applied).
what it does - you now have one more function available for bindng -
'paste-from-clipboard'. i mapped it to INSERT:
> bind '"\e[2~":paste-from-clipboard'
=== cut ===
diff -crb /usr/local/src/bash/cpp-Makefile bash-patched/cpp-Makefile
*** /usr/local/src/bash/cpp-Makefile Thu Jan 01 03:02:52 1970
--- bash-patched/cpp-Makefile Wed Mar 26 14:03:36 1997
***************
*** 685,691 ****
$(GLOB_LIBRARY) $(TILDE_LIBRARY) $(MALLOC_LIBRARY) $(LOCAL_LIBS)
#else /* !LD_HAS_NO_DASH_L */
LIBRARIES = $(READLINE_LIB) $(HISTORY_LIB) $(TERMCAP_LIB) $(GLOB_LIB) \
! $(TILDE_LIB) $(MALLOC_LIB) $(LOCAL_LIBS)
#endif /* !LD_HAS_NO_DASH_L */
#if defined (READLINE)
--- 685,691 ----
$(GLOB_LIBRARY) $(TILDE_LIBRARY) $(MALLOC_LIBRARY) $(LOCAL_LIBS)
#else /* !LD_HAS_NO_DASH_L */
LIBRARIES = $(READLINE_LIB) $(HISTORY_LIB) $(TERMCAP_LIB) $(GLOB_LIB) \
! $(TILDE_LIB) $(MALLOC_LIB) $(LOCAL_LIBS) -luser32
#endif /* !LD_HAS_NO_DASH_L */
#if defined (READLINE)
diff -crb /usr/local/src/bash/lib/readline/bind.c
bash-patched/lib/readline/bind.c
*** /usr/local/src/bash/lib/readline/bind.c Thu Jan 01 02:56:48 1970
--- bash-patched/lib/readline/bind.c Wed Mar 26 14:22:54 1997
***************
*** 1485,1487 ****
--- 1485,1515 ----
return (s1 + i);
return ((char *)NULL);
}
+
+ #ifdef __CYGWIN32__
+ #include <windows.h>
+
+ int rl_paste_from_clipboard()
+ {
+ char *data, *ptr;
+ int len;
+
+ if (!OpenClipboard(NULL)) return;
+ data = (char *)GetClipboardData(CF_TEXT);
+ if (data)
+ {
+ ptr = strchr(data, '\r');
+ if (ptr)
+ {
+ len = ptr - data;
+ ptr = malloc(len+1);
+ ptr[len] = 0;
+ strncpy(ptr, data, len);
+ }
+ else
+ ptr = data;
+ rl_insert_text(ptr);
+ };
+ CloseClipboard();
+ }
+ #endif
diff -crb /usr/local/src/bash/lib/readline/funmap.c
bash-patched/lib/readline/funmap.c
*** /usr/local/src/bash/lib/readline/funmap.c Thu Jan 01 02:56:49 1970
--- bash-patched/lib/readline/funmap.c Wed Mar 26 13:27:35 1997
***************
*** 90,95 ****
--- 90,96 ----
{ "non-incremental-reverse-search-history", rl_noninc_reverse_search },
{ "non-incremental-forward-search-history-again",
rl_noninc_forward_search_again },
{ "non-incremental-reverse-search-history-again",
rl_noninc_reverse_search_again },
+ { "paste-from-clipboard", rl_paste_from_clipboard },
{ "possible-completions", rl_possible_completions },
{ "previous-history", rl_get_previous_history },
{ "quoted-insert", rl_quoted_insert },
diff -crb /usr/local/src/bash/lib/readline/readline.h
bash-patched/lib/readline/readline.h
*** /usr/local/src/bash/lib/readline/readline.h Thu Jan 01 02:56:51 1970
--- bash-patched/lib/readline/readline.h Wed Mar 26 13:35:29 1997
***************
*** 51,57 ****
rl_upcase_word (), rl_downcase_word (), rl_capitalize_word (),
rl_restart_output (), rl_re_read_init_file (), rl_dump_functions (),
rl_delete_horizontal_space (), rl_history_search_forward (),
! rl_history_search_backward (), rl_tty_status (), rl_yank_last_arg ();
/* `Public' utility functions. */
extern int rl_insert_text (), rl_delete_text (), rl_kill_text ();
--- 51,61 ----
rl_upcase_word (), rl_downcase_word (), rl_capitalize_word (),
rl_restart_output (), rl_re_read_init_file (), rl_dump_functions (),
rl_delete_horizontal_space (), rl_history_search_forward (),
! rl_history_search_backward (), rl_tty_status (), rl_yank_last_arg ()
! #ifdef __CYGWIN32__
! , rl_paste_from_clipboard()
! #endif
! ;
/* `Public' utility functions. */
extern int rl_insert_text (), rl_delete_text (), rl_kill_text ();
=== cut ===
-
For help on using this list, send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".
More information about the Cygwin
mailing list