A gnome shell extension that store your shell commands and lets you copy to your clipboard. We use various commands frequently and it is sometimes difficult to remember the exact syntax. You can easily store your commands, scripts, snippets etc on this extension and copy it whenever you like. 😃
There references to start with gnome extension development assuming zero previous knowledge. Also has an example extension to get some inspiration. ☺
Generate a skeleton gnome extension which adds an ‘Hello World’ item on your panel.
gnome-shell-extension-tool --create-extension
Follow screen instructions to provide details of extension such as name, description, uuid etc. UUID should be a unique name, convention is to follow an email address pattern e.g. command-keeper@Baymax
Below is the output of the above command, green underlines are the fields you have to enter yourself.
If you plan on to publish this extension to Gnome’s library you need to adhere to their UUID schema. To verify UUID is correct, open a Python shell:
$ python
>> import re
>> re.match(‘[-a-zA-Z0–9@._]+$’, ‘[email protected]’)
Gnome shell extensions are typically stored in following locations:
Local:
Systemwide:
When you open your hello-world extension folder you will find the following files:
extension.js
metadata.json
stylesheet.css
The extension.js file is simply a JavaScript file; it must however have a function called init, which will be invoked at most once directly after your source JS file is loaded. You should modify all user interfaces in a separate enable function, and remove all custom functionality in a disable function.
You may optionally include a stylesheet file, stylesheet.css.
To understand the code refer to this gist which consists of well written comments for each function.
To enable the generated extension run the following command inside your extension directory
Extensions may be configured in a consistent manner using the
gnome-shell-extension-prefs
tool. To hook into it, provide a simple javascript
file called prefs.js. It must contain a function labeled
buildPrefsWidget, which should return some sort of GTK+ widget. Whatever is
returned from there will be inserted into the Preferences widget screen. Beyond
that, a function named init may also be provided, and will be invoked after
the file is loaded but before buildPrefsWidget is invoked.
For more development setup and basics, see this.
Style Guide — https://wiki.gnome.org/Projects/GnomeShell/StyleGuide
For all the API references of various Gnome components see this.
If need some inspiration from Gnome Source JavaScript Files, see this.
To start development just familiarise with these components:
- The Clutter UI library
(
imports.gi.Clutter
) - The GLib(
imports.gi.GLib
) - The Shell Toolkit (
imports.gi.St
)
On systemd-based systems (like Debian), you can see error and log output of
extensions using journalctl /usr/bin/gnome-shell -f
. On other systems, logs
might be written to ~/.xsession-errors
.
You can log messages from an extension into this log for informational or
debugging purposes using log(msg)
.
Looking Glass is
GNOME Shell’s integrated inspector tool and JavaScript console useful for
debugging. It can be run by typing ‘lg’ in the Alt+F2
prompt.
I frequently used complex terminal commands and I can’t write a script for each one of them. So I need to keep them in a place where I can search, add, copy from my commands list.
This extension is a panel menu button with the following functionality:
- Add: Type your command on the text box and add it to the
commands
table - **Search: **Search for your command by typing it to the text box
- **Delete: **Delete a command from menu and also remove the row containing the
command from the
commands
table - **Copy: **Copy a command to your clipboard on selection
Initially, I planned on using a plain text file to store my commands but file
handling in this case got complicated once I started to do crazy things with the
items I was storing. Switching to a database helped me track the menuitems with
their ids with autoincrement
so that I could query them with their ids. There
are of course other advantages of a database over a file system.
You can start with looking at the codebase of this extension, it has well written comments. Find the code here. There are some UI issues that I see.
For example,
1) The panel menu is not aligned properly and floats around
could be aligned with the right edge of the screen.
2) On entering a long
text (long enough to exceed the size of the text box) then the text pierces
out.
3) Cannot added multiline commands in one menuitem since during parsing
it is done using the newline spliting
If you want to improve the extension, your PRs will be most welcomed. If you have any problems/confusion feel free to comment below.
This extension was heavily inspired from the clipboard-indicator-extension.
To be able to use SQLite in gnome extension you need to install the GDA library. You can find it here. On Ubuntu you can install using:
sudo apt-get install libgdal-dev
Checkout the APIs here: http://library.gnome.org/devel/libgda/stable/
Installing the library is a painstaking process in itself. Took me about half a day to figure out to get it working. There are multiple dependencies that you need to install. Listing below some possible errors and their workarounds.
Install this library:
And add the following to your .bashrc
export GI_TYPELIB_PATH=/usr/lib/x86_64-linux-gnu/girepository-1.0
Add the following contents in a file libpcre.pc
:
# Package Information for pkg-config
prefix=/usr
exec_prefix=${prefix}
libdir=${prefix}/lib/x86_64-linux-gnu
includedir=${prefix}/include
Name: libpcre
Description: PCRE - Perl compatible regular expressions C library
Version: 8.12
Libs: -L${libdir} -lpcre
Cflags: -I${includedir}
And save it in the following path:
/usr/lib/x86_64-linux-gnu/pkgconfig/
Add the path to your .bashrc
:
export PKG_CONFIG_PATH=/usr/lib/pkgconfig
Gnome Shell Extension Reference and
Tutorial
Example SQLite
Extension
Aloha.