From 7cd2b2dc5ee9b74b62b4876808cdf34a2978201c Mon Sep 17 00:00:00 2001 From: Asocia Date: Sat, 17 Jul 2021 16:35:37 +0300 Subject: [PATCH] Generate terminal colors properly --- .aliases | 1 - .zshrc | 16 ++++++++ scripts/misc/adjust_terminal_colors.py | 52 ++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100755 scripts/misc/adjust_terminal_colors.py diff --git a/.aliases b/.aliases index 9c8481b..8de99e0 100644 --- a/.aliases +++ b/.aliases @@ -1,4 +1,3 @@ -alias newbg="wal -i ~/Pictures/Wallpapers/Desktop/ --backend=haishoku -o ~/scripts/misc/restart_dunst.sh" alias af=alias-finder alias ls=lsd alias lt="lsd --tree" diff --git a/.zshrc b/.zshrc index 9733531..66071c4 100644 --- a/.zshrc +++ b/.zshrc @@ -107,6 +107,22 @@ function my_bindings() { 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+=(my_bindings) diff --git a/scripts/misc/adjust_terminal_colors.py b/scripts/misc/adjust_terminal_colors.py new file mode 100755 index 0000000..9080a6f --- /dev/null +++ b/scripts/misc/adjust_terminal_colors.py @@ -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)