Skip to content

Commit

Permalink
Refactor config and install-process
Browse files Browse the repository at this point in the history
Now a Makefile is provided for simply building and installation of
shellex. A hopefully flexible enough config-scheme is implemented at the
same time.
  • Loading branch information
Merovius committed Aug 30, 2013
1 parent 2c84320 commit f5f8743
Show file tree
Hide file tree
Showing 18 changed files with 183 additions and 48 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
preload/shellex_preload.so
shellex
urxvt/shellex
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
TOPDIR=$(shell pwd)

include $(TOPDIR)/common.mk

ALL_TARGETS =
INSTALL_TARGETS =
CLEAN_TARGETS =
DISTCLEAN_TARGETS =

all: real-all

include preload/preload.mk
include shellex.mk
include urxvt/urxvt_shellex.mk
include conf.mk

real-all: $(ALL_TARGETS)

install: $(INSTALL_TARGETS)

clean: $(CLEAN_TARGETS)

distclean: clean $(DISTCLEAN_TARGETS)
45 changes: 19 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ Architecture
parameters
* [An urxvt-extension](urxvt_shellex.pl) that manages the terminal/displaying
part.
* [A zsh-config](zshrc) that does all stuff relating to the functional
behaviour.

* [configfile](conf) that do all stuff relating to the functional behaviour

(Planned) Features
==================
Expand All @@ -60,37 +58,32 @@ Planned, but not Implemented yet:
Installation
============

If you want to try it, you should do the following:
* Change the path in [the shell-script](shellex)
* `cd /path/to/shellex/preload; make`
* `mkdir ~/.urxvt; ln /path/to/shellex/urxvt_shellex.pl ~/.urxvt/shellex`
* `echo "URxvt.perl-lib: $HOME/.urxvt" >> ~/.Xresources`
* `xrdb -merge ~/.Xresources`
* `cp -r /path/to/shellex/etc /etc/shellex`

or something equivalent.
Just do

$ make
$ make install

Configuration
=============

There are two locations for `shellex` configuration: The first one is the
shell-script (following the tradition of window managers like awesome or dwm of
calling the sourcecode "configfile") for the functional part, the other one are
X-resources (the latter we will try to eliminate in the future).
Configuration of `shellex` has two parts: The first one are X-resources (which we will try to eliminate in the future):

Resource | Values | Default | Description
----------------- | -------------- | ------- | ---
URxvt.shellex.pos | pointer|focus | focus | If pointer, shellex shows the window on the window, the mousepointer is on, else it uses the output, where most of the currently focused window is.
URxvt.shellex.edge | bottom|top | top | On what screenedge to show shellex

For shell-config there are two locations:
* `/etc/shellex/global.d` for systemwide configuration-snippets
* `~/.shellex` for user-specific configuration-snippets (copied from
`/etc/shellex/userdef.d` on first start)

You should copy (or link, for development purposes) the etc-directory of the
source to /etc/shellex. This will give you some reasonable defaults for all
global users (such as the typical launching-behaviour) and powerfull
user-defaults on your system (which the user can then opt-out by deleting them
from her created config).
The other are small shell-script-snippets. When starting, `shellex` will look
into `$HOME/.shellex` and into `/etc/shellex`. It will then source all the
snippets in either location. If there is an identically named file in both
directories, the one in your home will be preferred.

This makes for a pretty flexible configuration process: Usually there will be a
lot of snippets in `/usr/lib/shellex/conf`, which should be self-contained and
without a lot of side-effects. In `/etc/shellex` there then are some symlinks
to those snippets, making up the default-configuration on this system, together
with administrator-provided additional defaults. Whenever you don't want a
snippet form `/etc/shellex` to be used, just create a symlink of the same name
to `/dev/null` in `$HOME/.shellex`. If you want to create your own snippets,
just put them in `$HOME/.shellex` under a name not used yet and it will be
automatically sourced.
32 changes: 32 additions & 0 deletions common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
INSTALL=install
SED=sed
ifndef PREFIX
PREFIX=/usr
endif
ifndef SYSCONFDIR
ifeq ($(PREFIX),/usr)
SYSCONFDIR=/etc
else
SYSCONFDIR=$(PREFIX)/etc
endif
endif
LIBDIR ?= /lib

SHELLEX_CFLAGS = -std=c99
SHELLEX_CFLAGS += -Wall
SHELLEX_CFLAGS += -Wunused-value

sed_replace_vars := -e 's,@DESTDIR@,$(DESTDIR),g' \
-e 's,@PREFIX@,$(PREFIX),g' \
-e 's,@LIBDIR@,$(LIBDIR),g' \
-e 's,@SYSCONFDIR@,$(SYSCONFDIR),g'

V ?= 0
ifeq ($(V),0)
# Don't print command lines which are run
.SILENT:

endif

# always remake the following targets
.PHONY: install clean dist distclean
15 changes: 15 additions & 0 deletions conf.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
INSTALL_TARGETS += install-conf

default_confs := 10-autoexec 40-escape 40-setprompt 40-sigint 99-clear

