OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

160 lines
5.9 KiB

# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: lib/misc/bash-xterm.patch
# Copyright (C) 2008 The OpenSDE Project
# Copyright (C) 2004 - 2006 The T2 SDE Project
# Copyright (C) 1998 - 2003 Clifford Wolf
#
# More information can be found in the files COPYING and README.
#
# This patch file is dual-licensed. It is available under the license the
# patched project is licensed under, as long as it is an OpenSource license
# as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
# of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
# --- SDE-COPYRIGHT-NOTE-END ---
Little hack for bash: Adding 'xterm' option which causes bash to print the
PS1 prompt and the command bash is executing now in the title bar.
I'm not sure if my changes in execute_cmd.c will cause any troubles when
used with redirects and complex command blocks.
Written by Clifford <clifford@clifford.at>, 2001-04-08
diff -ruN bash-2.04-orig/builtins/builtins.c bash-2.04/builtins/builtins.c
--- bash-2.04-orig/builtins/builtins.c Sun Apr 8 11:19:48 2001
+++ bash-2.04/builtins/builtins.c Sun Apr 8 11:29:59 2001
@@ -765,6 +765,7 @@
#if defined (READLINE)
" vi use a vi-style line editing interface",
#endif /* READLINE */
+ " xterm create xterm title escape codes",
" xtrace same as -x",
" -p Turned on whenever the real and effective user ids do not match.",
" Disables processing of the $ENV file and importing of shell",
diff -ruN bash-2.04-orig/builtins/set.def bash-2.04/builtins/set.def
--- bash-2.04-orig/builtins/set.def Thu Aug 5 13:44:25 1999
+++ bash-2.04/builtins/set.def Sun Apr 8 11:36:59 2001
@@ -49,7 +49,7 @@
# include "../bashhist.h"
#endif
-extern int interactive;
+extern int interactive, xterm_mode;
extern int noclobber, posixly_correct, ignoreeof, eof_encountered_limit;
#if defined (READLINE)
extern int rl_editing_mode, no_line_editing;
@@ -104,6 +104,7 @@
#if defined (READLINE)
vi use a vi-style line editing interface
#endif /* READLINE */
+ xterm create xterm title escape codes
xtrace same as -x
-p Turned on whenever the real and effective user ids do not match.
Disables processing of the $ENV file and importing of shell
@@ -195,6 +196,7 @@
{ "emacs", (int *)NULL, set_edit_mode, get_edit_mode },
{ "vi", (int *)NULL, set_edit_mode, get_edit_mode },
#endif
+ { "xterm", &xterm_mode, (Function *)NULL, (Function *)NULL },
{ (char *)NULL, (int *)NULL }
};
diff -ruN bash-2.04-orig/execute_cmd.c bash-2.04/execute_cmd.c
--- bash-2.04-orig/execute_cmd.c Tue Jan 25 17:29:11 2000
+++ bash-2.04/execute_cmd.c Sun Apr 8 12:49:23 2001
@@ -98,7 +98,7 @@
# include "bashhist.h"
#endif
-extern int posixly_correct;
+extern int posixly_correct, xterm_mode;
extern int executing, breaking, continuing, loop_level;
extern int interactive, interactive_shell, login_shell, expand_aliases;
extern int parse_and_execute_level, running_trap, trap_line_number;
@@ -2367,6 +2367,16 @@
/* Remember what this command line looks like at invocation. */
command_string_index = 0;
print_simple_command (simple_command);
+
+ /* Create xterm title */
+ if (xterm_mode)
+ {
+ char *txt = get_string_value ("PS1");
+ txt = txt ? decode_prompt_string (txt) : NULL;
+ fprintf(stderr, "\033]0;%s%s\007", txt ? txt : "bash: ",
+ the_printed_command);
+ FREE(txt); fflush(stderr);
+ }
first_word_quoted =
simple_command->words ? (simple_command->words->word->flags & W_QUOTED): 0;
diff -ruN bash-2.04-orig/flags.c bash-2.04/flags.c
--- bash-2.04-orig/flags.c Thu Aug 5 13:20:28 1999
+++ bash-2.04/flags.c Sun Apr 8 11:35:24 2001
@@ -147,6 +147,11 @@
int brace_expansion = 1;
#endif
+/* Non-zero means that the shell prints xterm escape codes for creating
+ a new title text before printing the promt and before exetucing a
+ command. */
+int xterm_mode = 0;
+
/* **************************************************************** */
/* */
/* The Flags ALIST. */
diff -ruN bash-2.04-orig/parse.y bash-2.04/parse.y
--- bash-2.04-orig/parse.y Tue Feb 22 19:12:03 2000
+++ bash-2.04/parse.y Sun Apr 8 12:32:08 2001
@@ -99,6 +99,7 @@
#if defined (BUFFERED_INPUT)
extern int bash_input_fd_changed;
#endif
+extern int xterm_mode;
extern int errno;
/* **************************************************************** */
@@ -153,6 +154,7 @@
/* The decoded prompt string. Used if READLINE is not defined or if
editing is turned off. Analogous to current_readline_prompt. */
static char *current_decoded_prompt;
+static char *current_decoded_ps1_prompt;
/* The number of lines read from input while creating the current command. */
int current_command_line_count;
@@ -975,6 +977,10 @@
interrupt_immediately++;
}
+ if (xterm_mode) fprintf(stderr, "\033]0;%s\007",
+ current_decoded_ps1_prompt ?
+ current_decoded_ps1_prompt : "bash");
+
current_readline_line = readline (current_readline_prompt ?
current_readline_prompt : "");
@@ -3421,6 +3427,10 @@
ps1_prompt = get_string_value ("PS1");
ps2_prompt = get_string_value ("PS2");
+ FREE (current_decoded_ps1_prompt);
+ current_decoded_ps1_prompt = ps1_prompt ?
+ decode_prompt_string (ps1_prompt) : (char *)NULL;
+
if (!prompt_string_pointer)
prompt_string_pointer = &ps1_prompt;
@@ -3468,6 +3478,8 @@
static void
print_prompt ()
{
+ if (xterm_mode) fprintf(stderr, "\033]0;%s\007",
+ current_decoded_ps1_prompt ? current_decoded_ps1_prompt : "bash");
fprintf (stderr, "%s", current_decoded_prompt);
fflush (stderr);
}