From ca53077a593103ce03b178e1a2f1987ecb9a5444 Mon Sep 17 00:00:00 2001 From: David JULIEN Date: Fri, 22 Oct 2021 22:34:19 +0200 Subject: [PATCH] feat: change colorscheme, system-wide nvim: create the relevant utils switch-colors: change xcolors + nvim colorscheme -> $XDG_STATE_HOME/{xcolors,nvim_colorscheme} -> $XDG_DATA_HOME/colorschemes for correspondance sxhkd: keybindings --- .config/X11/xcolors_dark | 39 +++++++++++++++++++++++++++++ .config/X11/xcolors_light | 39 +++++++++++++++++++++++++++++ .config/X11/xprofile | 2 ++ .config/X11/xresources | 40 +++--------------------------- .config/nvim/lua/utils.lua | 18 ++++++++++++++ .config/sxhkd/sxhkdrc | 6 +++++ .local/bin/switch-colors | 50 ++++++++++++++++++++++++++++++++++++++ .local/share/colorschemes | 2 ++ 8 files changed, 159 insertions(+), 37 deletions(-) create mode 100644 .config/X11/xcolors_dark create mode 100644 .config/X11/xcolors_light create mode 100755 .local/bin/switch-colors create mode 100644 .local/share/colorschemes diff --git a/.config/X11/xcolors_dark b/.config/X11/xcolors_dark new file mode 100644 index 0000000..4ef9146 --- /dev/null +++ b/.config/X11/xcolors_dark @@ -0,0 +1,39 @@ +/* name dark light */ +/* black 0 8 */ +/* red 1 9 */ +/* green 2 10 */ +/* yellow 3 11 */ +/* blue 4 12 */ +/* purple 5 13 */ +/* cyan 6 14 */ +/* white 7 15 */ + +/* theme */ +*.color0: #131616 +*.color1: #b73935 +*.color2: #427d61 +*.color3: #f7a583 +*.color4: #458588 +*.color5: #b16286 +*.color6: #7cafa3 +*.color7: #d5c4a1 +*.color8: #373737 +*.color9: #ea6962 +*.color10: #89b594 +*.color11: #ffeca3 +*.color12: #7daea3 +*.color13: #d3869b +*.color14: #ace5d7 +*.color15: #fbf1c7 +*.background: #131616 +*.selbackground: #373737 +*.foreground: #fbf1c7 +*.normforeground: #a89984 +*.selforeground: #ebdbb2 +*.cursorColor: #ebdbb2 + +/* dmenu colors */ +dmenu.background: #131616 +dmenu.foreground: #fbf1c7 +dmenu.selbackground: #427d61 +dmenu.selforeground: #fbf1c7 diff --git a/.config/X11/xcolors_light b/.config/X11/xcolors_light new file mode 100644 index 0000000..4efad90 --- /dev/null +++ b/.config/X11/xcolors_light @@ -0,0 +1,39 @@ +/* name dark light */ +/* black 0 8 */ +/* red 1 9 */ +/* green 2 10 */ +/* yellow 3 11 */ +/* blue 4 12 */ +/* purple 5 13 */ +/* cyan 6 14 */ +/* white 7 15 */ + +/* theme */ +*.color0: #1d2021 +*.color1: #9d0006 +*.color2: #427d61 +*.color3: #d65d0e +*.color4: #076678 +*.color5: #8f3f71 +*.color6: #4a8785 +*.color7: #a89984 +*.color8: #373737 +*.color9: #b73935 +*.color10: #689d6a +*.color11: #d79921 +*.color12: #458588 +*.color13: #b16286 +*.color14: #7cafa3 +*.color15: #fbf1c7 +*.background: #fbf1c7 +*.selbackground: #ebdbb2 +*.foreground: #665c64 +*.normforeground: #665c64 +*.selforeground: #1d2021 +*.cursorColor: #1d2021 + +/* dmenu colors */ +dmenu.background: #fbf1c7 +dmenu.foreground: #665c64 +dmenu.selbackground: #427d61 +dmenu.selforeground: #fbf1c7 diff --git a/.config/X11/xprofile b/.config/X11/xprofile index c1a3f83..aa17a11 100644 --- a/.config/X11/xprofile +++ b/.config/X11/xprofile @@ -14,6 +14,8 @@ sbacklight set 3 & setbg & dwmblocks & xrdb "$XDG_CONFIG_HOME/X11/xresources" +xrdb -merge "$XDG_STATE_HOME/xcolors" +xautolock -locker slock -time 5 -corners 000- & xinput set-prop 'Synaptics TM3072-003' 'libinput Tapping Enabled' 1 & xinput set-prop 'Synaptics TM3072-003' 'libinput Natural Scrolling Enabled' 1 & diff --git a/.config/X11/xresources b/.config/X11/xresources index 46c4727..63e2d76 100644 --- a/.config/X11/xresources +++ b/.config/X11/xresources @@ -2,46 +2,12 @@ *.font: Iosevka Fixed Slab:size=12 *.symbols: Symbols Nerd Font:size=11 -/* name dark light */ -/* black 0 8 */ -/* red 1 9 */ -/* green 2 10 */ -/* yellow 3 11 */ -/* blue 4 12 */ -/* purple 5 13 */ -/* cyan 6 14 */ -/* white 7 15 */ - -/* theme */ -*.color0: #1d2021 -*.color1: #b73935 -*.color2: #5d9179 -*.color3: #f7a583 -*.color4: #458588 -*.color5: #b16286 -*.color6: #7cafa3 -*.color7: #d5c4a1 -*.color8: #373737 -*.color9: #ea6962 -*.color10: #89b482 -*.color11: #ffeca3 -*.color12: #7daea3 -*.color13: #d3869b -*.color14: #ace5d7 -*.color15: #fbf1c7 -*.background: #1d2021 -*.selbackground: #373737 -*.foreground: #fbf1c7 -*.normforeground: #a89984 -*.selforeground: #ebdbb2 -*.cursorColor: #ebdbb2 +/* dwm config */ +dwm.borderpx: 2 +dwm.gappx: 15 /* st config */ st.font: Iosevka Fixed Slab:size=14 st.symbols: Symbols Nerd Font:size=14 st.termname: st-256color st.borderpx: 5 - -/* dwm config */ -dwm.borderpx: 2 -dwm.gappx: 15 diff --git a/.config/nvim/lua/utils.lua b/.config/nvim/lua/utils.lua index 7fbb87a..e0f2e86 100644 --- a/.config/nvim/lua/utils.lua +++ b/.config/nvim/lua/utils.lua @@ -28,6 +28,24 @@ function M.map(mode, keys, action, options) vim.api.nvim_set_keymap(mode, keys, action, options) end +-- see if a file exists +function M.file_exists(file) + local f = io.open(file, "rb") + if f then f:close() end + return f ~= nil +end + +-- get all lines from a file +-- @return table (empty if the file does not exist) +function M.lines_from(file) + if not M.file_exists(file) then return {} end + local lines = {} + for line in io.lines(file) do + lines[#lines] = line + end + return lines +end + -- Make it accessible everywhere _G.utils = M -- Export the module diff --git a/.config/sxhkd/sxhkdrc b/.config/sxhkd/sxhkdrc index b5dfba8..b83d6b6 100644 --- a/.config/sxhkd/sxhkdrc +++ b/.config/sxhkd/sxhkdrc @@ -34,6 +34,12 @@ super + F9 super + shift + o dmenuopen +super + c + switch-colors + +super + shift + c + switch-colors -s + # Others super + Return $TERMINAL diff --git a/.local/bin/switch-colors b/.local/bin/switch-colors new file mode 100755 index 0000000..98e122d --- /dev/null +++ b/.local/bin/switch-colors @@ -0,0 +1,50 @@ +#!/usr/bin/env sh + +###################################################################### +# @author : swytch +# @file : switch-colors +# @license : GPLv3 +# @created : Fridat Oct. 22, 2022 23:52:53 CEST +# +# @description : switch colorscheme system-wide +###################################################################### + + +trim() { rev | cut -d'_' -f1 | rev; } + +switch_scheme() { + current="$(ls -l $XDG_CONFIG_HOME/X11/xcolors | trim)" + [ "dark" = "$current" ] && new="light" || new="dark" + select_nvim_scheme + set_scheme "$new" "$nvim_scheme" +} + +set_scheme() { + [ "" = "$new" ] && exit 1 + xcolors="$XDG_STATE_HOME/xcolors" + [ -f "$xcolors" ] && rm "$xcolors" + ln -s "$XDG_CONFIG_HOME/X11/xcolors_$new" "$xcolors" + xrdb -merge "$xcolors" && dunstify -u "low" "$new colorscheme set" + echo "$nvim_scheme" > "$XDG_STATE_HOME/nvim_colorscheme" + xrdb -merge "$xcolors" && dunstify -u "low" "neovim" "$nvim_scheme colorscheme set" +} + +select_scheme() { + new="$(ls "$XDG_CONFIG_HOME/X11" | grep -i "xcolors_" | trim | dmenu -i -l 5 -p "colorscheme:")" +} + +select_nvim_scheme() { + nvim_scheme="$(grep -i "$new" "$XDG_DATA_HOME/colorschemes" | cut -d'"' -f2 )" +} + +if [ "-s" = "$1" -o "select" = "$1" ]; then + select_scheme && select_nvim_scheme && set_scheme "$new" "$nvim_scheme" +else + if [ ! "" = "$1" ]; then + dunstify -u "normal" "Wrong parameter. Nothing performed" && exit 1 + else + switch_scheme + fi +fi + +exit 0 diff --git a/.local/share/colorschemes b/.local/share/colorschemes new file mode 100644 index 0000000..24df18f --- /dev/null +++ b/.local/share/colorschemes @@ -0,0 +1,2 @@ +"blackhole" dark +"pulsar" light