Generate terminal colors properly

This commit is contained in:
Asocia 2021-07-17 16:35:37 +03:00
parent cd205753e3
commit 7cd2b2dc5e
3 changed files with 68 additions and 1 deletions

View File

@ -1,4 +1,3 @@
alias newbg="wal -i ~/Pictures/Wallpapers/Desktop/ --backend=haishoku -o ~/scripts/misc/restart_dunst.sh"
alias af=alias-finder alias af=alias-finder
alias ls=lsd alias ls=lsd
alias lt="lsd --tree" alias lt="lsd --tree"

16
.zshrc
View File

@ -107,6 +107,22 @@ function my_bindings() {
bindkey "\e[1;3B" dirhistory_zle_dirhistory_down bindkey "\e[1;3B" dirhistory_zle_dirhistory_down
} }
chbackground() {
if [ "$3" == "" ]
then
wal -st -i ~/Pictures/Wallpapers/Desktop --backend=haishoku
python3 ~/scripts/misc/adjust_terminal_colors.py $1 $2
~/scripts/misc/restart_dunst.sh
else
python3 ~/scripts/misc/adjust_terminal_colors.py $1 $2 dummy
fi
}
chcolors() {
chbackground $1 $2 dummy
}
zvm_after_init_commands+=('[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh') zvm_after_init_commands+=('[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh')
zvm_after_init_commands+=(my_bindings) zvm_after_init_commands+=(my_bindings)

View File

@ -0,0 +1,52 @@
#!/usr/bin/env python3
import sys
import pywal
from subprocess import check_output
import json
colorspace = sys.argv[1]
fraction = sys.argv[2]
generate_from_old_colors = len(sys.argv) == 4
# get current color scheme
if generate_from_old_colors:
generated_colors = pywal.colors.file("/home/sahin/.cache/wal/.old_colors.json")
else:
generated_colors = pywal.colors.file("/home/sahin/.cache/wal/colors.json")
reference_colors = ['black', 'red', 'green', 'yellow', 'blue' , 'magenta', 'cyan', 'white']
with open("/home/sahin/.cache/wal/.old_colors.json", 'w') as f:
json.dump(generated_colors, f)
# we will only use first 8 colors in the terminal
terminal_colors = list(generated_colors['colors'].items())[:8]
for (name, t), ref in zip(terminal_colors, reference_colors):
command = f"pastel mix {t[1:]} {ref} "\
f"--colorspace={colorspace} "\
f"--fraction={fraction} | pastel format"
generated_colors['colors'][name] = check_output(command,
shell=True).decode('utf8').strip()
# generated_colors['special']['background'] = generated_colors['colors']['color0']
# generated_colors['special']['foreground'] = generated_colors['colors']['color7']
# generated_colors['special']['cursor'] = generated_colors['colors']['color7']
# print(colors)
# image = generated_colors["wallpaper"]
# Apply the palette to all open terminals.
# Second argument is a boolean for VTE terminals.
# Set it to true if the terminal you're using is
# VTE based. (xfce4-terminal, termite, gnome-terminal.)
pywal.sequences.send(generated_colors)
# Export all template files.
pywal.export.every(generated_colors)
# Reload xrdb, i3 and polybar.
# pywal.reload.env()
# Set the wallpaper.
# pywal.wallpaper.change(image)