mirror of
				https://github.com/sharkdp/bat.git
				synced 2025-10-31 15:12:12 +00:00 
			
		
		
		
	docs: Include GNOME bash script for Dark Mode
Title. I developed this on Fedora 39 with GNOME. Tested and works on my setup as expected.
This commit is contained in:
		
				
					committed by
					
						 Martin Nordholts
						Martin Nordholts
					
				
			
			
				
	
			
			
			
						parent
						
							94f1035c08
						
					
				
				
					commit
					1bcf760d90
				
			
							
								
								
									
										30
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								README.md
									
									
									
									
									
								
							| @@ -711,7 +711,7 @@ sidebar. Calling `bat` with `--tabs=0` will override it and let tabs be consumed | |||||||
|  |  | ||||||
| ### Dark mode | ### Dark mode | ||||||
|  |  | ||||||
| If you make use of the dark mode feature in macOS, you might want to configure `bat` to use a different | If you make use of the dark mode feature in **macOS**, you might want to configure `bat` to use a different | ||||||
| theme based on the OS theme. The following snippet uses the `default` theme when in the _dark mode_ | theme based on the OS theme. The following snippet uses the `default` theme when in the _dark mode_ | ||||||
| and the `GitHub` theme when in the _light mode_. | and the `GitHub` theme when in the _light mode_. | ||||||
|  |  | ||||||
| @@ -719,6 +719,34 @@ and the `GitHub` theme when in the _light mode_. | |||||||
| alias cat="bat --theme auto:system --theme-dark default --theme-light GitHub" | alias cat="bat --theme auto:system --theme-dark default --theme-light GitHub" | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
|  | The same dark mode feature is now available in **GNOME** and affects the `org.gnome.desktop.interface color-scheme` setting. The following code converts the above to use said setting. | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | # .bashrc | ||||||
|  | sys_color_scheme_is_dark() { | ||||||
|  |     condition=$(gsettings get org.gnome.desktop.interface color-scheme) | ||||||
|  |     condition=$(echo "$condition" | tr -d "[:space:]'") | ||||||
|  |     if [ $condition == "prefer-dark" ]; then | ||||||
|  |         return 0 | ||||||
|  |     else | ||||||
|  |         return 1 | ||||||
|  |     fi | ||||||
|  | } | ||||||
|  |  | ||||||
|  | bat_alias_wrapper() { | ||||||
|  |     #get color scheme | ||||||
|  |     sys_color_scheme_is_dark | ||||||
|  |     if [[ $? -eq 0 ]]; then | ||||||
|  |         # bat command with dark color scheme | ||||||
|  |         bat --theme=default "$@" | ||||||
|  |     else | ||||||
|  |         # bat command with light color scheme | ||||||
|  |         bat --theme=GitHub "$@" | ||||||
|  |     fi | ||||||
|  | } | ||||||
|  | alias cat='bat_alias_wrapper' | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  |  | ||||||
| ## Configuration file | ## Configuration file | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user