Phiên bản chức năng
Hướng dẫn:
Script xem xét bạn đang sử dụng gnome-terminal , là thiết bị đầu cuối Ubuntu mặc định.
Trước khi chạy tập lệnh, hãy mở gnome-terminal và tạo một số cấu hình (Chỉnh sửa> Tùy chọn> Cấu hình) với các cài đặt khác nhau theo ý muốn (màu nền, màu văn bản, ..). Bạn có thể đặt tên cho chúng là Profile1, Profile2, Profile3, v.v. Tạo đủ Hồ sơ để bao gồm số lượng Thiết bị đầu cuối sẽ được mở, nhưng nếu số lượng thiết bị đầu cuối được mở nhiều hơn, cấu hình mặc định sẽ được sử dụng.
Tập lệnh tạo một tệp ~ / .Bash_Color_Changer , tùy thuộc vào nó, vì nó sẽ báo cho tập lệnh nếu thiết bị đầu cuối được mở thường xuyên hoặc sau cuộc gọi trên .bashrc .
Thêm tập lệnh vào cuối tệp ~ / .bashrc của bạn .
Kịch bản:
Thêm vào .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
Đã thử nghiệm nhưng không rộng rãi. Thưởng thức!