[zsh] replace base16-shell with a custom colorscheme engine

This commit is contained in:
Dmytro Meleshko 2019-09-15 20:02:00 +03:00
parent 12e4fd22ad
commit 0e201ba4ea
6 changed files with 145 additions and 8 deletions

View file

@ -7,9 +7,10 @@ cd "$(dirname "${BASH_SOURCE[0]}")"
mkdir -p out
declare -A apps=(
[nvim]=vim
[iterm]=itermcolors
[kitty]=conf
[nvim]=vim
[shell]=zsh
[termux]=properties
)

View file

@ -0,0 +1,31 @@
colorscheme_bg=2d2d2d
colorscheme_fg=d3d0c8
colorscheme_cursor_bg=d3d0c8
colorscheme_cursor_fg=2d2d2d
colorscheme_selection_bg=515151
colorscheme_selection_fg=d3d0c8
colorscheme_link_color=6699cc
colorscheme_ansi_colors=(
2d2d2d
f2777a
99cc99
ffcc66
6699cc
cc99cc
66cccc
d3d0c8
747369
f2777a
99cc99
ffcc66
6699cc
cc99cc
66cccc
f2f0ec
f99157
d27b53
393939
515151
a09f93
e8e6df
)

20
colorschemes/shell.py Executable file
View file

@ -0,0 +1,20 @@
#!/usr/bin/env python3
import _theme as theme
for attr in [
"bg",
"fg",
"cursor_bg",
"cursor_fg",
"selection_bg",
"selection_fg",
"link_color",
]:
color = getattr(theme, attr)
print("colorscheme_{}={}".format(attr, color[1:]))
print("colorscheme_ansi_colors=(")
for color in theme.ansi_colors:
print(" {}".format(color[1:]))
print(")")

91
zsh/colorscheme.zsh Normal file
View file

@ -0,0 +1,91 @@
#!/usr/bin/env bash
# partially based on https://github.com/chriskempson/base16-shell/blob/master/templates/default.mustache
source "$ZSH_DOTFILES/../colorschemes/out/shell.zsh"
if [[ -n "$TMUX" ]]; then
# tmux
terminal_wrapper=tmux
elif [[ -n "$STY" ]]; then
# GNU Screen
terminal_wrapper=screen
fi
if [[ -z "$terminal_wrapper" ]]; then
case "$TERM" in
linux*) terminal="linux" ;;
*) terminal="xterm" ;;
esac
export _COLORSCHEME_TERMINAL="$terminal"
else
terminal="${_COLORSCHEME_TERMINAL:-xterm}"
fi
# when a terminal wrapper is detected certain control sequences are used to
# send color change control sequences directly to the terminal
case "$terminal_wrapper" in
tmux)
# http://permalink.gmane.org/gmane.comp.terminal-emulators.tmux.user/1324
_colorscheme_print_ctrl_seq() { print -n "\ePtmux;\e$1\e\\"; }
;;
screen)
# GNU screen uses the standard DCS (Device Control String) sequence (see
# console_codes(4) manpage)
_colorscheme_print_ctrl_seq() { print -n "\eP$1\e\\"; }
;;
*)
_colorscheme_print_ctrl_seq() { print -n "$1"; }
;;
esac; unset terminal_wrapper
case "$terminal" in
linux)
_colorscheme_print_osc_seq() {}
_colorscheme_set_attr_to_color() {}
_colorscheme_set_ansi_color() {
# Linux console supports setting only 16 ANSI colors and interestingly
# enough uses only 8 of them
if (( $1 >= 0 && $1 < 16 )); then
_colorscheme_print_ctrl_seq "$(printf "\e]P%X%s" "$1" "$2")"
fi
}
;;
xterm)
_colorscheme_print_osc_seq() {
_colorscheme_print_ctrl_seq "\e]$1\a";
}
_colorscheme_set_attr_to_color() {
_colorscheme_print_osc_seq "$1;rgb:${2[1,2]}/${2[3,4]}/${2[5,6]}";
}
_colorscheme_set_ansi_color() {
_colorscheme_set_attr_to_color "4;$1" "$2";
}
;;
esac; unset terminal
set-my-colorscheme() {
local i; for (( i = 1; i <= ${#colorscheme_ansi_colors}; i++ )); do
_colorscheme_set_ansi_color "$((i-1))" "${colorscheme_ansi_colors[$i]}"
done
if [[ -n "$ITERM_SESSION_ID" ]]; then
# iTerm2 proprietary escape codes
# https://www.iterm2.com/documentation-escape-codes.html
_colorscheme_print_osc_seq Pg"$colorscheme_fg"
_colorscheme_print_osc_seq Ph"$colorscheme_bg"
_colorscheme_print_osc_seq Pi"$colorscheme_fg" # bold
_colorscheme_print_osc_seq Pj"$colorscheme_selection_bg"
_colorscheme_print_osc_seq Pk"$colorscheme_selection_fg"
_colorscheme_print_osc_seq Pl"$colorscheme_cursor_bg"
_colorscheme_print_osc_seq Pm"$colorscheme_cursor_fg"
else
_colorscheme_set_attr_to_color 10 "$colorscheme_fg"
_colorscheme_set_attr_to_color 11 "$colorscheme_bg"
if [[ "$TERM" = rxvt* ]]; then
# internal window border
_colorscheme_set_attr_to_color 708 "$colorscheme_bg"
fi
fi
}
set-my-colorscheme

View file

@ -85,9 +85,6 @@ plugin alias-tips 'djui/alias-tips'
plugin ssh 'zpm-zsh/ssh'
plugin base16-shell 'chriskempson/base16-shell' \
after_load='export BASE16_SHELL="$plugin_dir"'
FAST_WORK_DIR="$ZSH_CACHE_DIR"
if [[ "$TERM" != "linux" ]]; then
plugin fast-syntax-highlighting 'zdharma/fast-syntax-highlighting'

View file

@ -2,7 +2,7 @@
ZSH_DOTFILES="${0:h}"
for script in functions path env plugins aliases zstyle zle prompt; do
for script in functions path env plugins aliases zstyle zle prompt colorscheme; do
source "$ZSH_DOTFILES/$script.zsh"
source_if_exists "$ZSH_DOTFILES/custom/$script.zsh"
done
@ -12,9 +12,6 @@ MANPATH="$MANPATH:"
command_exists rbenv && eval "$(rbenv init -)"
BASE16_SHELL_profile_helper="$BASE16_SHELL/profile_helper.sh"
[[ -n "$PS1" && -r "$BASE16_SHELL_profile_helper" ]] && eval "$("$BASE16_SHELL_profile_helper")"
setopt noclobber
welcome