You are not logged in.

#1 2009-10-07 12:59:39

robrene
Member
Registered: 2009-04-16
Posts: 168

[Bash] Automated symlinking question

Hey all, I've been struggling getting a tedious task of recreating symlinks automated... Let me justgive you an example of what I'd be doing by hand:

[~/.icons/my-theme/scalable/apps/ $] ls -l
total 8464
-rw-r--r-- 1 rob rob   3781 2008-06-05 12:08 abiword.svg
lrwxrwxrwx 1 rob rob     37 2009-05-31 16:59 access.svg -> preferences-desktop-accessibility.svg
-rwxrwxrwx 1 rob rob  43384 2009-03-29 13:00 accessories-calculator.svg
-rwxrwxrwx 1 rob rob  11145 2009-03-29 13:00 accessories-character-map.svg
-rw-r--r-- 1 rob rob  15667 2009-03-29 13:00 accessories-dictionary.svg
-rwxrwxrwx 1 rob rob  37368 2009-03-29 13:00 accessories-text-editor.svg
lrwxrwxrwx 1 rob rob     16 2009-05-30 18:29 acroread.svg -> adobe-reader.svg
lrwxrwxrwx 1 rob rob     38 2009-06-07 00:31 addressbook.svg -> ../mimetypes/x-office-address-book.svg
-rwxrwxrwx 1 rob rob   8885 2009-03-17 19:04 adobe-reader.svg
-rwxrwxrwx 1 rob rob  63899 2009-03-17 19:04 agave.svg
-rwxrwxrwx 1 rob rob  27652 2009-03-17 19:04 alacarte.svg
-rw-r--r-- 1 rob rob   9626 2008-06-05 12:08 amarok.svg
lrwxrwxrwx 1 rob rob     10 2009-05-30 18:55 amsn.svg -> im-msn.svg
-rw-r--r-- 1 rob rob  22315 2008-06-28 23:14 amule.svg
-rwxr-xr-x 1 rob rob 524008 2009-02-18 13:23 applets-screenshooter.svg
-rw-r--r-- 1 rob rob  15346 2008-08-06 21:00 application-default-icon.svg
-rwxrwxrwx 1 rob rob  12422 2009-03-17 19:04 appointment.svg
-rwxrwxrwx 1 rob rob   9381 2009-03-17 19:04 apport.svg
-rw-r--r-- 1 rob rob  43011 2008-07-31 23:30 aptoncd.svg
-rw-r--r-- 1 rob rob  21049 2008-06-05 11:42 ardour.svg
lrwxrwxrwx 1 rob rob      8 2009-05-31 21:31 audacious.svg -> xmms.svg
lrwxrwxrwx 1 rob rob     13 2009-09-25 12:25 audacious2.svg -> audacious.svg
-rw-r--r-- 1 rob rob  32781 2008-06-05 12:08 audacity.svg
-rwx------ 1 rob rob   8232 2009-03-21 09:24 audio-player.svg
-rw-r--r-- 1 rob rob  22008 2008-06-05 12:08 avant-window-navigator.svg
lrwxrwxrwx 1 rob rob      9 2009-05-30 20:08 avidemux.svg -> video.svg
-rw-r--r-- 1 rob rob  30860 2008-10-25 17:31 azureus.svg
... etc

Now I would cd ../../32x32/apps/ and then
ln -s preferences-desktop-accessibility.png access.png
ln -s adobe-reader.png acroread.png
ln -s ../mimetypes/x-office-address-book.png addressbook.png
ln -s im-msn.png amsn.png
ln -s xmms.png audacious.png
ln -s audacious.png audacious2.png
ln -s video.png avidemux.png
... etc

Notice how the extention has changed from .svg to .png

Now I would like this to be automated through some sort of bash script (any scripting language will do really).

I've tried getting this done, I just really have no clue when using bash. I realise we should probably write a script in the 32x32/apps/ folder that calls `ls -l ../../scalable/apps` and then works some magic, this I've failed at though.
Could someone please help me? This is such a tedious task to do by hand...


smile neutral sad big_smile yikes wink hmm tongue lol mad roll cool

Offline

#2 2009-10-08 10:32:21

grey
Member
From: Europe
Registered: 2007-08-23
Posts: 679

Re: [Bash] Automated symlinking question

I'd use perl and work from the text you get from ls -l. Bit low tech, but it should work.

1. ls -l ~/.icons/my-theme/scalable/apps/ > dirlisting
2. write perl script that extracts the (source, target) pairs of the links. The main loop should be something like

while <dirlisting> {
  next unless /^l/;
  if (/ (\S+)\.svg -> (\S+)\.svg/) {
    print "linking $1 to $2\n";
    system ("ln -s $1.png $2.png");
  }
}

3. run that script in all the directories where you want to create the symlinks.


Good ideas do not need lots of lies told about them in order to gain public acceptance.

Offline

Board footer

Powered by FluxBB