Dash:
[t2.git] / misc / archive / bash-xterm.patch
blobf5c3106fdf6374dbdaa7a5d37772fc7698343f79
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
3 #
4 # T2 SDE: misc/archive/bash-xterm.patch
5 # Copyright (C) 2004 - 2005 The T2 SDE Project
6 # Copyright (C) 1998 - 2003 ROCK Linux Project
7 #
8 # More information can be found in the files COPYING and README.
9 #
10 # This patch file is dual-licensed. It is available under the license the
11 # patched project is licensed under, as long as it is an OpenSource license
12 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
13 # of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
15 # version.
16 # --- T2-COPYRIGHT-NOTE-END ---
19 Little hack for bash: Adding 'xterm' option which causes bash to print the
20 PS1 prompt and the command bash is executing now in the title bar.
22 I'm not sure if my changes in execute_cmd.c will cause any troubles when
23 used with redirects and complex command blocks.
25 Written by Clifford <clifford@clifford.at>, 2001-04-08
27 diff -ruN bash-2.04-orig/builtins/builtins.c bash-2.04/builtins/builtins.c
28 --- bash-2.04-orig/builtins/builtins.c Sun Apr 8 11:19:48 2001
29 +++ bash-2.04/builtins/builtins.c Sun Apr 8 11:29:59 2001
30 @@ -765,6 +765,7 @@
31 #if defined (READLINE)
32 " vi use a vi-style line editing interface",
33 #endif /* READLINE */
34 + " xterm create xterm title escape codes",
35 " xtrace same as -x",
36 " -p Turned on whenever the real and effective user ids do not match.",
37 " Disables processing of the $ENV file and importing of shell",
38 diff -ruN bash-2.04-orig/builtins/set.def bash-2.04/builtins/set.def
39 --- bash-2.04-orig/builtins/set.def Thu Aug 5 13:44:25 1999
40 +++ bash-2.04/builtins/set.def Sun Apr 8 11:36:59 2001
41 @@ -49,7 +49,7 @@
42 # include "../bashhist.h"
43 #endif
45 -extern int interactive;
46 +extern int interactive, xterm_mode;
47 extern int noclobber, posixly_correct, ignoreeof, eof_encountered_limit;
48 #if defined (READLINE)
49 extern int rl_editing_mode, no_line_editing;
50 @@ -104,6 +104,7 @@
51 #if defined (READLINE)
52 vi use a vi-style line editing interface
53 #endif /* READLINE */
54 + xterm create xterm title escape codes
55 xtrace same as -x
56 -p Turned on whenever the real and effective user ids do not match.
57 Disables processing of the $ENV file and importing of shell
58 @@ -195,6 +196,7 @@
59 { "emacs", (int *)NULL, set_edit_mode, get_edit_mode },
60 { "vi", (int *)NULL, set_edit_mode, get_edit_mode },
61 #endif
62 + { "xterm", &xterm_mode, (Function *)NULL, (Function *)NULL },
63 { (char *)NULL, (int *)NULL }
66 diff -ruN bash-2.04-orig/execute_cmd.c bash-2.04/execute_cmd.c
67 --- bash-2.04-orig/execute_cmd.c Tue Jan 25 17:29:11 2000
68 +++ bash-2.04/execute_cmd.c Sun Apr 8 12:49:23 2001
69 @@ -98,7 +98,7 @@
70 # include "bashhist.h"
71 #endif
73 -extern int posixly_correct;
74 +extern int posixly_correct, xterm_mode;
75 extern int executing, breaking, continuing, loop_level;
76 extern int interactive, interactive_shell, login_shell, expand_aliases;
77 extern int parse_and_execute_level, running_trap, trap_line_number;
78 @@ -2367,6 +2367,16 @@
79 /* Remember what this command line looks like at invocation. */
80 command_string_index = 0;
81 print_simple_command (simple_command);
83 + /* Create xterm title */
84 + if (xterm_mode)
85 + {
86 + char *txt = get_string_value ("PS1");
87 + txt = txt ? decode_prompt_string (txt) : NULL;
88 + fprintf(stderr, "\033]0;%s%s\007", txt ? txt : "bash: ",
89 + the_printed_command);
90 + FREE(txt); fflush(stderr);
91 + }
93 first_word_quoted =
94 simple_command->words ? (simple_command->words->word->flags & W_QUOTED): 0;
95 diff -ruN bash-2.04-orig/flags.c bash-2.04/flags.c
96 --- bash-2.04-orig/flags.c Thu Aug 5 13:20:28 1999
97 +++ bash-2.04/flags.c Sun Apr 8 11:35:24 2001
98 @@ -147,6 +147,11 @@
99 int brace_expansion = 1;
100 #endif
102 +/* Non-zero means that the shell prints xterm escape codes for creating
103 + a new title text before printing the promt and before exetucing a
104 + command. */
105 +int xterm_mode = 0;
107 /* **************************************************************** */
108 /* */
109 /* The Flags ALIST. */
110 diff -ruN bash-2.04-orig/parse.y bash-2.04/parse.y
111 --- bash-2.04-orig/parse.y Tue Feb 22 19:12:03 2000
112 +++ bash-2.04/parse.y Sun Apr 8 12:32:08 2001
113 @@ -99,6 +99,7 @@
114 #if defined (BUFFERED_INPUT)
115 extern int bash_input_fd_changed;
116 #endif
117 +extern int xterm_mode;
119 extern int errno;
120 /* **************************************************************** */
121 @@ -153,6 +154,7 @@
122 /* The decoded prompt string. Used if READLINE is not defined or if
123 editing is turned off. Analogous to current_readline_prompt. */
124 static char *current_decoded_prompt;
125 +static char *current_decoded_ps1_prompt;
127 /* The number of lines read from input while creating the current command. */
128 int current_command_line_count;
129 @@ -975,6 +977,10 @@
130 interrupt_immediately++;
133 + if (xterm_mode) fprintf(stderr, "\033]0;%s\007",
134 + current_decoded_ps1_prompt ?
135 + current_decoded_ps1_prompt : "bash");
137 current_readline_line = readline (current_readline_prompt ?
138 current_readline_prompt : "");
140 @@ -3421,6 +3427,10 @@
141 ps1_prompt = get_string_value ("PS1");
142 ps2_prompt = get_string_value ("PS2");
144 + FREE (current_decoded_ps1_prompt);
145 + current_decoded_ps1_prompt = ps1_prompt ?
146 + decode_prompt_string (ps1_prompt) : (char *)NULL;
148 if (!prompt_string_pointer)
149 prompt_string_pointer = &ps1_prompt;
151 @@ -3468,6 +3478,8 @@
152 static void
153 print_prompt ()
155 + if (xterm_mode) fprintf(stderr, "\033]0;%s\007",
156 + current_decoded_ps1_prompt ? current_decoded_ps1_prompt : "bash");
157 fprintf (stderr, "%s", current_decoded_prompt);
158 fflush (stderr);