-
-
Save ttys3/a9412561f41f8f77244d09c17868395e to your computer and use it in GitHub Desktop.
Setting up truecolor (24 bit color) in emacs in the terminal, under iTerm2
This file contains 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
# sourcing this file will define a bash functions that | |
# tries to run subsequent calls to emacs with 24 bit color. | |
# | |
# It sets TERM to xterm-24bit if we're running in iTerm2 | |
# and we've created a user-local terminfo record for xterm-24bit | |
# | |
# This will cause emacs to use 24 bit color only when it will work, | |
# inside or outside of tmux | |
# | |
# details: https://gist.github.com/XVilka/8346728 | |
emacs () { | |
if [ "$LC_TERMINAL" == "iTerm2" -a -f "$HOME/.terminfo/x/xterm-24bit" ] | |
then | |
TERM=xterm-24bit command emacs "$@" | |
else | |
command emacs "$@" | |
fi | |
} |
This file contains 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
#!/bin/bash | |
# adds a terminfo entry defining a new terminal xterm-24bit | |
# If you run emacs (26.1+) setting TERM=xterm-24bit, then it | |
# will use 24bit color | |
# | |
# after running this, you can use colorize-emacs.bashsource to enable 24bit color | |
cd $(mktemp -d) | |
cat <<EOF > terminfo-24bit.src | |
# Use colon separators. | |
xterm-24bit|xterm with 24-bit direct color mode, | |
use=xterm-256color, | |
setb24=\E[48:2:%p1%{65536}%/%d:%p1%{256}%/%{255}%&%d:%p1%{255}%&%dm, | |
setf24=\E[38:2:%p1%{65536}%/%d:%p1%{256}%/%{255}%&%d:%p1%{255}%&%dm, | |
# Use semicolon separators. | |
xterm-24bits|xterm with 24-bit direct color mode, | |
use=xterm-256color, | |
setb24=\E[48;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%dm, | |
setf24=\E[38;2;%p1%{65536}%/%d;%p1%{256}%/%{255}%&%d;%p1%{255}%&%dm, | |
EOF | |
tic -x -o ~/.terminfo terminfo-24bit.src | |
rm terminfo-24bit.src | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment