我写了这个小脚本来换掉Numix主题上Ubuntu Gnome的颜色:
<?php
$oldColor = $argv[1];
$newColor = $argv[2];
// defaults
// $oldColor = 'd64937';
// $newColor = 'f66153';
$path = '/usr/share/themes/Numix/gtk-3.0/gtk-dark.css';
$fileRead = fopen($path, 'r');
$contents = fread($fileRead, filesize($path));
$newContents = str_replace($oldColor, $newColor, $contents);
$fileWrite = fopen($path, 'w');
fwrite($fileWrite, $newContents);
fclose($fileWrite);
?>
只要我传递了两个参数,脚本就会按预期工作。
答案 0 :(得分:3)
<?php
// How do I set defaults for the arguments?
$oldColor = !empty($argv[1]) ? $argv[1] : 'd64937';
$newColor = !empty($argv[2]) ? $argv[2] : 'f66153';
$file = '/usr/share/themes/Numix/gtk-3.0/gtk-dark.css';
// Your choice whether its cleaner, I think so.
file_put_contents(
$file,
str_replace(
$oldColor,
$newColor,
file_get_contents($file)
)
);
?>
答案 1 :(得分:1)
我要去学习Loz Cherone的答案,这对我来说有点先进(这是我的第一个剧本),但我确实想出了更好的东西:
<?php
if (empty($argv[1])) {
$oldColor = 'd64937';
$newColor = 'f66153';
} elseif (empty($argv[2])) {
echo "Please supply new color";
return false;
} else {
$oldColor = $argv[1];
$newColor = $argv[2];
}
$path = '/usr/share/themes/Numix/gtk-3.0/gtk-dark.css';
$oldContents = file_get_contents($path);
$newContents = str_replace($oldColor, $newColor, $oldContents);
file_put_contents($path, $newContents);
?>
答案 2 :(得分:0)
在Ubuntu上运行Numix主题的任何人分享最终产品似乎是公平的。只需将脚本复制到.php文件中并以sudo身份运行即可。首先备份这两个文件。
<?php
if (!empty($argv[1]) && empty($argv[2])) {
echo "Please supply two colors for your very own custom color swap or zero colors for a slight improvement";
return false;
}
$oldColor = !empty($argv[1]) ? $argv[1] : 'd64937';
$newColor = !empty($argv[2]) ? $argv[2] : 'f66153';
$file_1 = '/usr/share/themes/Numix/gtk-3.0/gtk-dark.css';
$file_2 = '/usr/share/themes/Numix/gtk-2.0/gtkrc';
file_put_contents(
$file_1,
str_replace(
$oldColor,
$newColor,
file_get_contents($file_1)
)
);
file_put_contents(
$file_2,
str_replace(
$oldColor,
$newColor,
file_get_contents($file_2)
)
);
?>