Skip to main content

Extending Bash Commandline with Bash Scripts

Bash logo

This blog post will show a very elegant way on how to easily extend the Bash command line with Bash scripts, or basically any command. The pivotal feature for all of this is the innocent looking function shell-expand-line accessible from GNU Readline used by Bash.

As we will see, this allows us to elegantly extend the Bash command line with our own hot keys. The screencast below shows a demo to archive a document just downloaded through Firefox tagged with a current date stamp. While entering the mv command, two hot keys are used:

  • Alt-l: Paste the least recently used file in GNOME

  • Alt-d: Insert a date-stamp at cursor position

Read more… (4 min remaining to read)

GSettings from GUI to Command Line


In GNOME, the user preferences are under the control of the GSettings subsystem. As GNOME is a graphical desktop, the usual form to interact with this is (doh) through a GUI. Recently I decided I want to mess with those settings also from the command line. Namely I wanted to quickly switch between disabling the screen blanking behaviour and its regular delay before activation. Changing this setting through the GNOME control center, requires me to grab the mouse, locate the control center, sift through all the menu options there trying to remember that it is below "Power" and finally changing it by using a drop-down menu. What I really want is a script called screenblank-toggle somewhere in my path. With such a script, I just type screenb <TAB> <Enter> without having to point the mouse or visually parse anything. The output tells me if the new situation is what I want and if not, <Arrow Up> <Enter> fixes it for good.

So to implement this, I need to find out what GSetting I am looking for.

dzu@krikkit:~$ gsettings list-recursively | wc -l

Hm, maybe I can limit the search somewhat:

dzu@krikkit:~$ gsettings list-recursively | grep screen | wc -l

As I am too lazy to go through this individually, this small blog post shows a shortcut from the GUI to the command line without guessing names or reading documentation (ha ha).

Read more… (2 min remaining to read)