0

I'm trying to improve my touch-typing which is very low both on accuracy and speed.

I've noticed that I have a great difficulty regarding upper case letters. I often have to leave the home row or I always mistype if I'm stretching my pinky to reach shift.

I had the same problems with backspace that I solved by starting using ^H instead, my control is in capslock so I can perform most readline shortcuts easily and I can easily correct mistakes without leaving the home row.

Maybe there is a way to escape an uppercase letter? Just like we can escape sequences with ^V, or like we can transpose the characters in cursor with ^T. There is a way to uppercase the character in cursor or something?

Edit: for clarification, as asked:

I'm currently in macOS, the default shell is zsh but I can easily switch for another one where I can achieve this. So I'm really accepting any possible solutions as I can try to test the same system-wide later.

On most apps on macOS I can use control sequences for line editing just like if I was in terminal, and I guess that macOS uses readline to achieve that, and for some applications I also use rlwrap which is a wrapper for readline, that's why I could probably benefit from a readline related solution as well.

If you know a solution for any shell, it'll be useful as I can start using this shell instead.

2
  • Do you want a system-wide solution? or in readline? (you used the tag). I think what you want is possible and relatively easy in the command line of Bash 5, not so easy (when multi-byte characters are involved) in Bash 4. What I have in mind is specific to Bash, so not even readline-wide. Please edit and state the desired scope and the minimal acceptable scope. Commented Jul 6, 2021 at 19:31
  • Thanks Kamil. I have a wide acceptable scope, I'm looking forward to hear about your Bash 5 solution. Commented Jul 6, 2021 at 19:48

1 Answer 1

0

This is what you can do in Bash 5:

_up() {
 [ "$READLINE_POINT" -lt 1 ] && return 0
 local char
 char="${READLINE_LINE:$((READLINE_POINT-1)):1}"
 READLINE_LINE="${READLINE_LINE:0:$((READLINE_POINT-1))}${char^}${READLINE_LINE:$READLINE_POINT}" 
}

bind -x '"\C-x\C-u":_up'

From now on Ctrl xu will convert the character before the text cursor to uppercase. The idea is you use the combination just after you type a lowercase character.

Bind the function to some less cumbersome combination.

READLINE_LINE is a variable that allows us to retrieve and/or modify the content of the command line. READLINE_POINT is a variable that allows us to know and/or set where in the line the text cursor is.

The method is quite limited, it works only in the command line of Bash. It should work well in Bash 5.

Bash 4 supports READLINE_LINE and READLINE_POINT but the latter variable uses bytes, while in Bash 5 it uses characters. This means you can use the function in Bash 4 and it will work in many cases, multi-byte characters will confuse it though. Patching the function so it works well with multi-byte characters in Bash 4 may not be trivial.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .