Table of Contents

  1. Why this post
  2. Before we begin | BASIC GOOD TO KNOW
    1. Readline
    2. ZLE
  3. Making of our custom widget
  4. My words to you dear friend
  5. Refrences

Why this post

I was always wondering why many of emacs keybindings work in terminal. Being dependent on key combinations ctrl+e, ctrl+a, alt+t, ctrl+t (my favorite)… every time i am fooling around the terminal, it felt so bad๐Ÿ‘ฟ if someone is navigating around pressing arrow keys โฌ…๏ธโฌ…๏ธโฌ…๏ธโฌ…๏ธ…so maaaaanyyyy times, swagging them these nifty shortcuts is so fun. Until my friend/binaysakya ๐Ÿ‘จโ€๐Ÿ’ป told me you should write about these things. I realized I know nothing what those bindings really meant ๐Ÿค” That’s how this post happened.

I would sharing my learning below more aliened to ZLE. I have copied the lines from the reference links below ๐Ÿ™Š๐Ÿ™ˆ๐Ÿ™‰

Before we begin | BASIC GOOD TO KNOW

Here we would look good to know theory that this post revolves around, skip๐Ÿš€ these theory at your risk.

Readline

Its a library used by bash and many of CLI programs to edit/interact via command line. Readline uses Emacs style shortcuts as default, that’s why your Ctrl+a, Ctrl+e… shortcuts works almost same in most of terminals, even the editors derivations like sublime respects๐Ÿ™‡ the style. And yes, because of this it super easy to jump along the text interface with such a ease โ˜บ๏ธ

ZLE

I have shifted to zsh like few years back, no speical reason still playing back and forth between bash and zsh. Just love the random theme from robbyrussell/oh-my-zsh.๐Ÿ˜„ till yesterday(22 dec 2017) when I found this thing called zle(ZSH LINE EDITOR) then I was like oh my… its so ๐Ÿ˜๐Ÿ˜๐Ÿ˜

ZLE is a powerful line editor, what that means… ? Every shell provides some kind of editing capability although it could be basic stuffs provided by os like enter character, delete line, delete word. ZLE extends your capability to interact with your shell with custom functions and custom key strokes, with ease(will share it how in section below โฌ‡๏ธ).

Example you want to change some text you just typed in terminal to UPPER Case. What you can do with zle widget is just like in your editor:

ZLE in simple words:

Making of our custom widget

Lets write a widget to find the top 5 memory savages on my machine at this moment. you can simply copy paste the following on your running zsh or source it somewhere in your rc file.

My words to you dear friend

Please go via the reference url below and explore for your self what awesome things we can do with our shell. ZLE is kinda simple&nice, lets make use of it to do tiny stuffs we repeatedly do in our daily like maybe look after logs like tail -f log/*.log, start our docker containers, run our specs, yeah its could be anything, I have so many alias,functions I depend on everyday, now I would have fun binding them to keystores of my choice ๐Ÿ˜‰

Future Notes: maybe I would try write about readline in days to come, still lot to learn ๐Ÿ˜ƒ

Refrences