Skip to content

Instantly share code, notes, and snippets.

@ttys3
Forked from algal/colorize-emacs.bashsource
Created February 16, 2021 17:07
Show Gist options
  • Select an option

  • Save ttys3/a9412561f41f8f77244d09c17868395e to your computer and use it in GitHub Desktop.

Select an option

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
# 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
}
#!/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
@briansorahan
Copy link
Copy Markdown

Thank you! I was ripping my hair out because of these weird black lines that kept showing up in emacs under iTerm2, and this seems to have fixed the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment