-
-
Save andrepiske/b8e5b08479994e633c22cd1bc30a1844 to your computer and use it in GitHub Desktop.
Set iTerm2 tab color
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # Codes at https://iterm2.com/documentation-escape-codes.html | |
| # License: MIT License, text at https://mit-license.org/ | |
| color_table = { | |
| 'blue' => '#2d74ef', | |
| 'blue-2' => '#5bb0d8', | |
| 'red' => '#f22e2e', | |
| 'red-2' => '#d17777', | |
| 'yellow' => '#f2e235', | |
| 'yellow-2' => '#efcb2b', | |
| 'pink' => '#e52bef', | |
| 'green' => '#66ef2b', | |
| 'green-2' => '#aad398', | |
| 'white' => '#ffffff', | |
| 'gray' => '#c4c4c4', | |
| 'gray-2' => '#5b5b5b', | |
| 'black' => '#000000', | |
| } | |
| def setcolor(colors) | |
| print(['red', 'green', 'blue'].zip(colors).map do |n, v| | |
| "\x1b]6;1;bg;#{n};brightness;#{v}\x07" | |
| end.join) | |
| end | |
| def to_rgb(s) | |
| [ s[1..2], s[3..4], s[5..6] ].map{|x| x.to_i(16)} | |
| end | |
| color_name = ARGV[0]&.downcase | |
| unless color_table.key?(color_name) | |
| puts "Usage: co <color name>\nAvailable colors:" | |
| color_table.each { |n,_| puts(" #{n}") } | |
| return | |
| end | |
| setcolor(to_rgb color_table[color_name]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment