From 5ae52f1a05ead9b135300e54a90265600331cba2 Mon Sep 17 00:00:00 2001 From: gzagatti Date: Mon, 14 Feb 2022 18:22:17 +0800 Subject: [PATCH] refactors Makefile and reorganizes config into dirs for easier maintenance. --- Makefile | 114 ++++++++++-------- eclimrc | 17 --- emacs-config.org => emacs/emacs-config.org | 0 init.el => emacs/init.el | 0 essentials/R | 25 ---- essentials/julia | 27 ----- essentials/linuxbrew | 12 -- essentials/texlive | 33 ----- magictrack.conf => linux/magictrack.conf | 0 mtrack.conf => linux/mtrack.conf | 0 matplotlibrc | 1 - init.lua => nvim/init.lua | 71 +++++++---- .../conda_activate.patch | 0 rofi.rasi => rofi/confi.rasi | 0 rofi-unicodeit => rofi/unicodeit | 0 bash_profile => shells/bash_profile | 0 bashrc => shells/bashrc | 52 +++++--- inputrc => shells/inputrc | 0 tmux.conf => shells/tmux.conf | 2 +- zshrc => shells/zshrc | 65 +++++++--- Rprofile => singles/Rprofile | 0 alacritty.yml => singles/alacritty.yml | 2 +- ctags => singles/ctags | 0 gitconfig => singles/gitconfig | 0 .../jupyter_console_config.py | 0 latexmkrc => singles/latexmkrc | 0 singles/startup.jl | 19 +++ vimrc => singles/vimrc | 0 zathurarc => singles/zathurarc | 0 startup.jl | 4 - 30 files changed, 219 insertions(+), 225 deletions(-) delete mode 100644 eclimrc rename emacs-config.org => emacs/emacs-config.org (100%) rename init.el => emacs/init.el (100%) delete mode 100644 essentials/R delete mode 100644 essentials/julia delete mode 100644 essentials/linuxbrew delete mode 100644 essentials/texlive rename magictrack.conf => linux/magictrack.conf (100%) rename mtrack.conf => linux/mtrack.conf (100%) delete mode 100644 matplotlibrc rename init.lua => nvim/init.lua (92%) rename conda_activate.patch => patches/conda_activate.patch (100%) rename rofi.rasi => rofi/confi.rasi (100%) rename rofi-unicodeit => rofi/unicodeit (100%) rename bash_profile => shells/bash_profile (100%) rename bashrc => shells/bashrc (80%) rename inputrc => shells/inputrc (100%) rename tmux.conf => shells/tmux.conf (97%) rename zshrc => shells/zshrc (79%) rename Rprofile => singles/Rprofile (100%) rename alacritty.yml => singles/alacritty.yml (94%) rename ctags => singles/ctags (100%) rename gitconfig => singles/gitconfig (100%) rename jupyter_console_config.py => singles/jupyter_console_config.py (100%) rename latexmkrc => singles/latexmkrc (100%) create mode 100644 singles/startup.jl rename vimrc => singles/vimrc (100%) rename zathurarc => singles/zathurarc (100%) delete mode 100644 startup.jl diff --git a/Makefile b/Makefile index 6ae3182..b006315 100644 --- a/Makefile +++ b/Makefile @@ -3,77 +3,93 @@ workspace := $(HOME) .PHONY: all -vim: - ln -fs $(dotfiles)/vimrc $(workspace)/.vimrc -nvim: - mkdir -p $(workspace)/.config/nvim/ - ln -fs $(dotfiles)/init.lua $(workspace)/.config/nvim +# SHELLS +shells/inputrc: + ln -fs $(dotfiles)/shells/inputrc $(workspace)/.inputrc + +bash: shells/inputrc + ln -fs $(dotfiles)/shells/bash_profile $(workspace)/.bash_profile + ln -fs $(dotfiles)/shells/bashrc $(workspace)/.bashrc -emacs: - mkdir -p $(workspace)/.emacs.d/ - ln -fs $(dotfiles)/init.el $(workspace)/.emacs.d/init.el - ln -fs $(dotfiles)/emacs-config.org $(workspace)/.emacs.d/emacs-config.org +zsh: shells/inputrc + ln -fs $(dotfiles)/shells/zshrc $(workspace)/.zshrc tmux: - ln -fs $(dotfiles)/tmux.conf $(workspace)/.tmux.conf + ln -fs $(dotfiles)/shells/tmux.conf $(workspace)/.tmux.conf -bash: - ln -fs $(dotfiles)/inputrc $(workspace)/.inputrc - ln -fs $(dotfiles)/bash_profile $(workspace)/.bash_profile - ln -fs $(dotfiles)/bashrc $(workspace)/.bashrc +shells: bash zsh tmux -zsh: - ln -fs $(dotfiles)/zshrc $(workspace)/.zshrc +# NVIM +$(workspace)/.config/nvim: + mkdir -p $@ -jupyter: - mkdir -p $(workspace)/.jupyter/kernels - mkdir -p $(workspace)/.local/share/jupyter/kernels - ln -fs $(dotfiles)/jupyter_console_config.py $(workspace)/.jupyter/jupyter_console_config.py - ln -fs $(dotfiles)/jupyter_notebook_config.py $(workspace)/.jupyter/jupyter_notebook_config.py +nvim/%: $(workspace)/.config/nvim + ln -fs $(dotfiles)/$@ $lua vim.lsp.buf.declaration()', opts) - buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) - buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) + buf_set_keymap('n', 'gD', + 'lua vim.lsp.buf.declaration()', opts) + buf_set_keymap('n', 'gd', + 'lua vim.lsp.buf.definition()', opts) + buf_set_keymap('n', 'gK', + 'lua vim.lsp.buf.hover()', opts) -- variable management - buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) - buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) + buf_set_keymap('n', 'gn', + 'lua vim.lsp.buf.rename()', opts) + buf_set_keymap('n', 'gr', + 'lua vim.lsp.buf.references()', opts) -- diagnostic + buf_set_keymap('n', '[telescope]l', + 'Telescope diagnostics theme=get_ivy', opts) + local diagnostic_hidden = {} + function diagnostic_toggle(toggle_bufnr, revert) toggle_bufnr = vim.api.nvim_buf_get_number(toggle_bufnr) print("Toggle diagnostics", toggle_bufnr, diagnostic_hidden[toggle_bufnr]) @@ -474,30 +487,33 @@ require'packer'.startup {function (use) diagnostic_hidden[toggle_bufnr] = true end end - buf_set_keymap('n', 'd', 'lua diagnostic_toggle(0)', opts) - - buf_set_keymap('n', '[telescope]l', 'Telescope diagnostics theme=get_ivy', opts) + buf_set_keymap('n', 'gl', + 'lua diagnostic_toggle(0)', opts) -- formatting - buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', opts) + buf_set_keymap('n', 'gf', + 'lua vim.lsp.buf.formatting()', opts) -- language specific if(client.name == 'texlab') then - buf_set_keymap('n', 'l', 'echo \'Building file.\'TexlabBuild', {}) + buf_set_keymap('n', '', + 'echo \'Building file.\'TexlabBuild', opts) end end -- list of servers: -- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md -- to check status: :lua vim.cmd('split'..vim.lsp.get_log_path()) - lsp.html.setup { on_attach = on_attach } - lsp.julials.setup { on_attach = on_attach } - lsp.pyright.setup { on_attach = on_attach } - lsp.texlab.setup { on_attach = on_attach } - lsp.jsonls.setup { on_attach = on_attach } - lsp.sumneko_lua.setup { + local autostart = false + lspconfig.html.setup { on_attach = on_attach, autostart = autostart } + lspconfig.julials.setup { on_attach = on_attach, autostart = autostart } + lspconfig.pyright.setup { on_attach = on_attach, autostart = autostart } + lspconfig.texlab.setup { on_attach = on_attach, autostart = autostart } + lspconfig.jsonls.setup { on_attach = on_attach, autostart = autostart } + lspconfig.sumneko_lua.setup { on_attach = on_attach, + autostart = autostart, settings = { Lua = { diagnostics = { @@ -507,8 +523,9 @@ require'packer'.startup {function (use) }, }, } - lsp.solargraph.setup { + lspconfig.solargraph.setup { on_attach = on_attach, + autostart = autostart, settings = { solargraph = { diagnostic = true, @@ -516,8 +533,9 @@ require'packer'.startup {function (use) }, }, } - lsp.stylelint_lsp.setup { + lspconfig.stylelint_lsp.setup { on_attach = on_attach, + autostart = autostart, settings = { stylelintplus = { autoFixOnSave = true, @@ -887,6 +905,9 @@ require'packer'.startup {function (use) } --}}} end, + { + auto_clean = false, + } } -- turn it on for automatic sync and compilation, slows down startup @@ -906,6 +927,12 @@ vim.api.nvim_set_keymap('n', '', ':luafile $MYVIMRC:PackerSync', 'wincmd h', { noremap = true }) + vim.api.nvim_set_keymap('', '', 'wincmd j', { noremap = true }) + vim.api.nvim_set_keymap('', '', 'wincmd k', { noremap = true }) + vim.api.nvim_set_keymap('', '', 'wincmd l', { noremap = true }) +end ---}}} ---moving laterally when concealed {{{ diff --git a/conda_activate.patch b/patches/conda_activate.patch similarity index 100% rename from conda_activate.patch rename to patches/conda_activate.patch diff --git a/rofi.rasi b/rofi/confi.rasi similarity index 100% rename from rofi.rasi rename to rofi/confi.rasi diff --git a/rofi-unicodeit b/rofi/unicodeit similarity index 100% rename from rofi-unicodeit rename to rofi/unicodeit diff --git a/bash_profile b/shells/bash_profile similarity index 100% rename from bash_profile rename to shells/bash_profile diff --git a/bashrc b/shells/bashrc similarity index 80% rename from bashrc rename to shells/bashrc index eaa5f63..fc24890 100644 --- a/bashrc +++ b/shells/bashrc @@ -19,7 +19,6 @@ if [[ $- == *i* ]]; then ## PATH {{{ # add ~/.local/bin to PATH, before looking for other commands export PATH=$HOME/.local/bin:$PATH - hash -f ## }}} ## ls {{{ @@ -33,7 +32,6 @@ if [[ $- == *i* ]]; then ## brew {{{ if hash brew &>/dev/null; then export PATH=$(brew --prefix)/bin:$(brew --prefix)/sbin:$PATH - hash -f elif [ -d $HOME/.linuxbrew ]; then export HOMEBREW_PREFIX=$HOME/.linuxbrew export HOMEBREW_CELLAR=$HOME/.linuxbrew/Cellar @@ -43,7 +41,6 @@ if [[ $- == *i* ]]; then # exporting the PATH slows the initialization quite significantly, would be # good to figure an efficient way to do so. export PATH=$HOME/.linuxbrew/bin:$HOME/.linuxbrew/sbin:$PATH - hash -f fi ## }}} @@ -96,20 +93,12 @@ if [[ $- == *i* ]]; then fi ## }}} - ## slimux {{{ - # magic environments in order to make slimux work in tmux - if [ -d $HOME/.vim/plugged/slimux ]; then - case $OSTYPE in - Linux*) - export EVENT_NOEPOLL=1 - ;; - Darwin*) - export EVENT_NOKQUEUE=1 - export EVENT_NOPOLL=1 - ;; - esac + ## kitty {{{ + if test -n "$KITTY_INSTALLATION_DIR"; then + export KITTY_SHELL_INTEGRATION="enabled" + source "$KITTY_INSTALLATION_DIR/shell-integration/bash/kitty.bash" fi - ## }}} + ##}}} # }}} @@ -147,10 +136,37 @@ if [[ $- == *i* ]]; then echo "$dev_info_msg" } + function get_termbg() { + oldstty=$(stty -g) + stty raw -echo min 0 time 1 + # terminal escape sequence to get the terminal background color + # only works in xterms + # https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands + printf '\033]11;?\033\\' + sleep 0.00000001 + read -r termbg + stty $oldstty + local termbg=$(echo $termbg | sed 's/.*\(rgb:[0-9a-f/]*\).*/\1/') + if [[ $termbg == "rgb:f8f8/fbfb/f8f8" ]]; then + export THEME="leuven" + elif [[ $termbg == "rgb:2828/2a2a/3636" ]]; then + export THEME="dracula" + fi + } + export THEME="" + get_termbg function _ps1() { - local color='$(if [[ $? == 0 ]]; then echo "\[\e[00;30m\]";else echo "\[\e[00;31m\]"; fi)' + local info='[\h \u]:\W \$' - local reset_color='\[\e[0m\] \[\e[33m\]' + local color="" + local reset_color=' ' + if [[ $THEME == "leuven" ]]; then + color='$(if [[ $? == 0 ]]; then echo "\[\e[48:5:11m\]";else echo "\[\e[38:5:1m\]\[\e[48:5:9m\]"; fi)' + reset_color='\[\e[0m\] ' + elif [[ $THEME == "dracula" ]]; then + color='$(if [[ $? == 0 ]]; then echo "\[\e[00;30m\]";else echo "\[\e[00;31m\]"; fi)' + reset_color='\[\e[0m\] \[\e[33m\]' + fi printf %s "$color$(_precmd_ps1)$info$reset_color" return 0 } diff --git a/inputrc b/shells/inputrc similarity index 100% rename from inputrc rename to shells/inputrc diff --git a/tmux.conf b/shells/tmux.conf similarity index 97% rename from tmux.conf rename to shells/tmux.conf index c0759f1..d3198fa 100644 --- a/tmux.conf +++ b/shells/tmux.conf @@ -30,7 +30,7 @@ bind -n C-h if-shell "$is_editor" "send-keys C-h" "select-pane -L" bind -n C-j if-shell "$is_editor" "send-keys C-j" "select-pane -D" bind -n C-k if-shell "$is_editor" "send-keys C-k" "select-pane -U" bind -n C-l if-shell "$is_editor" "send-keys C-l" "select-pane -R" -bind -n C-\134 if-shell "$is_editor" "send-keys C-\134" "select-pane -l" +# bind -n C-\134 if-shell "$is_editor" "send-keys C-\134" "select-pane -l" # restoring clear screen bind C-l send-keys 'C-l' diff --git a/zshrc b/shells/zshrc similarity index 79% rename from zshrc rename to shells/zshrc index 5bc3e2e..813738e 100644 --- a/zshrc +++ b/shells/zshrc @@ -112,20 +112,23 @@ if [[ $- == *i* ]]; then fi ## }}} - ## slimux {{{ - # magic environments in order to make slimux work in tmux - if [ -d $HOME/.vim/plugged/slimux ]; then - case $OSTYPE in - Linux*) - export EVENT_NOEPOLL=1 - ;; - Darwin*) - export EVENT_NOKQUEUE=1 - export EVENT_NOPOLL=1 - ;; - esac + ## kitty {{{ + if test -n "$KITTY_INSTALLATION_DIR"; then + export KITTY_SHELL_INTEGRATION="enabled" + autoload -Uz -- "$KITTY_INSTALLATION_DIR"/shell-integration/zsh/kitty-integration + kitty-integration + unfunction kitty-integration + # scroll-and-clear-screen() { + # printf '\n%.0s' {1..$LINES} + # zle clear-screen + # } + # zle -N scroll-and-clear-screen + # bindkey '^[[108;6u' scroll-and-clear-screen # ctrl + shit + l + if hash emacs 2>/dev/null; then + alias emacs="TERM=xterm-emacs emacs -nw" + fi fi - ## }}} + ##}}} # }}} @@ -167,7 +170,33 @@ if [[ $- == *i* ]]; then # inspired by # https://github.com/zsh-users/zsh/blob/master/Misc/vcs_info-examples#L51 precmd_ps1() { - local color='%(?.%F{black}.%F{red})' + + # https://gist.github.com/blueyed/c8470c2aad3381c33ea3 + # https://stackoverflow.com/questions/2507337/how-to-determine-a-terminals-background-color + local oldstty=$(stty -g) + stty raw -echo min 0 time 1 + # terminal escape sequence to get the terminal background color + # only works in xterms + # https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands + printf '\033]11;?\033\\' + sleep 0.00000001 + read -r termbg + stty $oldstty + local termbg=$(echo $termbg | sed 's/.*\(rgb:[0-9a-f/]*\).*/\1/') + local theme="" + if [[ $termbg == "rgb:f8f8/fbfb/f8f8" ]]; then + theme="leuven" + elif [[ $termbg == "rgb:2828/2a2a/3636" ]]; then + theme="dracula" + fi + + # https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html#Visual-effects + color="" + if [[ $theme == "leuven" ]]; then + color='%(?.%K{11}.%K{9}%F{1})' + elif [[ $theme == "dracula" ]]; then + color='%(?.%F{black}.%F{red})' + fi local host_info_msg="[%m %n]:%1~ %#" local dev_info_msg @@ -196,7 +225,13 @@ if [[ $- == *i* ]]; then dev_info_msg="(${dev_info_msg})" fi - PS1="$color${dev_info_msg}${host_info_msg}%F{yellow} " + if [[ $theme = "leuven" ]]; then + PS1="$color${dev_info_msg}${host_info_msg}%k%f " + elif [[ $theme = "dracula" ]]; then + PS1="$color${dev_info_msg}${host_info_msg}%F{yellow} " + else + PS1="$color${dev_info_msg}${host_info_msg} " + fi } precmd_functions+=( precmd_ps1 ) diff --git a/Rprofile b/singles/Rprofile similarity index 100% rename from Rprofile rename to singles/Rprofile diff --git a/alacritty.yml b/singles/alacritty.yml similarity index 94% rename from alacritty.yml rename to singles/alacritty.yml index d75034a..c0659d6 100644 --- a/alacritty.yml +++ b/singles/alacritty.yml @@ -1,5 +1,5 @@ +# dracula theme with minor modifications colors: -# colors after the Dracula theme with minor modifications primary: background: '0x282a36' foreground: '0xbbbbbb' diff --git a/ctags b/singles/ctags similarity index 100% rename from ctags rename to singles/ctags diff --git a/gitconfig b/singles/gitconfig similarity index 100% rename from gitconfig rename to singles/gitconfig diff --git a/jupyter_console_config.py b/singles/jupyter_console_config.py similarity index 100% rename from jupyter_console_config.py rename to singles/jupyter_console_config.py diff --git a/latexmkrc b/singles/latexmkrc similarity index 100% rename from latexmkrc rename to singles/latexmkrc diff --git a/singles/startup.jl b/singles/startup.jl new file mode 100644 index 0000000..906d0f6 --- /dev/null +++ b/singles/startup.jl @@ -0,0 +1,19 @@ +import Pkg +# activate project at current path or at repo root +if isfile("Project.toml") && + isfile("Manifest.toml") + Pkg.activate(".") +else + here = splitpath(abspath(".")) + for i in length(here):-1:1 + parent = here[1:i] + if isdir(joinpath([parent; ".git"])) + if isfile(joinpath([parent; "Project.toml"])) && + isfile(joinpath([parent; "Manifest.toml"])) + Pkg.activate(joinpath(parent)) + break + end + end + if i == 1 Pkg.activate() end + end +end diff --git a/vimrc b/singles/vimrc similarity index 100% rename from vimrc rename to singles/vimrc diff --git a/zathurarc b/singles/zathurarc similarity index 100% rename from zathurarc rename to singles/zathurarc diff --git a/startup.jl b/startup.jl deleted file mode 100644 index b624538..0000000 --- a/startup.jl +++ /dev/null @@ -1,4 +0,0 @@ -using Pkg -if isfile("Project.toml") && isfile("Manifest.toml") - Pkg.activate(".") -end