[PATCH] Fix READLINE_ARGUMENT with "M-1 M-2" and with `vi-arg-digit'

2021-06-27 Thread Koichi Murase
Description:

  Now "bind -x" can be used with numeric arguments when the numeric
  arguments are specified by e.g. "M-1 2 3".  However, when the
  numeric arguments are specified by e.g. "M-1 M-2 M-3", it still fails
  with the error message `bash_execute_unix_command: cannot find
  keymap for command'.  It fails too when the arguments are specified
  through `vi-arg-digit' in the vi-command map.

Repeat-By:

  $ ./bash --norc
  $ f1() { echo "ARG=$READLINE_ARGUMENT"; }
  $ bind -x '"\C-t": f1'
  $   # <--- Press "M-1 2 C-t" (Note: M-1 is transmitted as "ESC 1")
  ARG=12  #  The expected result

  $   # <--- Press "M-1 M-2 C-t"
  bash: bash_execute_unix_command: cannot find keymap for command
  #  An unexpected error message. "ARG=12" is expected

  $ set -o vi
  $ bind -m vi-command -x '"\C-t": f1'
  $   # <--- Press "ESC 1 C-t"
  bash: bash_execute_unix_command: cannot find keymap for command
  #  An unexpected error message. "ARG=1" is expected.

Fix:

  I attach a patch for `rl_trim_arg_from_keyseq'
  (lib/readline/bind.c)..

--
Koichi


r0027-fix-READLINE_ARGUMENT.patch
Description: Binary data


[PATCH] quote command and function names in `complete -p'

2021-06-27 Thread Koichi Murase
Description:

  In order to make the output of `complete -p' reusable as shell
  commands, the function name after `-F' and the command names also
  needs to be properly quoted.

  I understand that both the function names and the command names
  don't usually need to be quoted, but in principle it is possible to
  create such completion settings.  This becomes a problem when the
  script needs to handle user-supplied arbitrary completion settings.

  The related issue is https://github.com/akinomyoga/ble.sh/issues/102
  I need to evaluate/parse the result of `complete -p' in my script,
  I'm currently using a complicated heuristic way to analyze `complete
  -p', but really want an efficient and reliable way. i.e. something
  like « eval "words=($(complete -p CMD))" ».

Repeat-By:

  For example, the output of `complete -p' in the following cases
  cannot be reliably evaluated.

$ complete -c 'test1; echo yes'
$ complete -F 'A{B,C}' test1
$ complete -p
complete -c test1; echo yes
complete -F A{B,C} test1

  If we perform « saved=$(complete -p); ...; eval "$saved" », the
  above types of completion settings will cause unexpected results.

Fix:

  I attach a patch (r0028-quote-complete-p-A.patch).  In this patch,
  the command names are quoted only when necessary.  the function
  names after `-F' are always quoted.  If we want to quote the
  function name only when necessary, please instead use the second
  patch `r0028-quote-complete-p-B.patch'.

--
Koichi


r0028-quote-complete-p-A.patch
Description: Binary data


r0028-quote-complete-p-B.patch
Description: Binary data


The cursor moves abnormally

2021-06-27 Thread cheng wensui
bash  5.1.4(1)-release (x86_64-pc-linux-gnu) 

when ps1 is too long  ,The cursor moves abnormally  ,Entering letters too many  
too long is also abnormal 

example :
PS1='\033[5;37m[\033[0m\u\033[1;35m@\033[0m\033[4m\H\033[0m\033[1;31m(\t)\033[0m\W
 \033[0;33m\#/\!\033[0m\033[5;37m]\033[0m\033[0;37m\$ '

This wrong command "dpkg -L - bb -cc genisoimage | grep boot.cat" , Try to 
modify it , Use these keys "backspace" "space" "←↑→↓"
You will findings the cursor moves is abnormal , the language description is a 
bit difficult ,
and It is not normal to input too many letters that are too long 

qterminal ,tilix ,xterm ,3 softwares are like this  .

but PS1='[\u@\H(\t)\W \#/\!]\$ '  is OK


Re: The cursor moves abnormally

2021-06-27 Thread Greg Wooledge
On Sun, Jun 27, 2021 at 12:19:00PM +, cheng wensui wrote:
> bash  5.1.4(1)-release (x86_64-pc-linux-gnu) 
> 
> when ps1 is too long  ,The cursor moves abnormally  ,Entering letters too 
> many  too long is also abnormal 
> 
> example :
> PS1='\033[5;37m[\033[0m\u\033[1;35m@\033[0m\033[4m\H\033[0m\033[1;31m(\t)\033[0m\W
>  \033[0;33m\#/\!\033[0m\033[5;37m]\033[0m\033[0;37m\$ '

You're missing the \[ \] around your escape sequences.

See  for more details.