rene wrote: ⤴Fri Jan 14, 2022 5:29 am
The query makes not enormous sense to me. Is there anything wrong with, for the correct values of "desk_name", "lap_name" and whatever list you speak of, a simple e.g.
sed
?
No, it won't.
The problem is : when you don't want to bother people with your project, you end giving them insufficient infos to really understand what's going on. So' I'll try to be more precise :
I wrote quite a number of functions performing the elementary tasks to get some custom infos of my system. I won't give the whole list but names will speak for them : GetNemoConf, GetFavs, GetMenuItems, GetCustIcons...
These functions all write their data into an associated .cust file (nemo.cust, favs.cust, menu.cust, icon.cust...)
Of course there is a "Set" function associated to be able to recover these datas (SetNemoConf, SetFavs...)
In most of these .cust files there are items / lines with the file:/// header I mentioned in my original post followed by an absolute path.
Restoring on the same computer works fine because absolute paths are identical to the .cust files. The idea is to be able to transfer these config files on another computer (of course, must have the same distro and DE settings) and to replace every occurrence of the previous user (desk_user) with the new one (lap_user) in all files. However, if some nice settings are made on the laptop, the reverse is also meant to be possible (transfering the .cust files from the laptop to the desktop and some other computers I didn't mention)
This can already be done by the function :
Code: Select all
TranslateUserName() {
local PrevUser=$1
find $CustDir -name '*.cust' -exec sed -i 's|home/'$PrevUser'|home/'$USER'|g' {} +
}
$CustDir is a global variable defined in .bashrc containing the directory where all those .cust files and some others are saved - It has neither spaces nor fancy extension but I'll remember about the double quotes for portability
. $PrevUser has no sense under that form - $1 would do the job as well.
As you've noticed TranslateUserName() needs an argument, the previous user. What I'm looking for is automation of the process without any argument and just getting the previous user (which is not always the same) by extracting his name from any file:/// output and put it in the $PrevUser variable, something like
PrevUser=$(GetPrevUserNameFromFile///)
(that is by no means a syntax)
Feel free to ask if I wasn't clear enough