As of 2016-02-26, there will be no more posts for this blog. s/blog/pba/
Showing posts with label readline. Show all posts

I love timestamp. I have keys in Vim for that. So I added a new keybinding for Bash shell:

# Timestamping
"\C-xt": "\"$(date --utc +%Y-%m-%dT%H:%M:%SZ)\" "

I use readline to input the string, the same trick I use to input quotation marks. I found no ways to grab the output of an external command in readline. So, a string with Command Substitution is the only option I have.

When I press Ctrl+X then t, the string "$(date --utc +%Y-%m-%dT%H:%M:%SZ) " will be entered and it will be replaced with the timestamp by Bash.

If you have accidentally press Alt+Number, you will see your Bash prompt become like:

(arg: 2)

If you press one or more digits, it could be like:

(arg: 234)

Since I started using Tmux from version 1.0, I saw this kind of prompt for probably 2 years. For Alt+2, its the key to change layout to horizontal split. I didnt understand that prompt for such long time and I didnt try to learn about it until now.

But I did know it must be Bash, so I checked out the manpage and found:

digit-argument (M-0, M-1, ..., M--)
       Add  this  digit  to the argument already accumulating, or start a new argument.  M-- starts a negative
       argument.

To be honest, I didnt understand how I could utilize this, I didnt even know Readline accepts arguments. Well, actually I did when I search command history. Anyway, after few tests, I knew I could use it for repeating tasks.

One would be very helpful is deleting a word, which can be achieve by pressing Escape then Backspace. I have been using it a lot since I learned about it. (I think, I accidentally pressed at some time)

You can initialize digit-argument, then enter a keystroke, the keystroke will be repeated for N times. For example:

M-7, Backspace         -> 7 letter before cursor will be deleted
M-80,Space             -> 80 spaces will be inputed
M-3, Escape, Backspace -> 3 words before cursor will be deleted

I made a short video to demonstrate:

https://i.ytimg.com/vi/22W2nAIGNAo/sddefault.jpg

You can also use it for navigation, move forwards for a few words, or similar tasks.