This page looks best with JavaScript enabled

Urxvt tips II

 ·  🎃 kr0m

Continuing with the series of configurations for our favorite terminal emulator urxvt, we will explain how to bind certain key combinations to certain actions, so that we can have our most used commands transparently available on all our servers.

This trick will allow us to have our commands available regardless of the machine we are logged into. We could choose to copy our aliases, but with this other “hack” we will arrive at a simpler and more elegant solution.

Depending on the operating system we use, the path of the urxvt extensions will be in one place or another:


vi /usr/local/lib/urxvt/perl/kr0m
#! perl
sub on_user_command {
        my ($self, $cmd) = @_;
	if ($cmd eq "kr0m:mysqlSlave" or $cmd eq "kr0m:mysqlRepUsers" or $cmd eq "kr0m:iptables" or $cmd eq "kr0m:ss" or $cmd eq "kr0m:psaux" or $cmd eq "kr0m:icanhazip" or $cmd eq "kr0m:pass" or $cmd eq "kr0m:clearcomments" or $cmd eq "kr0m:disableLsColors") {
                my @command = split /kr0m:/, $cmd;
                my $filename = "/tmp/perlOutput.txt";
                #open my $fh, ">", $filename or die("Could not open file. $!");
                #print $fh $command[1];
                #close $fh;
                if ($command[1] eq "mysqlSlave") {
                        $cmd = "mysql -sre 'show slave status\\G;'\n";
		} elsif ($command[1] eq "mysqlRepUsers") {
                        $cmd = "mysql mysql -sre 'SELECT user,host FROM user;'|grep rep\n";
                } elsif ($command[1] eq "iptables") {
                        $cmd = "iptables -L -n --line-numbers\n";
                } elsif ($command[1] eq "ss") {
                        $cmd = "sockstat -46 -l -s";
                } elsif ($command[1] eq "psaux") {
                        $cmd = "ps aux|grep";
                } elsif ($command[1] eq "icanhazip") {
                        $cmd = "curl -4\n";
                } elsif ($command[1] eq "pass") {
                        $cmd = "PASSWORD\n";
                } elsif ($command[1] eq "clearcomments") {
                        $cmd = "egrep -v '^(\$|[[:space:]]*#|\\;)' ";
                } elsif ($command[1] eq "disableLsColors") {
                        $cmd = "alias ls='ls --color=never'";
                } else {
                        $cmd = "unknown urxvtCommand";
                $self->tt_write ($cmd);

NOTA: If we are configuring it on FreeBSD, we will have to change the command "ss -lpunt|grep LISTEN|grep" to "sockstat -sv|grep LISTEN|grep".

Configure the keysyms:

vi .Xresources

URxvt.keysym.Control-m: perl:kr0m:mysqlSlave
URxvt.keysym.Control-h: perl:kr0m:iptables
URxvt.keysym.Control-j: perl:kr0m:ss
URxvt.keysym.Control-o: perl:kr0m:clearcomments
URxvt.keysym.Control-p: perl:kr0m:psaux
URxvt.keysym.Control-i: perl:kr0m:icanhazip
URxvt.keysym.Control-u: perl:kr0m:pass
URxvt.keysym.Control-k: perl:kr0m:disableLsColors
URxvt.iso14755: False
URxvt.perl-ext-common: default,kr0m

We reload the config:

xrdb -load .Xresources

With Ctrl+X we will execute the associated command.

This way, there will be no need to migrate aliases or any type of configuration.

If you liked the article, you can treat me to a RedBull here