bug-bash
[Top][All Lists]
Advanced

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

tcsh + postcmd; ReadLine with mouse editing


From: Ilya Zakharevich
Subject: tcsh + postcmd; ReadLine with mouse editing
Date: Thu, 12 Sep 2002 07:25:03 +0000 (UTC)

Is there a way to put the contents of the current command line of tcsh
into a variable?  I find !# useless (in postcmd), since for a most
command lines it would in errors, in globs expanded, etc.

The best I could manage was

  setenv MOUSE_READLINE_ON 
'[?2001;2002;2003;2004;2005;2006s^[[?2001;2002;2003h'
  setenv MOUSE_READLINE_OFF '[?2001;2002;2003;2004;2005;2006r'
  set prompt = "%{^[]0;$user_in_prompt%m:    
%~/^G%}%U%m%u%B:%b%U%~%u%B%{$MOUSE_READLINE_ON%}->%b"
  # unsuitable during non-interactive part (.tcshrc) as postcmd
  #alias post_cmd  'test $?0 = 0 && echo -n "]2;\!#"'
  # Better do chomp, but some HPUXes have perl4 only
  # Similarly, can't use s///s
  alias post_cmd 'history -h 1 | perl -we '"'"'$_ = <STDIN>; chop; 
s/[;\x07\n][^\n]*/.../; s~^~\e]0;$ARGV[1]:$ARGV[0]/> ~; s/$/\x07/; 
s/\Q$ENV{HOME}/~/g; print $ENV{MOUSE_READLINE_OFF} if exists 
$ENV{MOUSE_READLINE_OFF}; print'"'"' $cwd $LOGNAME$__hostname'
  sched +0:00 alias postcmd post_cmd
  set __hostname=`hostname`

But running history -h 1 and perl for each command looks like an
enormous waste - at least I need to put `unalias postcmd' in the
beginning of my .tcshrc.  Otherwise resourcing it takes an eternity...

So my question is: is there a better way to access the current command
line than `history -h 1`?  BTW, while I'm here: is $:-0 (used in the
command completion) documented anywhere?

Another BTW: if you use the latest xterm (pl167) (compiled with
-DOPT_READLINE), then the setup above gives you a mouse-editable
command line.  (Due to a mishap one #ifdef'ed chunk got inside #ifdef
for a different define; so you need also --with-dec-locator during
./configure - or manually fix the defines in mouse.c).

Since the new configuration variables did not get to the docs yet,
here is the relevant chunk of the header:

#define SET_BUTTON1_MOVE_POINT      2001 /* click1 emit Esc seq to move point*/
#define SET_BUTTON2_MOVE_POINT      2002 /* press2 emit Esc seq to move point*/
#define SET_DBUTTON3_DELETE         2003 /* Double click-3 deletes */
#define SET_PASTE_IN_BRACKET        2004 /* Surround paste by escapes */
#define SET_PASTE_QUOTE             2005 /* Quote each char during paste */
#define SET_PASTE_LITERAL_NL        2006 /* Paste "\n" as C-j */

2004 sends escapes for F201 and F202 IIRC (so that on F201 the
application may switch itself to "interpret each char except F202
literally" mode)...

Ilya

P.S.  The current implementation of mouse-for-READLINE works only for
      command lines without embedded newlines.  I have in mind an
      implementation which should work with embedded newlines too.
      However, to have the ass completely covered, READLINE
      application should somehow inform the terminal when it
      temporarily switches to modes where LEFT/RIGHT keys do not have
      their usual meanings.

      Hmm, I see that bash is smart enough to interpret LEFT and RIGHT
      even in the reverse-i-search mode.  Are there modes for GNU
      readline in which LEFT/RIGHT have non-usual meanings?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]