Xutils
X utilities in POSIX shell scripts.
Install / Use
/learn @phillbush/XutilsREADME
XUtils
XUtils are a set of POSIX scripts that implement some handy X-related utilities. Each script has its respective manual page.
The scripts are the following. • drawterm: Draw a terminal on screen à la Plan9. • icon: Print paths to icons in icon theme. • iconcache: Cache png images from svg files. • mpdnotify: Pop up a notification for currently playing song. • run: Run a .desktop file • samedir: Open a terminal in the same directory of focused window. • xman: Open man pages with zatura. • xopen: Open file or URL with an application.
§ Installation
The following lists the dependencies each script has. • drawterm: slop(1) and xterm(1) (can be replaced with st(1) or urxvt(1)). • icon: awk(1) and test(1) • iconcache: inkscape(1) • mpdnotify: mpd(1), mpc(1), xnotify(1). • run: Variable. • samedir: xprop(1), xdotool(1), pstree(1), cwdof(1). • xman: man(1), zathura(1).
First, edit ./config.mk to match your local setup.
Since XUtils are just script, they do not need to be built.
By default, XUtils are installed into the /usr/local prefix. Enter the following command to install XUtils (if necessary as root). This command installs the scripts into the ${PREFIX}/bin/ directory, and the manual pages into the ${MANPREFIX}/man1/ directory.
make install
§ Usage
drawterm(1) is hardcoded to my terminal font size and border width. You
need to edit this script for it to fit your terminal size. The variables
wglyph, hglyph, border, and title refer to glyph width, glyph
height, border width and title bar height, respectively. Then, just run
drawterm, and it will run slop(1), an utility that draws a rectangle on
the screen with the mouse. After drawing the rectangle, a xterm window
will appear in the place of the drawn rectangle.
icon(1) searches in $ICONPATH (a colon-separated list of paths to icon theme directories) for the files of the icons specified in the stdin. For example, the following commands set $ICONPATH, export it, and get the paths to some icons. The files are preferably a 128-pixels width png file, or a 64-pixel width png file, or a scalable svg image.
$ ICONPATH=/usr/local/share/icons/faenza:/usr/local/share/icons/hicolor
$ export ICONPATH
$ cat <<EOF | icon 64 128 s
Applications/mpv
Applications/sxiv
MimeTypes/text-html
Places/user-trash
EOF
iconcache(1) uses inkscape(1) to convert a newline-separated list of
image files read from its stdin into png files, which are created in
$CACHEDIR/iconcache ($HOME/.cache/iconcache by default). It is
used to convert svg icon files into png. iconcache(1) receives as
sole argument the size of the resulting png files.
$ <iconnames icon s | iconcache 64 >iconpaths
mpdnotify(1) uses mpc(1) current --wait command to get the name of the
currently playing song each time it changes. You must call mpdnotify(1)
as background in your ~/.xinitrc, ~/.xsession or related file.
run(1) needs two environment variables: $APPPATH, a colon-separated list of paths to directories containing .desktop files (by default it is set to “/usr/local/share/applications:/usr/share/applications”); and $TERMCMD, which is the name of a terminal command (by default it is set to “xterm”). When run without arguments, run(1) lists all the .desktop files in $APPPATH without the .desktop extension, and also a description for each file separated by a tab character. When run with arguments, its first argument may be either a path to a .desktop file, or one of the names listed by running run(1) without argument; in either case, the corresponding .desktop file will be run with the remaining arguments. For example, to run firefox, type:
$ run firefox
samedir(1) is a tricky script. It works for me in my OpenBSD with the help of another program of mine, called cwdof1). If you use Linux (or other OS with /proc file system), the version of samedir(1) by Luke Smith2 may better fit you. This script spawns a $TERMCMD (by default “xterm”) in the same directory as the currently active window.
xman(1) can be run in two ways. Without arguments, it lists all the available man pages and their description (separated with a tab). With arguments, it calls man(1) with those arguments and redirect the output to zathura(1), effectively opening manpages with the PDF reader program.
xopen(1) opens a file with the default application specified, as specified in the file whose path is in the environment variable $MIMEFILE.
$ xopen file.jpg
§ License
This software is in public domain and is provided AS IS, with NO WARRANTY.
