diff --git a/theme-switcher-testing/zxcv.sh b/theme-switcher-testing/zxcv.sh new file mode 100755 index 0000000..ae0ca70 --- /dev/null +++ b/theme-switcher-testing/zxcv.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +# OMARCHY_CURRENT_THEME_NEOVIM="~/.config/omarchy/current/theme/neovim.lua" +OMARCHY_CURRENT_THEME_NEOVIM="./neovim.lua" + +if [[ ! -f "$OMARCHY_CURRENT_THEME_NEOVIM" ]]; then + echo "neovim theme not found for live update: $OMARCHY_CURRENT_THEME_NEOVIM" >&2 + exit 1 +fi + +read -r plugin_name colorscheme_name <<< "$( +nvim -l <(cat << NESTED_LUA_BLOCK +local ok, plugins = pcall(dofile, '${OMARCHY_CURRENT_THEME_NEOVIM}') +if not ok then + print('ERROR: could not load neovim theme file for live update') + os.exit(1) +end + +local first = plugins[1] +local plugin_name = (type(first.name) == 'string' and first.name) + or (type(first[1]) == 'string' and first[1]:match('.*/(.*)')) + or 'plugin_name_not_found' + +if plugin_name == 'plugin_name_not_found' then + print('ERROR: could not detect neovim theme plugin for live update') + os.exit(1) +end + +local last = plugins[#plugins] +local colorscheme = ((type(last.opts) == 'table' and type(last.opts.colorscheme) == 'string') and last.opts.colorscheme) + or plugin_name:gsub("%.%w+$", "") + +vim.print(plugin_name .. " " .. colorscheme) +NESTED_LUA_BLOCK +) > /dev/stdout 2>&1 | tr -d '\r' +)" + +nvim --headless +"lua require(\"lazy\").install({ show = false, wait = true })" +q > /dev/null 2>&1 + +nvim_stdpath_run=$(dirname $(nvim -l <(echo "vim.cmd.echo('stdpath(\"run\")')") > /dev/stdout 2>&1)) +find "$nvim_stdpath_run" -type s -name "nvim*" 2> /dev/null | +while IFS= read -r nvim_server; do + # echo "running for $nvim_server" + timeout 2s nvim --server "$nvim_server" \ + --remote-expr "execute('lua require(\"lazy\").install({ show = false, wait = true })')" \ + > /dev/null 2>&1 + timeout 4s nvim --server "$nvim_server" \ + --remote-expr "execute('lua require(\"lazy\").load({ show = false, wait = true, plugins = { \"$plugin_name\" } })')" \ + > /dev/null 2>&1 + timeout 2s nvim --server "$nvim_server" \ + --remote-expr "execute('colorscheme $colorscheme_name')" \ + > /dev/null 2>&1 + # echo "finished for $nvim_server" +done + +########################################################################################## + +# ln -snf ~/dev/git/other/omarchy/neovim.lua ~/.config/nvim/lua/plugins_lazy/colorschemes.lua +# ref only +# lua require("lazy").install({ show = false, wait = true }) +# lua require("lazy").load({ show = false, wait = true, plugins = { "nightfox.nvim" } }) +# lua require("lazy").build({ show = false, wait = true, plugins = { name = "tokyonight.nvim" } }) +# lua require("lazy").reload({ show = false, wait = true, plugins = { name = "tokyonight.nvim" } }) + +# get neovim theme file, parse as lua? load the tables and get first value in each, as well as a name if one is set +# if name is set, that is plugin name which lazy.nvim knows, if not, then take the value after the / in the git repo name + +# also, in the final table, parse out the colorscheme value, that is what needs to be passed to my loop below +# if none is present, then default to the plugin name from above, but trim off any .suffix like .nvim + +# # nvim_sockets=$(find /var/folders -type s -user "$USERNAME" -name "nvim*" -path "*nvim.$USERNAME*" 2> /dev/null) +# nvim_sockets=$(find /var/folders -type s -name "nvim*" -path "*nvim.*" 2> /dev/null) +# # for s in "${nvim_sockets[@]}"; do +# for s in $nvim_sockets; do +# echo "will run for $s" +# # nvim --server "$s" --remote-expr "execute('colorscheme $1')" +# done + +# find /var/folders -type s -name "nvim*" -path "*nvim.*" 2> /dev/null | while IFS= read -r server; do + +# nvim -l <(echo "vim.cmd.echo('stdpath(\"run\")')") > /dev/stdout 2>&1 | +# dirname $@ | +# find $@ -type s -name "nvim*" 2> /dev/null | +# while IFS= read -r server; do +# timeout 0.5s nvim --server "$server" --remote-expr "execute('colorscheme $1')" > /dev/null 2>&1 +# done