How to set the background color of the git bash terminal - terminal

I would like to set the background color of my whole terminal. google didn't help.
The idea is to have it set to red when working in a prod context and black when in dev context.
Ideally would like to do it using the .bash_profile file where I have code to switch environment context.

Console colors are stored in the registry under HKCU/Console/[window name]/ColorTable00-15.
[window name] is either "Git Bash" for the start menu entry or something like "C:_Program Files (x86)_Git_git-cheetah_.._bin_sh.exe" for the Windows Explorer context menu entry (supplied by Git-Cheetah).
Alternatively, the registry settings can be overridden by storing an NT_CONSOLE_PROPS structure with appropriate ColorTable settings in the "Git Bash.lnk" shortcut via IShellLinkDataList::AddDataBlock. This happens e.g. if you edit the properties of a console window started via shortcut, or if you edit the shortcut properties directly.
If you want the values from the registry instead, create a new "Git Bash.lnk" shortcut from scratch and leave the Options/Font/Layout/Colors tabs alone.
It seems the only way I can see so far is to manually edit the boxes from the properties window, but this is buggy and tedious - you can't use hex strings, and selecting the color to inspect it sometimes alters the color wildly.
enter image description here

Related

How to change the font color of SageMath terminal version 9.5?

I am rocking a Ubuntu 22.04 laptop, so I am stuck to SageMath v9.5, instead of the current version as of today. The font is currently blue, which is not the best match at all with the default purple terminal background. How could I change the color to, let's say, green?
I've tried something in this link, but the approach is so old, it doesn't apply to this version anymore. I can type %colors Linux at the Sage shell itself, but it resets whenever I log off.
You can change the font colour of the terminal by modifying the Sage Terminal profile in the terminal's preferences.
Open the terminal in SageMath.
Go to Edit > Profile Preferences.
In the Profile Preferences window, select the Colours tab.
4.Under Text colour, you can use the colour picker to select a new font colour for the terminal.
5.Click Close to apply the changes and close the window.
I've tried something in this link, but the approach is so old, it
doesn't apply to this version anymore. I can type %colors Linux at the
Sage shell itself, but it resets whenever I log off.
You have to save the command %colors Linux into init.sage file which will be save at location ~/.sage/init.sage you can flow the below steps to achieve this
Open the Terminal by pressing keys Ctrl+Alt+T or from all programs
Go to ~/.sage directory by using cd ~/.sage command
Enter touch init.sage to create a file by the name init.sage
Open the file with an editor like vim/nano etc
Now write the command %colors Linux and save the file and close it
New font color will not change after restarting sage

Reuse window / tab when file is already open

I want to set a global shortcut that will open a certain file. When there already is a gvim window that has that file open, I want it to focus on that window, and select the tab with that file. If there isn't, I want it to be opened in a new gvim window, regardless of whether there already are other gvim windows.
I can do part of this with --remote and --servername, but I can't find a way to detect whether there already is a remote server running with the name I use, so I can't quite get everything to work together to come to what I described above.
OK, turns out most can be done using the default behavior of --remote-silent. The whole setup is a matter of making an AutoHotkey script like this:
#!^+1::
Run "c:\Program Files (x86)\vim\vim74\gvim.exe" --servername org --remote-silent %DROPBOX%\org\TODO.org
WinActivate, TODO.org
Return
AHK is needed for the global hotkey as well as activating the window; vim (using --servername and --remote-silent) will start a new session called 'org' if there isn't one yet, and start it otherwise. It even gets the tab activation right when there already is a server called 'org' but if that server has another tab active.

Loading Git Bashes with different background colours

I need to have a couple of bashes open pointing to different repos.
I'd like to have them with different background colours so it's less confusing to see.
I assume that the colour options aren't specific to the Git Bash as the Windows Command Prompt has the same options in the properties window.
I know that the OS or whatever must be storing these somewhere, as they are persisted between sessions.
Does anyone know how to achieve this?
press alt+spacebar or click on the git bash window's icon on top left, select "properties" then choose the tab "colors" and select the desired color
I'm not sure that there's a way to pass this on to the shell instance's host cmd window when you start, but you can definitely wrap your existing call in a customized window: make a shortcut to cmd and then pass it the color option as well as a command - in this case, to start the shell process.
Would look like this in the shortcut's Target properties: %windir%\system32\cmd.exe /T:24 c:\path\to\msysgit\sh.exe (or path to your current shortcut, since there will maybe be flags or options used there).
On Windows environment you can use color command. It changes font and background color simultaneously.
What you need to is to run color command before running sh.exe. Start cmd.exe and type:
color EA
"c:\Program Files\Git\bin\sh.exe"
This example makes windows terminal green-yellow.
Run color /? and sh.exe --help for more.

