Page 12 of 15

Re: Post your Command line tricks

Posted: Wed Apr 29, 2015 4:37 pm
by rhowaldt
not so much CLI as it is scripting, but can be useful for both.

was playing with Lemonbar and figured it would be nice of it were somehow possible to have it tie in, colourwise, with one's Xresources colourscheme. so I wanted a quick way to grab a colour from the Xresources to use it in my script. i figured i'd use grep, but some online searching led me to use sed instead, which can do the same basic thing as grep, namely find PATTERN in FILE.

Code: Select all

sed -n "/*color4:/s/*color4://p" ~/.Xresources | tr -d [:blank:]
since i make thankful use of Drew's colourswitching-thingy (Bork! included by default, but i assume all spins?), my .Xresources doesn't have the colours listed directly but instead works through an #include. to deal with that, i did the following.

Code: Select all

xcolors=$(sed -n "/#include/s/#include//p" ~/.Xresources | sed "s/<\(.*\)>/\1/")
mycolor=$(sed -n "/*color4:/s/*color4://p" $xcolors | tr -d [:blank:])
as you can see in both examples, this is crude in the sense that it will let you pick just one colour and you will have to hope and pray it is the right one for your notification (or whatever), and if not you have to trial-and-error and see which number does fit. when you decide to change colourschemes, another run of trial-and-error might be needed to get what you want.

so it's definitely not perfect, but it is an idea that might be expanded upon, and at least i learned something new about sed :)

Re: Post your Command line tricks

Posted: Wed Apr 29, 2015 5:52 pm
by z3bra
Hey, did you know? You can interact with the X resources database using its client: "xrdb".
And as every database client, it can both write and READ data to/from the database:

Code: Select all

xrdb | grep -E '\*color[0-9]*:'

Re: Post your Command line tricks

Posted: Wed Apr 29, 2015 6:08 pm
by machinebacon
^ that :D

Re: Post your Command line tricks

Posted: Wed Apr 29, 2015 7:43 pm
by rhowaldt
hahahahaha, fuck, nope, clearly didn't know. oh well, i learned some more sed at least :)
thanksss

edit: HOWEVER i would like to point out that the issue with which colour to grab still stands. if anybody has anything bright to say in that regard, that would be nice. if not i'll keep thinking :)

Re: Post your Command line tricks

Posted: Wed Apr 29, 2015 8:01 pm
by rhowaldt
in my case it doesn't help though, as xrdb seems to only be able to get this information from ~/.Xresources and not from a seperate file:

Code: Select all

[22:59:59]$ xrdb ~/.Xresources 
xrdb:  "*background" on line 43 overrides entry on line 3
xrdb:  "*foreground" on line 44 overrides entry on line 4

[23:00:08]$ cat /home/rhowaldt/xcolors/xcolor_code/blend 
! dkeg 2014
! blend

*background:   #121212
*foreground:   #abacae

*color0:       #2a2a2a
*color1:       #4c3333
*color2:       #959c4f
*color3:       #976c4e
*color4:       #3d5a72
*color5:       #978a9b
*color6:       #4a5e5b
*color7:       #a1a7ad
*color8:       #3a3a3a
*color9:       #8d4d4d
*color10:      #b6bd6e
*color11:      #bc9f67
*color12:      #7a9dbc
*color13:      #ae9eb3
*color14:      #80a09b
*color15:      #c7cbcf

[23:00:23]$ xrdb /home/rhowaldt/xcolors/xcolor_code/blend 

(the command in z3bra's example does nothing because xrdb requires a filename to work on)

Re: Post your Command line tricks

Posted: Wed Apr 29, 2015 8:12 pm
by z3bra
Oh, my bad, I forgot the most important bit!

Code: Select all

xrdb -query | grep -E '\*color[0-9]*:'
It will then output what's currently loaded in the database

Re: Post your Command line tricks

Posted: Wed Apr 29, 2015 8:41 pm
by rhowaldt
aaaah thanks! damn, and i looked through the manpage but missed that query bit.
then to get the actual colour so it can be used in a script, you can still use part of my suggestion:

Code: Select all

xrdb -query | sed -n "/*color4:/s/*color4://p" $xcolors | tr -d [:blank:]

Re: Post your Command line tricks

Posted: Thu Apr 30, 2015 6:32 am
by machinebacon
just a very little side note, rho, you can comment line 3 and 4 in .Xresources which usually sets the background and foreground for all X11 appllications (like xpdf or xcalc), using the almight *background and *foreground entries, but spits out the warning because of the override in the last row. Means, if you want the grey scheme in xpdf after commenting line 3 and 4, you need to set the resources of xpdf explicitly, for example like described here: https://wiki.archlinux.org/index.php/X_ ... _resources

Re: Post your Command line tricks

Posted: Thu Apr 30, 2015 6:51 am
by stark
^ Didn't knew that Thanks mb !

@rho *cough* colr *cough* :)

