URxvt Config

aaah
Oyster-Slurper
Posts: 21
Joined: Wed Mar 09, 2016 12:38 pm

Re: URxvt Config

Unread post by aaah » Fri Jul 01, 2016 1:52 pm

How do you over-ride (only temporarily) the default colours you have set in .Xresources ?
If I try to open urxvt with a yellow background ie
urxvt -bg yellow
when it opens I see a quick flash of yellow but then it goes to black as set in .Xresources

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: URxvt Config

Unread post by dkeg » Fri Jul 01, 2016 11:49 pm

I'd say that is b/c when urxvt loads, it loads from .Xresources, thus undoing your -bg change. Potentially, and this is really just me thinking out loud, you could leave bg as a variable, then create a function in bashrc to take your bg parameter and insert into you .xresource file as a parameter. The -bg variable may need to be hex.
Or if you want to take the easy way out, comment out the bg value in xresources, and set the bg parameter each time you start urxvt. With no parameter set, by default it will be white bg
Have fun, get creative, and if figure out a cool solution, share it.

Work hard; Complain less

User avatar
stark
MILF
Posts: 521
Joined: Sat Sep 27, 2014 6:38 pm
Location: Arpanet
Contact:

Re: URxvt Config

Unread post by stark » Fri Jul 08, 2016 5:24 pm

aaah wrote:How do you over-ride (only temporarily) the default colours you have set in .Xresources ?
If I try to open urxvt with a yellow background ie
urxvt -bg yellow
when it opens I see a quick flash of yellow but then it goes to black as set in .Xresources
A quick a dirty solution, is to update the color by piping it to xrdb.

NOTE: The color you set will stay the same for all new instances of urxvt launched, unless you update it again ( via this script by providing 'reload' as an argument, which loads from the current Xresource file, modify XRES to mention the location and/ name of the your current Xresource/Xdefaults file where your usual colors for urxvt is mentioned ) or you can update it manually. Feel free to modify this dirty solution to your needs : )

Code: Select all

#!/bin/sh
# A quick and dirty solution for temporarily changing color for rxvt-unicode

# If no arguments provided then print usage and exit
[ $# -lt 1 ] && {
	printf '\033[31m%s\033[0m\n' 'No arguments provided'
	printf 'usage: %s\n' "$(basename $0) <color | reload>"
	printf 'examples:\n\nChange color:\n    %s\n' "$(basename $0) 013370"
	printf 'Reload color from Xresources. See $XRES in this script:\n    %s\n' "$(basename $0) reload"

	exit 1
}

# Location of the Xresource/Xdefault
XRES="$HOME/.Xresources"

# Terminal: if we are running urxvt in daemon mode then set the respective client as the TERM
test "$(pgrep urxvtd)" && TERM=urxvtc || TERM=urxvt

_reload()
{
	# Merge changes from exisiting Xresource/Xdefaults file
	xrdb -merge "$XRES"
}

case "$1" in
	*[0-9]* | *[a-f]* | *[A-F]*)
		printf 'URxvt*background: #%s\n' "$1" | xrdb -merge
		exec $TERM &
		;;
	reload)
		# Reload when 'reload' is provided as an argument 
		_reload
		;;
esac

exit 0
Last edited by stark on Tue Jul 12, 2016 6:28 am, edited 1 time in total.
If you can do it go ahead and do it, if you can't do it then don't even criticize it. - gingerdesu

User avatar
wuxmedia
Grasshopper
Posts: 6445
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: URxvt Config

Unread post by wuxmedia » Mon Jul 11, 2016 9:10 pm

nice scripting stark
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
daggoth
runs Stable
Posts: 36
Joined: Mon Mar 10, 2014 8:16 am

Re: URxvt Config

Unread post by daggoth » Sat Jul 16, 2016 10:58 am

aaah wrote:How do you over-ride (only temporarily) the default colours you have set in .Xresources ?
I use this script to help me change colors for the current terminal. First create addcolor, an empty script, and paste in the following...

Code: Select all

#!/usr/bin/perl -w

use Term::ExtendedColor::Xresources qw( set_xterm_color ) ;

while (<>) {
    if (/^\D*color(\d+):?\s+#?(\w+)/) {
        set_xterm_color({ $1 => $2}) ;
    }
}
But the script depends on a perl module which must be installed from CPAN. So enter the following commands as root...

Code: Select all

  apt-get install cpanminus
  cpanm Term::ExtendedColor::Xresources
Lastly, to change terminal colors, I do something like this. Doesn't work within tmux though.

Code: Select all

./addcolor <<EOF
    *color0: #181818
    *color1: #a67558
    *color2: #a67458
    *color3: #bfb273
EOF

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: URxvt Config

Unread post by dkeg » Sat Jul 16, 2016 11:33 am

Wow, check that out.

Work hard; Complain less

Post Reply