How to change Terminal background color when I open new tab?

I wanted to change color when I login to remote server by ssh.
The problem solved by this question.
How do I make the apple terminal window auto change colour scheme when I ssh to a specific server
But the solution above have a little problem.
Connet to remote server by ssh. (Background color is changed)
Open new terminal Tab.
This Tab's background is still changed.
So I want to "reset" background color when I open new Terminal Tab.
How can I do it?
By default, Terminal creates new tabs with the same settings as the current tab. You can change it to always use your default profile for new tabs in Preferences > Startup by changing New tabs open with: to Default Settings.
Note that there’s a built-in way to automatically set the background color for specific commands instead of using the script from that other answer:
You can set the name of a settings profile to a command name and Terminal will select that profile when you create a new terminal via either Shell > New Command… or Shell > New Remote Connection….
For example, duplicate your default profile, name it “ssh” and set its background color to red. Then use New Command… to run ssh host.example.com.
It also matches on arguments, so you can have it choose different settings for different remote hosts, for example. You could have one named “ssh host.example.com” with a blue background and another named “ssh” with a red background to handle any ssh commands that don’t match other profiles.

How can I change the main display via AppleScript?

From the Displays pane in System Preferences, I can manually change the main monitor by dragging the menu bar from one display to the other. I'd like to automate this and make it part of an AppleScript.
The tool I wrote, displayplacer, does this.
Configure your screens how you like, drag the "white bar" to your primary screen in the macOS system settings, and then execute displayplacer list. It will output the command to run to put your screens in their current configuration. The screen with origin:(0,0) is the main display with the "white bar". Run this terminal command through a script, Automator, BetterTouchTool, etc.
Example profile 1 puts the white bar on the menu bar on the left monitor.
displayplacer "id:<leftScreenId> res:1920x1080 scaling:on origin:(0,0) degree:0" "id:<rightScreenId> res:1920x1080 scaling:on origin:(1920,0) degree:0"
Example profile 1 puts the white bar on the menu bar on the right monitor.
displayplacer "id:<leftScreenId> res:1920x1080 scaling:on origin:(1920,0) degree:0" "id:<rightScreenId> res:1920x1080 scaling:on origin:(0,0) degree:0"
Also available via Homebrew brew tap jakehilborn/jakehilborn && brew install displayplacer
The displays are controlled by the /Library/Preferences/com.apple.windowserver.plist preference file:
A flag controls whether the main display is the onboard screen the DisplayMainOnInternal key.
The DisplaySets key contains the list of the display sets. The first set is the one used (fact to check).
In the set, each item contains the screen properties. The IOFlags key seems to indicate if the display is the main one (value of 7) or not (value of 3).
Before going Apple Script, you may change the display configuration by hand, and save a copy of the /Library/Preferences/com.apple.windowserver.plist file to study it.
Note that the following procedure has not been tested !!!
With AppleScript, the keys in the plist file are changed individually, in order to change the main display:
Make a backup of the /Library/Preferences/com.apple.windowserver.plist (in case of)
Alter the display set the select the main display (DisplaySets and IOFlags keys) by using the defaults command
Restart the Window Server: killall -KILL SystemUIServer
You should see if you can do it via AppleScript's User Interface Scripting. It allows you to manipulate an application's GUI elements; useful when the app doesn't support scripting directly. I'd test it myself but I don't have any extra displays lying around.
Here's a pretty good overview by MacTech.
Much like you can tell System Events.app to sleep your Mac, you can tell Image Events.app to mess with your displays. The Image Events application provides a "displays" collection. Each display has a "profile" with lots of goodies. However, everything I just mentioned is read-only, so I don't have a good way to do it from within script.
You might have better luck in Automator – Hit record, run System Preferences, go to Displays, drag the menu bar to the other screen, and hit stop. I bet something will work.
Using AppleScript, you can invoke default to write the setting to change the main monitor.

Resources