You are not logged in.

#1 2009-10-02 16:22:48

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

[Solved] A Challenge: Loop meld to update *.pacnew files

I got no secret, I love meld big_smile.  Does a great job of showing differences alot of times if even scattered all over the page, allows for copy and paste...  vimdiff is good but requires a much more keypresses, copy and paste isn't as elegant, and with my fixed drop-down terminal is just too narrow to be able to do it well.  So what I usually end up doing is:

find /etc -type f -name "*.pacnew"

and just go through them one at a time:

kdesu meld /etc/config /etc/config.pacnew

I haven't do much work with loops, so I was hoping that someone that knew a little about them that could create a script that would go through them one by one.  I suppose this is going to be a little tricker because (I imagine) it's going to have to detect when the windowed instance closes.

From the knowledge I know, I would do:

#!/bin/bash
# etc-update - merge *.pacnew files with original configurations with meld

pacnew=$(find /etc -type f -name "*.pacnew")

for i in $pacnew
do
  kdesu meld $i
done

Which isn't going to work very well.  Well, I guess it could, but it's going to open them all at once and leave a nice scruched-up taskbar with *.pacnew files.  Like to be able to go through them one by one.

Anyone had any experiences at this that could help?

Last edited by Gen2ly (2009-10-03 01:46:55)


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#2 2009-10-02 16:34:19

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,365
Website

Re: [Solved] A Challenge: Loop meld to update *.pacnew files

Maybe....

#!/bin/bash
# etc-update - merge *.pacnew files with original configurations with meld

pacnew=$(find /etc -type f -name "*.pacnew")

for i in $pacnew
do
  kdesu meld $(basename $i .pacmew) $i &
  wait
done

Note - untested

Offline

#3 2009-10-02 16:39:31

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [Solved] A Challenge: Loop meld to update *.pacnew files

http://pbrisbin.com:8080/bin/pacnews

just do a find/replace of vimdiff for meld (or whatever...)

Offline

#4 2009-10-02 16:40:18

ugkbunb
Member
Registered: 2009-02-26
Posts: 227

Re: [Solved] A Challenge: Loop meld to update *.pacnew files

I just edited the pacdiff script to use meld and it worked great : ) -- I am not at home atm, but if you would like I can post up my edited pacdiff script.

Last edited by ugkbunb (2009-10-02 16:40:44)

Offline

#5 2009-10-02 16:40:43

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: [Solved] A Challenge: Loop meld to update *.pacnew files

Allan wrote:

Maybe....

#!/bin/bash
# etc-update - merge *.pacnew files with original configurations with meld

pacnew=$(find /etc -type f -name "*.pacnew")

for i in $pacnew
do
  kdesu meld $(basename $i .pacmew) $i &
  wait
done

Note - untested

pacmew ? Kittens ?


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#6 2009-10-02 17:01:21

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [Solved] A Challenge: Loop meld to update *.pacnew files

How about

#!/bin/bash
pacnew=$(find /etc -type f -name "*.pacnew")

for i in $pacnew ; do
kdesu meld $i &
while (ps -e | grep ^$! &>/dev/null); do
    sleep 1
done
done

Edit: wait! big_smile

Last edited by lolilolicon (2009-10-02 17:46:29)


This silver ladybug at line 28...

Offline

#7 2009-10-02 17:30:29

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [Solved] A Challenge: Loop meld to update *.pacnew files

Nice one lolilolicon. BTW $! does not expire, so you could use kdesu meld $i & while [ -d /proc/$! ]; do sleep 1; done

Offline

#8 2009-10-02 17:48:14

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [Solved] A Challenge: Loop meld to update *.pacnew files

Procyon wrote:

Nice one lolilolicon. BTW $! does not expire, so you could use kdesu meld $i & while [ -d /proc/$! ]; do sleep 1; done

Procyon, this is Great! big_smile


This silver ladybug at line 28...

Offline

#9 2009-10-02 18:55:39

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: [Solved] A Challenge: Loop meld to update *.pacnew files

i wrote my full script a while back... but in the interest of a find-the-simplest-way challenge i'll post this version of allan's

for file in $(find /etc -name '*.pacnew'); do meld ${file/.pacnew/} $file; done

why do you all send it to the background then wait for it?  just leave it in foreground and the loop will wait for you, right?

/edit: screwed up the order
/edit2: nope, had it right the first time...

Last edited by brisbin33 (2009-10-02 18:57:32)

Offline

#10 2009-10-02 20:22:52

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: [Solved] A Challenge: Loop meld to update *.pacnew files

brisbin33 wrote:

http://pbrisbin.com:8080/bin/pacnews

just do a find/replace of vimdiff for meld (or whatever...)

Nice script, bris.  If I had know about that before, I'd be using it. smile  Do like the idea of the walk-through process and the saving of the the current one.

lol, I just read your last post and just what I thought about.

ugkbunb wrote:

I just edited the pacdiff script to use meld and it worked great : ) -- I am not at home atm, but if you would like I can post up my edited pacdiff script.

Yeah, I saw that on the wiki.  Said it was for CLI though so I didn't get to try.

@ lolilolicon, and Procyon

Still learning about pids, what I have seen was more complicated than this.  Pretty clever.

Allan wrote:

Maybe....

#!/bin/bash
# etc-update - merge *.pacnew files with original configurations with meld

pacnew=$(find /etc -type f -name "*.pacnew")

for i in $pacnew
do
  kdesu meld $(basename $i .pacmew) $i &
  wait
done

Note - untested

Ah, very nice.  Also fits into my knowledge of bash. smile  Hadn't thought about just using & but it works great.  Had to truncate the file extension and just used a bash filter:

#!/bin/bash
# pacnew-diff - merge *.pacnew files with original configurations with meld

pacnew=$(find /etc -type f -name "*.pacnew")

for config in $pacnew
do
  kdesu meld ${config%\.*} $config &
  wait
done

Like to be able to do a backup of the current config and then erase the pacnew file afterword, but havn't found out a way to do that without having to type in a password everytime, but, I guess, that can easily be done elsewhere.

Last edited by Gen2ly (2009-10-02 20:27:17)


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

#11 2009-10-03 02:10:50

Gen2ly
Member
From: Sevierville, TN
Registered: 2009-03-06
Posts: 1,529
Website

Re: [Solved] A Challenge: Loop meld to update *.pacnew files

Ooop, forgot to mention Thanks to everyone for all the help.

Thanks o/


Setting Up a Scripting Environment | Proud donor to wikipedia - link

Offline

Board footer

Powered by FluxBB