Shell script that displays any image file centered over specified area, either active window or whole display.
The main reason to write this script was to let me me quickly display cheatsheet image of my choice (with
this shell shortcuts cheatsheet being the main reason). I wanted to be able to peek the
cheatsheet easily at any time, but I couldn't find any existing tool to show me that image in useful way - display it
centered over currently actvive (focused) window and be quickly dismissed. This script reads details of currently active
window and then steers existing image viewers to show the image centered over that window (or whole display area).
Once I had it working, I created global key shortcut in my desktop environment that once hit, started show-cheatsheet
and voila - I had my cheatsheet hovering over my currently used terminal window (see Integration for
how to do the same in KDE).
This script shall work with any modern window manager.
The following packages are required:
Optional but recommended:
- feh - image viewer (website)
All these should be installable by your package manager. For Debian/Ubuntu/Kubuntu do:
sudo apt install -y imagemagick xdotool feh
show-cheatsheet [-h] [-c MODE] [-v VIEWER] FILE
Supported arguments are:
-h
displays help page-c MODE
sets centering mode of displayed image. Supported options are:window
orw
to open image centered over currently active window (default)display
ord
to open image centered over whole display (screen) area
-v VIEWER
sets viewer to be used. If not specified, tries to find one automatically. Supported viewers are:FILE
image file to be displayed
Support for any new image viewer can be easily added, however only apps that support --geometry
type of argument
or are offering any other way control placement of their opened window are of any use. It'd be also handy if viewer
could be dismissed with just ECS
key but that's optional.
To display bash-cheatsheet.png
over currently active terminal window:
show-cheatsheet bash-cheatsheet.png
This assumes cheatsheet image is in your current working directory and show-cheatsheet
is in your $PATH
.
If neither is the case, use full paths.
To make image display centered:
show-cheatsheet -c window bash-cheatsheet.png
To use display
utility instead of feh
in case both are installed
show-cheatsheet -v display bash-cheatsheet.png
Using script with global shortcut in KDE:
- Run
kmenuedit
- Create
New item...
and name it as you like (i.e. "Shell cheatsheet") - Set
<PATH-TO>/show-cheatsheet <PATH-TO>/bash-cheatsheet.png
asCommand
- Set
Current shortcut key
onAdvanced
tab to whatever you like - Save.
You can now i.e. open new Konsole window and try your shortcut to see if it makes cheatsheet image pop up.
- Written and copyrighted ©2019-2021 by Marcin Orlowski <mail (#) marcinorlowski (.) com>
- This is open-sourced software licensed under the MIT license