install-conf:
$(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)$(LIBDIR)/shellex/conf
for file in $(wildcard conf/*); \
do \
$(INSTALL) -m 0644 $${file} $(DESTDIR)$(PREFIX)$(LIBDIR)/shellex/conf/; \
done
$(INSTALL) -d -m 0755 $(DESTDIR)$(SYSCONFDIR)/shellex
for link in $(default_confs); \
do \
ln -s $(DESTDIR)$(PREFIX)$(LIBDIR)/shellex/conf/$${link} $(DESTDIR)$(SYSCONFDIR)/shellex; \
done
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 0 additions & 9 deletions etc/global.d/90-include_user

This file was deleted.

7 changes: 0 additions & 7 deletions preload/Makefile

This file was deleted.

19 changes: 19 additions & 0 deletions preload/preload.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ALL_TARGETS += preload/shellex_preload.so
INSTALL_TARGETS += install-shellex_preload
CLEAN_TARGETS += clean-shellex_preload

SHELLEX_CFLAGS=-fPIC
SHELLEX_PRELOAD_LDFLAGS=-shared

preload/shellex_preload.so: preload/main.c
echo "[CC] $@"
$(CC) $(SHELLEX_CPPFLAGS) $(CPPFLAGS) $(SHELLEX_CFLAGS) $(CFLAGS) $(SHELLEX_PRELOAD_CFLAGS) $(LDFLAGS) $(SHELLEX_LDFLAGS) $(SHELLEX_PRELOAD_LDFLAGS) -o $@ $<

install-shellex_preload: preload/shellex_preload.so
echo "[INSTALL] $<"
$(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)$(LIBDIR)/shellex
$(INSTALL) -m 0755 $< $(DESTDIR)$(PREFIX)$(LIBDIR)/shellex/

clean-shellex_preload:
echo "[CLEAN] shellex_preload"
rm -f preload/shellex_preload.so
5 changes: 0 additions & 5 deletions shellex

This file was deleted.

4 changes: 4 additions & 0 deletions shellex.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

export LD_PRELOAD="@DESTDIR@@PREFIX@@LIBDIR@/shellex/shellex_preload.so"
exec urxvt -perl-lib @DESTDIR@@PREFIX@@LIBDIR@/shellex/urxvt -pe shellex -override-redirect -name shellex -e env -u LD_PRELOAD zsh -f
19 changes: 19 additions & 0 deletions shellex.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ALL_TARGETS += shellex
INSTALL_TARGETS += install-shellex
CLEAN_TARGETS += clean-shellex

SHELLEX_CFLAGS=-fPIC
SHELLEX_PRELOAD_LDFLAGS=-shared

shellex: shellex.in
echo "[SED] $@"
$(SED) $(sed_replace_vars) $< > $@

install-shellex: shellex
echo "[INSTALL] $<"
$(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)/bin
$(INSTALL) -m 0755 shellex $(DESTDIR)$(PREFIX)/bin/

clean-shellex:
echo "[CLEAN] shellex"
rm -f shellex
35 changes: 34 additions & 1 deletion urxvt_shellex.pl → urxvt/shellex.in
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#line 3
use X11::Protocol;
use File::Temp qw|tempfile|;
use File::Basename qw|basename|;

# The existing Randr-modules on CPAN seem to work only barely, so instead we
# just parse the output of xrandr -q. This is an uglyness, that should go away
Expand Down Expand Up @@ -88,6 +90,35 @@ sub geometry_from_focus {
}
}

sub slurp {
open my $fh, '<', shift;
local $/;
<$fh>;
}

sub gen_conf {
my ($cfg, $cfgname) = tempfile("/tmp/shellex-XXXXXXXX", UNLINK => 0);

print $cfg "rm $cfgname\n";

my %fileset = ();
map { $fileset{basename($_)} = 1 } <@DESTDIR@@SYSCONFDIR@/shellex/*>;
map { $fileset{basename($_)} = 1 } <$ENV{HOME}/.shellex/*>;

my @files = keys %fileset;

for my $f (@files) {
if (-e "$ENV->{HOME}/.shellex/$f") {
print $cfg slurp("$ENV{HOME}/.shellex/$f");
} else {
print $cfg slurp("@DESTDIR@@SYSCONFDIR@/shellex/$f");
}
}
close($cfg);

return $cfgname;
}

# This hook is run when the extension is first initialized, before any windows
# are created or mapped. There is not much work we can do here.
sub on_init {
Expand Down Expand Up @@ -137,7 +168,9 @@ sub on_start {
$self->XMoveResizeWindow($self->parent, $self->{x}, $self->{y}, $self->{w}, 2+$self->fheight);
}

$self->tt_write($self->locale_encode("foreach file (/etc/shellex/global.d/*) . \$file; end\n"));
my $cfg = gen_conf();

$self->tt_write($self->locale_encode(". $cfg\n"));
();
}

Expand Down
16 changes: 16 additions & 0 deletions urxvt/urxvt_shellex.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ALL_TARGETS += urxvt/shellex
INSTALL_TARGETS += install-urxvt_shellex
CLEAN_TARGETS += clean-urxvt_shellex

urxvt/shellex: urxvt/shellex.in
echo "[SED] $@"
$(SED) $(sed_replace_vars) $< > $@

install-urxvt_shellex: urxvt/shellex
echo "[INSTALL] $<"
$(INSTALL) -d -m 0755 $(DESTDIR)$(PREFIX)$(LIBDIR)/shellex/urxvt
$(INSTALL) -m 0644 urxvt/shellex $(DESTDIR)$(PREFIX)$(LIBDIR)/shellex/urxvt/

clean-urxvt_shellex:
echo "[CLEAN] urxvt/shellex"
rm -f urxvt/shellex

0 comments on commit f5f8743

Please sign in to comment.