Sources
- Add prefix and suffix to every line in a .txt file
- 'ls -1' : how to list filenames without extension
- Linux commands to fetch all files,size and path of files from all directories and subdirectories
- Remove files and subdirectories of particular folder
- How to make a text file in every subdirectory so that the text file contains name of the directory
Details
My script is based on @btd1337's Uratu Icons script for leaving only the third-party icons, but this script is not compatible with my icons theme project, because:
- Yaru++ and Canonical's Yaru have different hierarchies/trees;
- Yaru++ uses the format SVG and Yaru uses the format PNG.
So I rewrote a script in Shell Script to locate the directories and subdirectories of original Yaru, generate the output of all icons of each subdirectory to text files, and enter into the Yaru++ folder, list the text files to remove the files that already exist and leave only the third-party icons. I also proivided a compressed file for easing your analysis at the end of detail.
Pay attention to the sample and small trees of Yaru++ and Yaru:
Tree of Yaru++:
Yaru++ ├── actions │ ├── 16 │ │ ├── button_cancel.svg │ │ └── window-close.svg │ ├── 48 │ │ ├── button_cancel.svg │ │ └── window-close.svg │ ├── scalable │ │ ├── button_cancel.svg │ │ └── window-close.svg │ └── symbolic │ ├── button_cancel-symbolic.svg │ └── window-close-symbolic.svg └── apps ├── 16 │ ├── office.svg │ └── x-office-address-book.svg ├── scalable │ ├── office.svg │ └── x-office-address-book.svg └── symbolic ├── office-symbolic.svg └── x-office-address-book-symbolic.svg
Tree of original Yaru:
Yaru ├── 16x16 │ ├── actions │ │ ├── button_cancel.png │ │ └── window-close.png │ └── apps │ ├── office.png │ └── x-office-address-book.png ├── 48x48 │ ├── actions │ │ ├── button_cancel.png │ │ └── window-close.png │ └── apps │ ├── office.png │ └── x-office-address-book.png └── scalable ├── actions │ ├── button_cancel-symbolic.svg │ └── window-close.svg └── apps ├── officer-symbolic.svg └── x-office-address-book-symbolic.svg
Also pay attention to small details:
- In original Yaru, sizes are folders and directories are subfolders;
- In Yaru++, directories are folders and sizes are subfolders;
- Original Yaru's
scalable/[directories]
is same as Yaru++'s[directories]/symbolic
because their icons have the suffix-symbolic
.
Now I'll show each part of script in Shell Script:
Observe that directories
is the same in both Yaru and Yaru++. The sizes are different.
yaru_original="/usr/share/icons/Yaru"
declare -a yaru_original_sizes=(16x16 24x24 32x32 48x48 scalable)
yaru_plus="$HOME/GitHub/yaru-plus/Yaru++"
declare -a yaru_plus_sizes=(16 24 32 48 symbolic)
declare -a directories=(actions apps categories devices emblems mimetypes places status)
home="$(pwd)" # folder /script
The next part will locate the original Yaru, its folders (size
) and subfolders (directory
), and it will store to fileList
:
echo "PHASE 1 – Locate the directories of original Yaru"
function main()
{
cd $yaru_original
for size in "${yaru_original_sizes[@]}"
do
for directory in "${directories[@]}"
do
fileList $size $directory
done
done
cd $home
}
Then it will return to the original pwd
where the folder script
is.
It should output like:
# $yaru_original/$size/directory
/usr/share/icons/Yaru/16x16/actions
/usr/share/icons/Yaru/16x16/apps
/usr/share/icons/Yaru/24x24/actions
/usr/share/icons/Yaru/24x24/apps
/usr/share/icons/Yaru/32x32/actions
/usr/share/icons/Yaru/32x32/apps
/usr/share/icons/Yaru/48x48/actions
/usr/share/icons/Yaru/48x48/apps
/usr/share/icons/Yaru/scalable/actions
/usr/share/icons/Yaru/scalable/apps
# ...
Then the function fileList
that stored the subdirectories from the function main
, and will generate the output of all icons without extension (because Yaru uses the format PNG and Yaru++ uses the format SVG) of each subdirectory:
echo "PHASE 2 – Generate output files without extension"
function fileList()
{
local directory=$1
local size=$2
local search_file=($(find $yaru_original/$size/$directory/))
if [ $search_file ]
then
for entry in "${search_file[@]}"
do
for i in *; do echo "${i%.png}"; done > $home/$directory-$size.txt
done
fi
}
It should output like:
# $home/$directory-$size.txt
/home/gus/script/actions-16x16.txt
/home/gus/script/apps-16x16.txt
/home/gus/script/actions-24x24.txt
/home/gus/script/apps-24x24.txt
/home/gus/script/actions-32x32.txt
/home/gus/script/apps-32x32.txt
/home/gus/script/actions-48x48.txt
/home/gus/script/apps-48x48.txt
/home/gus/script/actions-scalable.txt
/home/gus/script/apps-scalable.txt
Observe that I do not know to subtract x{size}
and to replace scalable
for symbolic
which is not present in original Yaru's array yaru_original_sizes
.
Inside a file actions-16x16.txt
:
button_cancel
window-close
Now, in the final party, it will read the text files using awk
and printing the extension .svg
, and will remove the files that already exist in Yaru, from Yaru++:
echo "PHASE 3 – Remove the files that already exist in Canonical's original Yaru"
function removeList()
{
cd $yaru_plus
for directory in "${directories[@]}"
do
for size in "${yaru_plus_sizes[@]}"
do
rm $(awk '{ print $0".svg" }' $home/$size-$directory.txt)
done
done
}
main
Output of awk '{ print $0".svg" }' $home/$size-$directory.txt
:
# awk '{ print $0".svg" }' /home/gus/script/actions-16x16.txt
button_cancel.svg
window-close.svg
Output of rm $(awk '{ print $0".svg" }' $home/$size-$directory.txt)
:
rm /home/gus/GitHub/yaru-plus/Yaru++/actions/16/button_cancel.svg
rm /home/gus/GitHub/yaru-plus/Yaru++/actions/16/window-close.svg
rm /home/gus/GitHub/yaru-plus/Yaru++/actions/48/button_cancel.svg
rm /home/gus/GitHub/yaru-plus/Yaru++/actions/48/window-close.svg
rm /home/gus/GitHub/yaru-plus/Yaru++/actions/symbolic/button_cancel-symbolic.svg
rm /home/gus/GitHub/yaru-plus/Yaru++/actions/symbolic/window-close-symbolic.svg
rm /home/gus/GitHub/yaru-plus/Yaru++/apps/16/office.svg
rm /home/gus/GitHub/yaru-plus/Yaru++/apps/16/x-office-address-book.svg
rm /home/gus/GitHub/yaru-plus/Yaru++/apps/48/office.svg
rm /home/gus/GitHub/yaru-plus/Yaru++/apps/48/x-office-address-book.svg
rm /home/gus/GitHub/yaru-plus/Yaru++/apps/symbolic/office-symbolic.svg
rm /home/gus/GitHub/yaru-plus/Yaru++/apps/symbolic/x-office-address-book-symbolic.svg
I will provide a small compressed folder for easing your analysis: https://github.com/Bonandry/yaru-plus/files/5013472/UnixStackExchange.zip
Result
The script was unsuccessful because the error output:
find: ‘/usr/share/icons/Yaru/16x16/128x128/’: No file or folder
find: ‘/usr/share/icons/Yaru/24x24/128x128/’: No file or folder
find: ‘/usr/share/icons/Yaru/32x32/128x128/’: No file or folder
find: ‘/usr/share/icons/Yaru/48x48/128x128/’: No file or folder
My script did not work, and it seemed my codes are not correct. How to locate correctly directories and subdirectories, using function and for
condition, to store for fileList
and how to make fileList
generate correctly the file output with all icons of each subdirectory, and then to remove the files that already exist in Yaru, from Yaru++ and leave only the third-party icons?
fileList $size $directory
, but in thefileList
function, you havelocal directory=$1
local size=$2
- why swap the order of arguments?for entry in "${search_file[@]}" do for i in *; do echo "${i%.png}"; done
, ignoring theentry
altogether?