我经常会发现自己打开了三个终端,我真的很喜欢每个终端都有不同调色板的外观。
我保存了一些调色板,我希望每次打开终端时都能通过默认的设置来浏览保存的配置文件,因此,如果我打开3种,则每种颜色都是不同的,而无需手动更改2种配置文件。
有什么想法吗?
谢谢!
指示:
脚本认为您使用的是gnome-terminal,这是默认的Ubuntu终端。
在运行脚本之前,请打开gnome终端,并根据需要创建一些具有不同设置的配置文件(“编辑”>“首选项”>“配置文件”)(背景颜色,文本颜色,..)。您可以将它们命名为Profile1,Profile2,Profile3等。创建足够的配置文件以涵盖将要打开的终端数量,但是如果打开的终端数量更多,则将使用默认配置文件。
该脚本创建了〜/ .Bash_Color_Changer文件,它依赖于此文件,因为它将告诉脚本终端是定期打开还是在调用.bashrc之后打开。
将脚本添加到〜/ .bashrc文件的末尾。
脚本:
添加到.bashrc
:
#Change color according to the number of Bash shells opened
#Creates the .Bash_Color_Changer file if it's not present
if ! [ -f ~/.Bash_Color_Changer ]; then
echo ORIGINAL > ~/.Bash_Color_Changer
fi
#Array holding the name of the profiles: Substitute it for the names you're using
Color_counter=(Profile1 Profile2 Profile3)
#Finds out the number of opened bashs counting the lines containing "bash"
#in the pstree function. (-c deactivates compact display to avoid it showing
#lines with "2*[bash]" instead of one for each bash)
Number_of_bashs=$(($(pstree -c | grep "bash" | wc -l)-1))
#Checks if the terminal being opened was opened by the user or by
#the script, and act according to it
if [ $(cat ~/.Bash_Color_Changer) = ORIGINAL ]; then
if ((Number_of_bashs < ${#Color_counter[*]})); then
echo COPY > ~/.Bash_Color_Changer
gnome-terminal --tab-with-profile-internal-id=${Color_counter[${Number_of_bashs}]}
exit
fi
else
echo ORIGINAL > ~/.Bash_Color_Changer
fi
经过测试,但未进行广泛的测试。享受!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句