Re: readline 'unix-filename-rubout' whitespace bug

2021-08-31 Thread Dabrien 'Dabe' Murphy

On 8/27/21, 5:22 PM, Dabrien 'Dabe' Murphy wrote:

On 8/27/21, 4:09 PM, Chet Ramey wrote:
That circumstance is a pathname consisting solely of  one or more 
slashes,

separated from the previous word by whitespace. I'll fix it.

The code has been like this since January, 2004. That's pretty dated.


I guess I was just hoping somebody smarter than me [that's not hard] would
bust out some super fu and say something like, "Have you tried adding
'set word-break-chars [blah]' to your .inputrc ?"  «grin»


[FWIW, I'm sure the "bug-bash" list isn't actually the right venue for 
this, and I
apologize, but I figured I'd send this along as a reply, just for 
posterity...]


Although the following doesn't — slash *CAN'T* ? — save to the kill ring 
(it doesn't

even attempt to keep track of $READLINE_MARK), I came up with the following
"clever workaround" [read: "gross hack"] to wrangle even bash 3.2 into 
submission:


prompt% less ~/.bash_readline
...
### Set up macro (shell function) to eval
unix_filename_rubout() {
local removed_space=0 removed_slash=0

while [[ ${READLINE_POINT:-0} -gt 0 ]] &&
  [[ ${READLINE_LINE: $((READLINE_POINT - 1)): 1} =~ ^\ ?$ ]]; do
READLINE_LINE="${READLINE_LINE: 0: $((READLINE_POINT - 
1))}${READLINE_LINE: $((READLINE_POINT--))}"

removed_space=1
done

while [[ ${READLINE_POINT:-0} -gt 0 ]] &&
  [[ ${READLINE_LINE: $((READLINE_POINT - 1)): 1} =~ ^/?$ ]]; do
READLINE_LINE="${READLINE_LINE: 0: $((READLINE_POINT - 
1))}${READLINE_LINE: $((READLINE_POINT--))}"

removed_slash=1
done

if ! { [[ ${removed_slash:-0} -ge 1 ]] && [[ ${removed_space:-0} 
-ge 1 ]]; }; then

removed_space=0
while [[ ${READLINE_POINT:-0} -gt 0 ]] &&
  [[ ${READLINE_LINE: $((READLINE_POINT - 1)): 1} =~ ^\ ?$ 
]]; do
READLINE_LINE="${READLINE_LINE: 0: $((READLINE_POINT - 
1))}${READLINE_LINE: $((READLINE_POINT--))}"

removed_space=1
done
else
removed_space=0
fi

if ! { [[ ${removed_slash:-0} -ge 1 ]] && [[ ${removed_space:-0} 
-ge 1 ]]; }; then

while [[ ${READLINE_POINT:-0} -gt 0 ]] &&
! [[ ${READLINE_LINE: $((READLINE_POINT - 1)): 1} =~ ^[\ 
/]?$ ]]; do
READLINE_LINE="${READLINE_LINE: 0: $((READLINE_POINT - 
1))}${READLINE_LINE: $((READLINE_POINT--))}"

done
fi
}

stty werase undef
bind -x '"\C-w": unix_filename_rubout'


You know what they say...  "If it's stupid but it works, it isn't 
stupid."  «grin»


Thanks!  :-D

--
:- Dabe


Re: readline 'unix-filename-rubout' whitespace bug

2021-08-27 Thread Dabrien 'Dabe' Murphy

On 8/27/21, 4:09 PM, Chet Ramey wrote:
Thanks for the report. That circumstance is a pathname consisting 
solely of

one or more slashes, separated from the previous word by whitespace. I'll
fix it.


Awesome!  :-D

PS — Another pathological test case is, e.g.:

ls / /  / //


The code has been like this since January, 2004. That's pretty dated.


For sure!  I guess I was just hoping somebody smarter than me [that's not
hard] would bust out some super fu and say something like, "Have you tried
adding 'set word-break-chars [blah]' to your .inputrc ?"  «grin»

Thanks for the quick reply,

--
:- Dabe


Re: readline 'unix-filename-rubout' whitespace bug

2021-08-27 Thread Chet Ramey

On 8/26/21 10:18 PM, d...@dabe.com wrote:


