A few days ago, I had a conversation with a viewer of my YouTube channel. In which, I mentioned about Ctrl+L after I watched the viewer using clear on her video.
After conversation ended, I realized that there could be many people ain’t aware of the usefulness of Ctrl+L. Actually, it is not just for Bash, but possibly for anything built with GNU Readline library. From bash(1) and readline(3):
- clear-screen (C-l)
- Clear the screen leaving the current line at the top of the screen. With an argument, refresh the current line without clearing the screen.
By default, the Readline command clear-screen is bound to C-l, you can rebind it with ~/.inputrc to any key you like, but I find the default Ctrl+L is a perfect key for me.
It is much better than using clear command because it keeps whatever you have already typed. You can watch this video to see how it working in Bash as well as in Python, SQLite 3, and bc consoles, which are some programs I know have interface that uses the library.
Imagine you are halfway typing a stinkingly long command or one-liner, what would you do if you want to clear screen first? Jump to the head of line and insert clear;? That certainly works, but Ctrl+L makes life easier.
Ever since I have learned this magic key, I couldn’t recall even once I have typed clear in shell to clear screen. I am not entirely sure how or when I learned about it, I will guess it’s when I was reading bash(1) to learn something interesting, and it could have been three or more years.
Nonetheless, we still needs clear command in scripting, no questions asked. By the way, the command is part of ncurses.
Simply two keystrokes instead of six.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.