How can I control word boundaries in bash without modifying readline?

0
7
Asked By SilkyCloud77 On

I'm looking to change the way word boundaries are recognized when using the `M-t` shortcut to swap two words in bash. Ideally, I'd want it to treat a word as being separated by spaces. Since bash relies on readline and readline doesn't allow for custom word boundaries, I'm curious if there's any kind of workaround or hack to make this happen.

4 Answers

Answered By HelpfulLink99 On

Check out this wiki page: https://mywiki.wooledge.org/IFS. It contains useful information about word boundaries, especially regarding how they are defined in readline.

Answered By TechSavvy123 On

You might try this syntax: `"${WORD#*-}-${WORD%-*}"`. It's a neat trick to manipulate word boundaries in bash, which might help with what you're trying to do.

Answered By DeepDiver97 On

Readline actually lets you define word boundaries through the `rl_basic_word_break_characters` variable. If you're feeling adventurous, you could use LD_PRELOAD to tweak libreadline settings when launching the shell.

Answered By QuickCoder42 On

Have you given `C-M-t` a shot? I just tried it, and it worked perfectly for swapping the words as you wanted!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.