Bash Version: 5.1
Patch Level: 8
Release Status: release

Description:
The manpage for bash(1) says:

   unix-filename-rubout
   Kill the word behind point, ***USING WHITE SPACE AND THE SLASH
  CHARACTER AS THE WORD BOUNDARIES***.  The killed text is saved
   on the kill-ring.   [Emphasis mine]

In certain circumstances, however, it gobbles up too much.


Thanks for the report. That circumstance is a pathname consisting solely of
one or more slashes, separated from the previous word by whitespace. I'll
fix it.



PS: I'm hopeful there might be some kind of workaround that will work even
on those dated releases!  [crossing fingers]


The code has been like this since January, 2004. That's pretty dated.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/



readline 'unix-filename-rubout' whitespace bug

2021-08-26 Thread dabe
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: darwin18.7.0
Compiler: clang
Compilation CFLAGS: -DSSH_SOURCE_BASHRC 
uname output: Darwin triton.parabon.com 18.7.0 Darwin Kernel Version 18.7.0: 
Tue Jun 22 19:37:08 PDT 2021; root:xnu-4903.278.70~1/RELEASE_X86_64 x86_64
Machine Type: x86_64-apple-darwin18.7.0

Bash Version: 5.1
Patch Level: 8
Release Status: release

Description:
The manpage for bash(1) says:

   unix-filename-rubout
  Kill the word behind point, ***USING WHITE SPACE AND THE SLASH
  CHARACTER AS THE WORD BOUNDARIES***.  The killed text is saved
  on the kill-ring.   [Emphasis mine]

In certain circumstances, however, it gobbles up too much.
[See below...]


Repeat-By:
###  Since we're dealing with ^w...
###  'set bind-tty-special-chars off' has the same results
bash%  stty werase undef

###  Now set ^w to 'unix-filename-rubout'
bash%  bind '"\C-w": unix-filename-rubout'

###  Simplest Minimal Reproducible Example:

Type "echo /" and hit 'ctrl-w'.

You'd expect it to stop at the space, and just go back to "echo ",
but instead, it erases both words.  :-(

###  Here's a slightly longer example that shows more detail:
bash%  echo /path/one /path/two   # Now ^w a few times:
   echo /path/one /path/  # OK
   echo /path/one /   # OK
   echo /path/# FAIL!

PS: I'm hopeful there might be some kind of workaround that will work even
on those dated releases!  [crossing fingers]

Thanks!

-- 
:- Dabe



readline 'unix-filename-rubout' whitespace bug

2021-08-26 Thread dabe
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: darwin18.7.0
Compiler: clang
Compilation CFLAGS: -DSSH_SOURCE_BASHRC 
uname output: Darwin triton.parabon.com 18.7.0 Darwin Kernel Version 18.7.0: 
Tue Jun 22 19:37:08 PDT 2021; root:xnu-4903.278.70~1/RELEASE_X86_64 x86_64
Machine Type: x86_64-apple-darwin18.7.0

Bash Version: 5.1
Patch Level: 8
Release Status: release

Description:
The manpage for bash(1) says:

   unix-filename-rubout
  Kill the word behind point, ***USING WHITE SPACE AND THE SLASH
  CHARACTER AS THE WORD BOUNDARIES***.  The killed text is saved
  on the kill-ring.   [Emphasis mine]

In certain circumstances, however, it gobbles up too much.
[See below...]


Repeat-By:
###  Since we're dealing with ^w...
###  'set bind-tty-special-chars off' has the same results
bash%  stty werase undef

###  Now set ^w to 'unix-filename-rubout'
bash%  bind '"\C-w": unix-filename-rubout'

###  Simplest Minimal Reproducible Example:

Type "echo /" and hit 'ctrl-w'.

You'd expect it to stop at the space, and just go back to "echo ",
but instead, it erases both words.  :-(

###  Here's a slightly longer example that shows more detail:
bash%  echo /path/one /path/two   # Now ^w a few times:
   echo /path/one /path/  # OK
   echo /path/one /   # OK
   echo /path/# FAIL!

PS: I'm hopeful there might be some kind of workaround that will work even
on those dated releases!  [crossing fingers]

Thanks!

-- 
:- Dabe