Re: Post your Command line tricks

Posted: Thu Apr 30, 2015 9:38 am
by rhowaldt
^^ thanks :)
^ thanks, now i see how that would be useful, notice you even provided a dmenu example with it :)

Re: Post your Command line tricks

Posted: Thu Apr 30, 2015 5:17 pm
by ivanovnegro
Clear old configuration files from your Debian system. Did that after the freeze, it removed a bunch of shit.

Code: Select all

apt-get purge $(dpkg -l | awk '/^rc/ { print $2 }')
You probably use that command already or in one of the BBQ cleaner scripts.

Re: Post your Command line tricks

Posted: Thu Apr 30, 2015 6:11 pm
by machinebacon
Ah, that's a nice one, removed the stuff that --purge didn't catch. Thanks!

Re: Post your Command line tricks

Posted: Thu Apr 30, 2015 6:26 pm
by pidsley
Thanks ivan -- I will add this to the sysup script.

Re: Post your Command line tricks

Posted: Fri May 01, 2015 4:41 pm
by rhowaldt
from here: http://stackoverflow.com/questions/3510 ... -and-regex
Explaining the grep '[p]ython csp_build.py' bit in a bit more detail:

When you do sleep 3600 & followed by ps -ef | grep sleep, you tend to get two processes with sleep in it, the sleep 3600 and the grep sleep (because they both have sleep in them, that's not rocket science).

However, ps -ef | grep 'leep' won't create a process with sleep in it, it instead creates grep 'leep' and here's the tricky bit: the grep doesn't find it because it's looking for the regular expression "any character from the character class (which is s) followed by leep.

In other words, it's looking for sleep but the grep process is grep 'leep' which doesn't have sleep in it.

When I was shown this (by someone here on SO), I immediately started using it because

it's one less process than adding | grep -v grep; and
it's elegant and sneaky, a rare combination :-)

Re: Post your Command line tricks

Posted: Fri May 01, 2015 7:09 pm
by stark
^ Woah, Thanks so much rho !

Not much of a trick, I use `most` as my main pager but sometimes for whatever reason I like to view some manpages with `less` so here's a little tweaked out shell function:

Code: Select all

h ()
{
man='/usr/bin/man'
export PAGER='less'

	env \
		LESS_TERMCAP_mb=$(printf "\e[1;31m") \
		LESS_TERMCAP_md=$(printf "\e[1;31m") \
		LESS_TERMCAP_me=$(printf "\e[0m") \
		LESS_TERMCAP_se=$(printf "\e[0m") \
		LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
		LESS_TERMCAP_ue=$(printf "\e[0m") \
		LESS_TERMCAP_us=$(printf "\e[1;32m") \
			man "$@"

export PAGER='most -dw'
}
So the usual `man info` command will open the manpage using most and `h info` will open the manpage using less with the colors and will restore back `most` as the main pager.

Another very stupid `cd` shell function:

Code: Select all

cd ()
{
  if [ -n "$1" ]; then
   clear && echo && builtin cd "$@" && ls --group-directories-first --color=no && echo
  else
   clear && echo && builtin cd ~ && ls --group-directories-first --color=no && echo
  fi
}

Re: Post your Command line tricks

Posted: Fri May 01, 2015 7:26 pm
by wuxmedia
^ challenge: How hard could it be to replace bash's default pager (when tabbing large dir listings) 'less', instead of 'more'?
I think I gave it a go and just typed a bit more... :)

Re: Post your Command line tricks

Posted: Fri May 01, 2015 8:29 pm
by stark
^ I don't think that's possible, that's an internal pager built into the readline and I haven't found any options to change it.

from bash's man page:

Code: Select all

page-completions (On)
       If set to On, readline uses an internal more-like pager to display a screenful of possible completions at a time.
Typing more is the only option I can think of ;) or maybe messing with this function http://git.savannah.gnu.org/cgit/readli ... ete.c#n545 ?

Re: Post your Command line tricks

Posted: Fri May 01, 2015 11:54 pm
by rhowaldt
this might be naive or something, but i thought you could just do

Code: Select all

PAGER="less -X"
(that was always my choice, so example here)
have that in your .bashrc and it's default, no?

Re: Post your Command line tricks

Posted: Sat May 02, 2015 3:25 am
by machinebacon
yup, IMO just / export PAGER="less -X" / before the man command and there you go.

Re: Post your Command line tricks

Posted: Sun May 03, 2015 8:17 pm
by wuxmedia
for 'man' sure and anything that calls it. As stark observed in the readline of bash one cannot change it..

Code: Select all

wux@numenor:~$ ls /etc/
Display all 198 possibilities? (y or n)
yeah looks like fiddling with the code. Not going to be doing that :)