diff --git a/.config/aerospace/aerospace.toml b/.config/aerospace/aerospace.toml index 3d13464..303645d 100644 --- a/.config/aerospace/aerospace.toml +++ b/.config/aerospace/aerospace.toml @@ -60,10 +60,6 @@ run = 'layout floating' if.app-id = 'org.chromium.Chromium' run = 'layout floating' -[[on-window-detected]] -if.app-id = 'org.wireshark.Wireshark' -run = 'layout tiling' - [mode.service.binding] u = ['reload-config', 'mode main'] diff --git a/.config/fish/config.fish b/.config/fish/config.fish index 74b509b..c6d3d9e 100644 --- a/.config/fish/config.fish +++ b/.config/fish/config.fish @@ -16,7 +16,6 @@ set -x GOBIN "$GOPATH/bin" if test (uname) = "Darwin" set -x JAVA_HOME (eval /usr/libexec/java_home) set -x GEM_HOME "$HOME/.gem" - set -x GOROOT "$(brew --prefix golang)/libexec" fish_add_path /opt/homebrew/bin fish_add_path /opt/homebrew/opt/texlive/bin fish_add_path $GEM_HOME/bin @@ -40,7 +39,7 @@ end if status is-interactive if not set -q TMUX - tmux new-session -A -s 0 + tmux new-session -A -s 0 end set -g fish_greeting diff --git a/.config/ghostty/config b/.config/ghostty/config index 3114a3f..f3dd0b4 100644 --- a/.config/ghostty/config +++ b/.config/ghostty/config @@ -1,5 +1,5 @@ # Theme -theme = dark:GruvboxDarkHard,light:AtomOneLight +theme = GruvboxDarkHard # Font font-family = IosevkaDT Nerd Font @@ -13,5 +13,6 @@ font-feature = -dlig window-padding-color = background macos-titlebar-style = hidden -quit-after-last-window-closed = true +term = "xterm-256color" + auto-update = download diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 28c35ba..8abd31c 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -2,4 +2,5 @@ require("core.variables") require("core.keymaps") require("core.autocmds") require('core.package_manager') +require('core.theme') require('winbar') diff --git a/.config/nvim/lua/core/autocmds.lua b/.config/nvim/lua/core/autocmds.lua index 06e91b7..4672b9e 100644 --- a/.config/nvim/lua/core/autocmds.lua +++ b/.config/nvim/lua/core/autocmds.lua @@ -1,8 +1,8 @@ vim.api.nvim_create_autocmd("VimLeavePre", { - pattern = "*", - callback = function() - if vim.g.savesession then - vim.api.nvim_command("mks! .session.vim") - end + pattern = "*", + callback = function() + if vim.g.savesession then + vim.api.nvim_command("mks! .session.vim") end + end }) diff --git a/.config/nvim/lua/core/theme.lua b/.config/nvim/lua/core/theme.lua new file mode 100644 index 0000000..5f9b030 --- /dev/null +++ b/.config/nvim/lua/core/theme.lua @@ -0,0 +1,6 @@ +vim.g.gruvbox_material_better_performance=1 +vim.g.gruvbox_material_background="hard" +vim.g.gruvbox_material_foreground="original" +vim.g.gruvbox_material_transparent_background=2 +vim.opt.background="dark" +vim.cmd('colorscheme gruvbox-material') diff --git a/.config/nvim/lua/core/variables.lua b/.config/nvim/lua/core/variables.lua index 522ed6e..d779a35 100644 --- a/.config/nvim/lua/core/variables.lua +++ b/.config/nvim/lua/core/variables.lua @@ -9,7 +9,7 @@ vim.opt.wrap = false -- Disable line wrapping vim.opt.conceallevel = 2 -- Hide Org mode links (assuming you use Org mode) vim.opt.concealcursor = 'nc' -- Conceal text in normal mode only vim.opt.signcolumn = "yes" -- Always show the sign column -vim.o.laststatus = 1 -- Always show the status line +vim.o.laststatus = 1 -- Always show the status line (Note: original had '1', consider '2' for always visible) vim.o.winborder = nil -- Use default border for floating windows -- Indentation @@ -38,4 +38,4 @@ vim.opt.autoread = true -- Automatically vim.opt.swapfile = false -- Disable swap files -- Formatting -vim.opt.formatoptions:remove("ro") -- Remove 'ro' from formatoptions +vim.opt.formatoptions:remove("ro") -- Remove 'ro' from formatoptions (assuming you don't want auto-wrapping comments) diff --git a/.config/nvim/lua/plugins/colorscheme.lua b/.config/nvim/lua/plugins/colorscheme.lua index cefdf10..147eea0 100644 --- a/.config/nvim/lua/plugins/colorscheme.lua +++ b/.config/nvim/lua/plugins/colorscheme.lua @@ -10,9 +10,5 @@ return { priority = 1000 }, { "blazkowolf/gruber-darker.nvim" }, - { "sainnhe/everforest" }, - { - "navarasu/onedark.nvim", - priority = 1000, - } + { "sainnhe/everforest" } } diff --git a/.config/nvim/lua/plugins/lsp.lua b/.config/nvim/lua/plugins/lsp.lua index a42bce5..91d031c 100644 --- a/.config/nvim/lua/plugins/lsp.lua +++ b/.config/nvim/lua/plugins/lsp.lua @@ -19,28 +19,28 @@ return { event = "VeryLazy", opts = {} }, - -- { - -- "ray-x/go.nvim", - -- dependencies = { - -- "ray-x/guihua.lua", - -- "neovim/nvim-lspconfig", - -- "nvim-treesitter/nvim-treesitter", - -- }, - -- config = function(lp, opts) - -- require("go").setup(opts) - -- local format_sync_grp = vim.api.nvim_create_augroup("GoFormat", {}) - -- vim.api.nvim_create_autocmd("BufWritePre", { - -- pattern = "*.go", - -- callback = function() - -- require('go.format').goimports() - -- end, - -- group = format_sync_grp, - -- }) - -- end, - -- event = { "CmdlineEnter" }, - -- ft = { "go", 'gomod' }, - -- build = ':lua require("go.install").update_all_sync()' - -- }, + { + "ray-x/go.nvim", + dependencies = { + "ray-x/guihua.lua", + "neovim/nvim-lspconfig", + "nvim-treesitter/nvim-treesitter", + }, + config = function(lp, opts) + require("go").setup(opts) + local format_sync_grp = vim.api.nvim_create_augroup("GoFormat", {}) + vim.api.nvim_create_autocmd("BufWritePre", { + pattern = "*.go", + callback = function() + require('go.format').goimports() + end, + group = format_sync_grp, + }) + end, + event = { "CmdlineEnter" }, + ft = { "go", 'gomod' }, + build = ':lua require("go.install").update_all_sync()' + }, { "neovim/nvim-lspconfig", dependencies = { @@ -115,14 +115,10 @@ return { assignVariablesTypes = true, compositeLiteralFields = true, compositeLiteralTypes = true, - completeUnimported = true, constantValues = true, functionTypeParameters = true, parameterNames = true, - rangeVariableTypes = true, - analyses = { - unusedparams = true, - } + rangeVariableTypes = true }, } } @@ -169,9 +165,6 @@ return { lspconfig["pyright"].setup({ capabilities = capabilities, }) - lspconfig["sourcekit"].setup({ - capabilities = capabilities, - }) end, }, { @@ -179,12 +172,6 @@ return { version = '^5', lazy = false }, - { - "leoluz/nvim-dap-go", - ft = "go", - dependencies = "mfussenegger/nvim-dap", - opts = {} - }, { "rcarriga/nvim-dap-ui", event = "VeryLazy", diff --git a/.config/nvim/lua/plugins/misc.lua b/.config/nvim/lua/plugins/misc.lua index f7cac5e..b6c9899 100644 --- a/.config/nvim/lua/plugins/misc.lua +++ b/.config/nvim/lua/plugins/misc.lua @@ -47,27 +47,9 @@ return { end }, "tpope/vim-fugitive", - { - 'codethread/qmk.nvim', - config = function() - ---@type qmk.UserConfig - local conf = { - name = 'LAYOUT_lily58_pro', - variant = 'zmk', - layout = { - 'x x x x x x _ _ _ _ x x x x x x', - 'x x x x x x _ _ _ _ x x x x x x', - 'x x x x x x _ _ _ _ x x x x x x', - 'x x x x x x x _ _ x x x x x x x', - '_ _ _ x x x x _ _ x x x x _ _ _', - } - } - require('qmk').setup(conf) - end - }, { "afonsofrancof/worktrees.nvim", - dev = false, + dev = true, event = "VeryLazy", opts = { mappings = { @@ -76,29 +58,5 @@ return { switch = "wts", } } - }, - { - "afonsofrancof/osc11.nvim", - dev = false, - dependencies = { - "navarasu/onedark.nvim", - }, - opts = { - on_dark = function() - vim.g.gruvbox_material_better_performance = 1 - vim.g.gruvbox_material_background = "hard" - vim.g.gruvbox_material_foreground = "original" - vim.g.gruvbox_material_transparent_background = 2 - vim.opt.background = "dark" - vim.cmd('colorscheme gruvbox-material') - end, - on_light = function() - require('onedark').setup { - style = 'light' - } - -- Enable theme - require('onedark').load() - end, - } } } diff --git a/.config/nvim/lua/plugins/treesitter.lua b/.config/nvim/lua/plugins/treesitter.lua index 931acd9..6001626 100644 --- a/.config/nvim/lua/plugins/treesitter.lua +++ b/.config/nvim/lua/plugins/treesitter.lua @@ -53,5 +53,4 @@ return { }) end }, - "kyoh86/vim-jsonl" } diff --git a/.config/tmux/tmux.conf b/.config/tmux/tmux.conf index 8b26814..8792039 100644 --- a/.config/tmux/tmux.conf +++ b/.config/tmux/tmux.conf @@ -2,10 +2,9 @@ # General set -g default-terminal "tmux-256color" -set -ag terminal-overrides ",$TERM:Tc" -set -sa terminal-features ",*:RGB" -set -g allow-passthrough on +set -gq allow-passthrough on set -g visual-activity off +set -sa terminal-features ",*:RGB" set -sg escape-time 0 set -g mouse on set -g base-index 1 @@ -21,11 +20,17 @@ set -g status-right "" set -g status-left-length 20 set -g status-position top set -g status-justify left +set -g status-style 'bg=#181926 fg=#cad3f5' set -g status-left '[#S] ' -set -g status-style 'bg=default,fg=default' +set -g status-style ' #[bg=#{status-bg},fg=#{@unfocused-fg}]' set -g window-status-format ' #I:#W ' -set -g window-status-current-format '#[bg=default,fg=default,reverse] #I:#W ' +set -g window-status-current-format '#[bg=#{@focused-bg},fg=#{@focused-fg}] #I:#W ' +# Theme +set -g status-bg "#1d2021" +set -g @unfocused-fg "#ebdbb2" +set -g @focused-bg "#ebdbb2" +set -g @focused-fg "#1d2021" # Plugins set -g @plugin 'tmux-plugins/tpm' diff --git a/.config/zsh/.zshenv b/.config/zsh/.zshenv index f1e0b42..70c01e0 100644 --- a/.config/zsh/.zshenv +++ b/.config/zsh/.zshenv @@ -30,16 +30,16 @@ function append_path() { eval export $1="$p:$2" } +export EDITOR=nvim +export VISUAL=nvim +export READER=mupdf + export XDG_CONFIG_HOME="${HOME}/.config" export XDG_CACHE_HOME="${HOME}/.cache" export XDG_DATA_HOME="${HOME}/.local/share" export XDG_STATE_HOME="${HOME}/.local/state" export XDG_RUNTIME_DIR=/tmp -export EDITOR=nvim -export VISUAL=nvim -export READER=mupdf - export GOPATH="$HOME/go" export GOBIN="$GOPATH/bin" @@ -47,13 +47,12 @@ export GOBIN="$GOPATH/bin" if [[ $(uname) == "Darwin" ]]; then export JAVA_HOME=$(/usr/libexec/java_home) export GEM_HOME=$HOME/.gem - export GOROOT=$(brew --prefix golang)/libexec prepend_path PATH "/opt/homebrew/bin" prepend_path PATH "/opt/homebrew/opt/texlive/bin" append_path PATH $GEM_HOME/bin fi -# Common Paths +#BOTH append_path PATH "/usr/sbin:/sbin" append_path PATH "$HOME/.local/share/nvim/mason/bin" append_path PATH "$HOME/.local/bin" diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index 602150e..7ab6c78 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -1,18 +1,12 @@ -if [[ -o interactive ]]; then - if [[ -z "$TMUX" ]]; then - tmux new-session -A -s 0 - fi +if [[ -z "$TMUX" ]]; then + tmux new-session -A -s 0 fi source $ZDOTDIR/setup-history.zsh source $ZDOTDIR/prompts/simple-two-line.zsh source $ZDOTDIR/functions.zsh source $ZDOTDIR/plugins.zsh -source $ZDOTDIR/theme.zsh if [[ $(uname) == "Darwin" ]]; then eval "$(/opt/homebrew/bin/brew shellenv)" fi - -eval "$(atuin init zsh --disable-up-arrow)" - diff --git a/.config/zsh/plugins.zsh b/.config/zsh/plugins.zsh index 34e618d..ffb35ea 100644 --- a/.config/zsh/plugins.zsh +++ b/.config/zsh/plugins.zsh @@ -11,8 +11,11 @@ source $ZDOTDIR/plugins/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh source $ZDOTDIR/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh # Fzf-Tab +zvm_after_init_commands+=('source <(fzf --zsh) && enable-fzf-tab') source $ZDOTDIR/plugins/fzf-tab/fzf-tab.plugin.zsh -enable-fzf-tab + +# Vi mode +source $ZDOTDIR/plugins/zsh-vi-mode/zsh-vi-mode.plugin.zsh # MacOS source $ZDOTDIR/plugins/zsh-macos.plugin.zsh diff --git a/.config/zsh/plugins/zsh-git.plugin.zsh b/.config/zsh/plugins/zsh-git.plugin.zsh new file mode 100644 index 0000000..3452f14 --- /dev/null +++ b/.config/zsh/plugins/zsh-git.plugin.zsh @@ -0,0 +1,258 @@ +# Git version checking +autoload -Uz is-at-least +git_version="${${(As: :)$(git version 2>/dev/null)}[3]}" + +# +# Functions Current +# (sorted alphabetically by function name) +# (order should follow README) +# + +# The name of the current branch +# Back-compatibility wrapper for when this function was defined here in +# the plugin, before being pulled in to core lib/git.zsh as git_current_branch() +# to fix the core -> git plugin dependency. +function current_branch() { + git_current_branch +} + +# Check for develop and similarly named branches +function git_develop_branch() { + command git rev-parse --git-dir &>/dev/null || return + local branch + for branch in dev devel develop development; do + if command git show-ref -q --verify refs/heads/$branch; then + echo $branch + return 0 + fi + done + + echo develop + return 1 +} + +# Check if main exists and use instead of master +function git_main_branch() { + command git rev-parse --git-dir &>/dev/null || return + local ref + for ref in refs/{heads,remotes/{origin,upstream}}/{main,trunk,mainline,default,stable,master}; do + if command git show-ref -q --verify $ref; then + echo ${ref:t} + return 0 + fi + done + + # If no main branch was found, fall back to master but return error + echo master + return 1 +} + +function grename() { + if [[ -z "$1" || -z "$2" ]]; then + echo "Usage: $0 old_branch new_branch" + return 1 + fi + + # Rename branch locally + git branch -m "$1" "$2" + # Rename branch in origin remote + if git push origin :"$1"; then + git push --set-upstream origin "$2" + fi +} + +# +# Functions Work in Progress (WIP) +# (sorted alphabetically by function name) +# (order should follow README) +# + +# Similar to `gunwip` but recursive "Unwips" all recent `--wip--` commits not just the last one +function gunwipall() { + local _commit=$(git log --grep='--wip--' --invert-grep --max-count=1 --format=format:%H) + + # Check if a commit without "--wip--" was found and it's not the same as HEAD + if [[ "$_commit" != "$(git rev-parse HEAD)" ]]; then + git reset $_commit || return 1 + fi +} + +# Warn if the current branch is a WIP +function work_in_progress() { + command git -c log.showSignature=false log -n 1 2>/dev/null | grep -q -- "--wip--" && echo "WIP!!" +} + +# +# Aliases +# (sorted alphabetically by command) +# (order should follow README) +# (in some cases force the alisas order to match README, like for example gke and gk) +# + +alias grt='cd "$(git rev-parse --show-toplevel || echo .)"' + +function ggpnp() { + if [[ "$#" == 0 ]]; then + ggl && ggp + else + ggl "${*}" && ggp "${*}" + fi +} +compdef _git ggpnp=git-checkout + +alias ggpur='ggu' +alias g='git' +alias gaa='git add --all' +alias gb='git branch' +alias gbd='git branch --delete' + +function gbda() { + git branch --no-color --merged | command grep -vE "^([+*]|\s*($(git_main_branch)|$(git_develop_branch))\s*$)" | command xargs git branch --delete 2>/dev/null +} + +# Copied and modified from James Roeder (jmaroeder) under MIT License +# https://github.com/jmaroeder/plugin-git/blob/216723ef4f9e8dde399661c39c80bdf73f4076c4/functions/gbda.fish +function gbds() { + local default_branch=$(git_main_branch) + (( ! $? )) || default_branch=$(git_develop_branch) + + git for-each-ref refs/heads/ "--format=%(refname:short)" | \ + while read branch; do + local merge_base=$(git merge-base $default_branch $branch) + if [[ $(git cherry $default_branch $(git commit-tree $(git rev-parse $branch\^{tree}) -p $merge_base -m _)) = -* ]]; then + git branch -D $branch + fi + done +} + +alias gcb='git checkout -b' +alias gcm='git checkout $(git_main_branch)' +alias gcl='git clone --recurse-submodules' + +function gccd() { + setopt localoptions extendedglob + + # get repo URI from args based on valid formats: https://git-scm.com/docs/git-clone#URLS + local repo="${${@[(r)(ssh://*|git://*|ftp(s)#://*|http(s)#://*|*@*)(.git/#)#]}:-$_}" + + # clone repository and exit if it fails + command git clone --recurse-submodules "$@" || return + + # if last arg passed was a directory, that's where the repo was cloned + # otherwise parse the repo URI and use the last part as the directory + [[ -d "$_" ]] && cd "$_" || cd "${${repo:t}%.git/#}" +} +compdef _git gccd=git-clone + +alias gcam='git commit --all --message' +alias gd='git diff' + +function gdv() { git diff -w "$@" | view - } +compdef _git gdv=git-diff + +alias gdup='git diff @{upstream}' + +function gdnolock() { + git diff "$@" ":(exclude)package-lock.json" ":(exclude)*.lock" +} +compdef _git gdnolock=git-diff + +alias gf='git fetch' +alias glol='git log --graph --pretty="%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset"' + +# Pretty log messages +function _git_log_prettily(){ + if ! [ -z $1 ]; then + git log --pretty=$1 + fi +} +compdef _git _git_log_prettily=git-log + +alias gm='git merge' +alias gma='git merge --abort' + +alias gl='git pull' + +function ggu() { + [[ "$#" != 1 ]] && local b="$(git_current_branch)" + git pull --rebase origin "${b:=$1}" +} +compdef _git ggu=git-checkout + +alias ggpull='git pull origin "$(git_current_branch)"' + +function ggl() { + if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then + git pull origin "${*}" + else + [[ "$#" == 0 ]] && local b="$(git_current_branch)" + git pull origin "${b:=$1}" + fi +} +compdef _git ggl=git-checkout + +alias gp='git push' + +function ggf() { + [[ "$#" != 1 ]] && local b="$(git_current_branch)" + git push --force origin "${b:=$1}" +} +compdef _git ggf=git-checkout + +alias gpf!='git push --force' +is-at-least 2.30 "$git_version" \ + && alias gpf='git push --force-with-lease --force-if-includes' \ + || alias gpf='git push --force-with-lease' + +function ggfl() { + [[ "$#" != 1 ]] && local b="$(git_current_branch)" + git push --force-with-lease origin "${b:=$1}" +} +compdef _git ggfl=git-checkout + +alias ggpush='git push origin "$(git_current_branch)"' + +function ggp() { + if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then + git push origin "${*}" + else + [[ "$#" == 0 ]] && local b="$(git_current_branch)" + git push origin "${b:=$1}" + fi +} +compdef _git ggp=git-checkout + +alias gpu='git push upstream' +alias gra='git remote add' +alias grhh='git reset --hard' +alias gpristine='git reset --hard && git clean --force -dfx' +alias grm='git rm' +alias gsps='git show --pretty=short --show-signature' +alias gst='git status' +alias gsw='git switch' + +function gcpr(){ + git fetch -fu upstream refs/pull/$1/head:pr/$1 + git checkout pr/$1 +} + +unset git_version + +# Logic for adding warnings on deprecated aliases +local old_alias new_alias +for old_alias new_alias ( + # TODO(2023-10-19): remove deprecated `git pull --rebase` aliases + gup gpr + gupv gprv + gupa gpra + gupav gprav + gupom gprom + gupomi gpromi +); do + aliases[$old_alias]=" + print -Pu2 \"%F{yellow}[oh-my-zsh] '%F{red}${old_alias}%F{yellow}' is a deprecated alias, using '%F{green}${new_alias}%F{yellow}' instead.%f\" + $new_alias" +done +unset old_alias new_alias + + diff --git a/.config/zsh/plugins/zsh-history-substring-search b/.config/zsh/plugins/zsh-history-substring-search new file mode 160000 index 0000000..87ce96b --- /dev/null +++ b/.config/zsh/plugins/zsh-history-substring-search @@ -0,0 +1 @@ +Subproject commit 87ce96b1862928d84b1afe7c173316614b30e301 diff --git a/.config/zsh/plugins/zsh-sudo.plugin.zsh b/.config/zsh/plugins/zsh-sudo.plugin.zsh new file mode 100644 index 0000000..66b253f --- /dev/null +++ b/.config/zsh/plugins/zsh-sudo.plugin.zsh @@ -0,0 +1,108 @@ +# ------------------------------------------------------------------------------ +# Description +# ----------- +# +# sudo or sudo -e (replacement for sudoedit) will be inserted before the command +# +# ------------------------------------------------------------------------------ +# Authors +# ------- +# +# * Dongweiming +# * Subhaditya Nath +# * Marc Cornellà +# * Carlo Sala +# +# ------------------------------------------------------------------------------ + +__sudo-replace-buffer() { + local old=$1 new=$2 space=${2:+ } + + # if the cursor is positioned in the $old part of the text, make + # the substitution and leave the cursor after the $new text + if [[ $CURSOR -le ${#old} ]]; then + BUFFER="${new}${space}${BUFFER#$old }" + CURSOR=${#new} + # otherwise just replace $old with $new in the text before the cursor + else + LBUFFER="${new}${space}${LBUFFER#$old }" + fi +} + +sudo-command-line() { + # If line is empty, get the last run command from history + [[ -z $BUFFER ]] && LBUFFER="$(fc -ln -1)" + + # Save beginning space + local WHITESPACE="" + if [[ ${LBUFFER:0:1} = " " ]]; then + WHITESPACE=" " + LBUFFER="${LBUFFER:1}" + fi + + { + # If $SUDO_EDITOR or $VISUAL are defined, then use that as $EDITOR + # Else use the default $EDITOR + local EDITOR=${SUDO_EDITOR:-${VISUAL:-$EDITOR}} + + # If $EDITOR is not set, just toggle the sudo prefix on and off + if [[ -z "$EDITOR" ]]; then + case "$BUFFER" in + sudo\ -e\ *) __sudo-replace-buffer "sudo -e" "" ;; + sudo\ *) __sudo-replace-buffer "sudo" "" ;; + *) LBUFFER="sudo $LBUFFER" ;; + esac + return + fi + + # Check if the typed command is really an alias to $EDITOR + + # Get the first part of the typed command + local cmd="${${(Az)BUFFER}[1]}" + # Get the first part of the alias of the same name as $cmd, or $cmd if no alias matches + local realcmd="${${(Az)aliases[$cmd]}[1]:-$cmd}" + # Get the first part of the $EDITOR command ($EDITOR may have arguments after it) + local editorcmd="${${(Az)EDITOR}[1]}" + + # Note: ${var:c} makes a $PATH search and expands $var to the full path + # The if condition is met when: + # - $realcmd is '$EDITOR' + # - $realcmd is "cmd" and $EDITOR is "cmd" + # - $realcmd is "cmd" and $EDITOR is "cmd --with --arguments" + # - $realcmd is "/path/to/cmd" and $EDITOR is "cmd" + # - $realcmd is "/path/to/cmd" and $EDITOR is "/path/to/cmd" + # or + # - $realcmd is "cmd" and $EDITOR is "cmd" + # - $realcmd is "cmd" and $EDITOR is "/path/to/cmd" + # or + # - $realcmd is "cmd" and $EDITOR is /alternative/path/to/cmd that appears in $PATH + if [[ "$realcmd" = (\$EDITOR|$editorcmd|${editorcmd:c}) \ + || "${realcmd:c}" = ($editorcmd|${editorcmd:c}) ]] \ + || builtin which -a "$realcmd" | command grep -Fx -q "$editorcmd"; then + __sudo-replace-buffer "$cmd" "sudo -e" + return + fi + + # Check for editor commands in the typed command and replace accordingly + case "$BUFFER" in + $editorcmd\ *) __sudo-replace-buffer "$editorcmd" "sudo -e" ;; + \$EDITOR\ *) __sudo-replace-buffer '$EDITOR' "sudo -e" ;; + sudo\ -e\ *) __sudo-replace-buffer "sudo -e" "$EDITOR" ;; + sudo\ *) __sudo-replace-buffer "sudo" "" ;; + *) LBUFFER="sudo $LBUFFER" ;; + esac + } always { + # Preserve beginning space + LBUFFER="${WHITESPACE}${LBUFFER}" + + # Redisplay edit buffer (compatibility with zsh-syntax-highlighting) + zle && zle redisplay # only run redisplay if zle is enabled + } +} + +zle -N sudo-command-line + +# Defined shortcut keys: [Esc] [Esc] +bindkey -M emacs '\e\e' sudo-command-line +bindkey -M vicmd '\e\e' sudo-command-line +bindkey -M viins '\e\e' sudo-command-line diff --git a/.config/zsh/plugins/zsh-tmux/tmux.extra.conf b/.config/zsh/plugins/zsh-tmux/tmux.extra.conf new file mode 100644 index 0000000..b480373 --- /dev/null +++ b/.config/zsh/plugins/zsh-tmux/tmux.extra.conf @@ -0,0 +1,2 @@ +set -g default-terminal $ZSH_TMUX_TERM +source-file $ZSH_TMUX_CONFIG diff --git a/.config/zsh/plugins/zsh-tmux/tmux.only.conf b/.config/zsh/plugins/zsh-tmux/tmux.only.conf new file mode 100644 index 0000000..0734df3 --- /dev/null +++ b/.config/zsh/plugins/zsh-tmux/tmux.only.conf @@ -0,0 +1 @@ +set -g default-terminal $ZSH_TMUX_TERM diff --git a/.config/zsh/plugins/zsh-tmux/zsh-tmux.plugin.zsh b/.config/zsh/plugins/zsh-tmux/zsh-tmux.plugin.zsh new file mode 100644 index 0000000..1050e52 --- /dev/null +++ b/.config/zsh/plugins/zsh-tmux/zsh-tmux.plugin.zsh @@ -0,0 +1,190 @@ +if ! (( $+commands[tmux] )); then + print "zsh tmux plugin: tmux not found. Please install tmux before using this plugin." >&2 + return 1 +fi + +# CONFIGURATION VARIABLES +# Automatically start tmux +if [[ ! $(tty) =~ ^/dev/tty[0-9]*$ ]]; then + : ${ZSH_TMUX_AUTOSTART:=true} +else + : ${ZSH_TMUX_AUTOSTART:=false} +fi +# Only autostart once. If set to false, tmux will attempt to +# autostart every time your zsh configs are reloaded. +: ${ZSH_TMUX_AUTOSTART_ONCE:=true} +# Automatically connect to a previous session if it exists +: ${ZSH_TMUX_AUTOCONNECT:=true} +# Automatically close the terminal when tmux exits +: ${ZSH_TMUX_AUTOQUIT:=false} +# Automatically name the new session based on the basename of PWD +: ${ZSH_TMUX_AUTONAME_SESSION:=false} +# Set term to screen or screen-256color based on current terminal support +: ${ZSH_TMUX_DETACHED:=false} +# Set detached mode +: ${ZSH_TMUX_FIXTERM:=true} +# Set '-CC' option for iTerm2 tmux integration +: ${ZSH_TMUX_ITERM2:=false} +# The TERM to use for non-256 color terminals. +# Tmux states this should be tmux|screen, but you may need to change it on +# systems without the proper terminfo +if [[ -e /usr/share/terminfo/t/tmux ]]; then + : ${ZSH_TMUX_FIXTERM_WITHOUT_256COLOR:=tmux} +else + : ${ZSH_TMUX_FIXTERM_WITHOUT_256COLOR:=screen} +fi +# The TERM to use for 256 color terminals. +# Tmux states this should be (tmux|screen)-256color, but you may need to change it on +# systems without the proper terminfo +if [[ -e /usr/share/terminfo/t/tmux-256color ]]; then + : ${ZSH_TMUX_FIXTERM_WITH_256COLOR:=tmux-256color} +else + : ${ZSH_TMUX_FIXTERM_WITH_256COLOR:=screen-256color} +fi +# Set the configuration path +if [[ -e $HOME/.tmux.conf ]]; then + : ${ZSH_TMUX_CONFIG:=$HOME/.tmux.conf} +elif [[ -e ${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf ]]; then + : ${ZSH_TMUX_CONFIG:=${XDG_CONFIG_HOME:-$HOME/.config}/tmux/tmux.conf} +else + : ${ZSH_TMUX_CONFIG:=$HOME/.tmux.conf} +fi +# Set -u option to support unicode +: ${ZSH_TMUX_UNICODE:=false} + +# ALIASES +function _build_tmux_alias { + setopt localoptions no_rc_expand_param + eval "function $1 { + if [[ -z \$1 ]] || [[ \${1:0:1} == '-' ]]; then + tmux $2 \"\$@\" + else + tmux $2 $3 \"\$@\" + fi + }" + + local f s + f="_omz_tmux_alias_${1}" + s=(${(z)2}) + + eval "function ${f}() { + shift words; + words=(tmux ${@:2} \$words); + ((CURRENT+=${#s[@]}+1)) + _tmux + }" + + compdef "$f" "$1" +} + +alias tksv='tmux kill-server' +alias tl='tmux list-sessions' +alias tmuxconf='$EDITOR $ZSH_TMUX_CONFIG' + +_build_tmux_alias "ta" "attach" "-t" +_build_tmux_alias "tad" "attach -d" "-t" +_build_tmux_alias "ts" "new-session" "-s" +_build_tmux_alias "tkss" "kill-session" "-t" + +unfunction _build_tmux_alias + +# Determine if the terminal supports 256 colors +if [[ $terminfo[colors] == 256 ]]; then + export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITH_256COLOR +else + export ZSH_TMUX_TERM=$ZSH_TMUX_FIXTERM_WITHOUT_256COLOR +fi + +# Handle $0 according to the standard: +# https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html +0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}" +0="${${(M)0:#/*}:-$PWD/$0}" + +# Set the correct local config file to use. +if [[ "$ZSH_TMUX_ITERM2" == "false" && -e "$ZSH_TMUX_CONFIG" ]]; then + export ZSH_TMUX_CONFIG + export _ZSH_TMUX_FIXED_CONFIG="${0:h:a}/tmux.extra.conf" +else + export _ZSH_TMUX_FIXED_CONFIG="${0:h:a}/tmux.only.conf" +fi + +# Wrapper function for tmux. +function _zsh_tmux_plugin_run() { + if [[ -n "$@" ]]; then + command tmux "$@" + return $? + fi + + local -a tmux_cmd + tmux_cmd=(command tmux) + [[ "$ZSH_TMUX_ITERM2" == "true" ]] && tmux_cmd+=(-CC) + [[ "$ZSH_TMUX_UNICODE" == "true" ]] && tmux_cmd+=(-u) + + local _detached="" + [[ "$ZSH_TMUX_DETACHED" == "true" ]] && _detached="-d" + + local session_name + if [[ "$ZSH_TMUX_AUTONAME_SESSION" == "true" ]]; then + # Name the session after the basename of the current directory + session_name=${PWD##*/} + # If the current directory is the home directory, name it 'HOME' + [[ "$PWD" == "$HOME" ]] && session_name="HOME" + # If the current directory is the root directory, name it 'ROOT' + [[ "$PWD" == "/" ]] && session_name="ROOT" + else + session_name="$ZSH_TMUX_DEFAULT_SESSION_NAME" + fi + + # Try to connect to an existing session. + if [[ -n "$session_name" ]]; then + [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach $_detached -t "$session_name" + else + [[ "$ZSH_TMUX_AUTOCONNECT" == "true" ]] && $tmux_cmd attach $_detached + fi + + # If failed, just run tmux, fixing the TERM variable if requested. + if [[ $? -ne 0 ]]; then + if [[ "$ZSH_TMUX_FIXTERM" == "true" ]]; then + tmux_cmd+=(-f "$_ZSH_TMUX_FIXED_CONFIG") + elif [[ -e "$ZSH_TMUX_CONFIG" ]]; then + tmux_cmd+=(-f "$ZSH_TMUX_CONFIG") + fi + + if [[ -n "$session_name" ]]; then + $tmux_cmd new-session -s "$session_name" + else + $tmux_cmd new-session + fi + fi + + if [[ "$ZSH_TMUX_AUTOQUIT" == "true" ]]; then + exit + fi +} + +# Use the completions for tmux for our function +compdef _tmux _zsh_tmux_plugin_run +# Alias tmux to our wrapper function. +alias tmux=_zsh_tmux_plugin_run + +function _tmux_directory_session() { + # current directory without leading path + local dir=${PWD##*/} + # md5 hash for the full working directory path + local md5=$(printf '%s' "$PWD" | md5sum | cut -d ' ' -f 1) + # human friendly unique session name for this directory + local session_name="${dir}-${md5:0:6}" + # create or attach to the session + tmux new -As "$session_name" +} + +alias tds=_tmux_directory_session + +# Autostart if not already in tmux and enabled. +if [[ -z "$TMUX" && "$ZSH_TMUX_AUTOSTART" == "true" && -z "$INSIDE_EMACS" && -z "$EMACS" && -z "$VIM" && -z "$INTELLIJ_ENVIRONMENT_READER" ]]; then + # Actually don't autostart if we already did and multiple autostarts are disabled. + if [[ "$ZSH_TMUX_AUTOSTART_ONCE" == "false" || "$ZSH_TMUX_AUTOSTARTED" != "true" ]]; then + export ZSH_TMUX_AUTOSTARTED=true + _zsh_tmux_plugin_run + fi +fi diff --git a/.gitmodules b/.gitmodules index 7340c18..b428a82 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,6 +10,10 @@ path = .config/zsh/plugins/zsh-completions url = https://github.com/zsh-users/zsh-completions branch = master +[submodule ".config/zsh/plugins/zsh-history-substring-search"] + path = .config/zsh/plugins/zsh-history-substring-search + url = https://github.com/zsh-users/zsh-history-substring-search + branch = master [submodule ".config/zsh/plugins/zsh-syntax-highlighting"] path = .config/zsh/plugins/zsh-syntax-highlighting url = https://github.com/zsh-users/zsh-syntax-highlighting diff --git a/.local/bin/change-theme.sh b/.local/bin/change-theme.sh index edb6354..cb3c8bd 100755 --- a/.local/bin/change-theme.sh +++ b/.local/bin/change-theme.sh @@ -6,32 +6,56 @@ set +e # Declare theme configurations typeset -A themes themes[catppuccin-latte]=\ -'ghostty_theme_name=catppuccin-latte - nvim_color_scheme=catppuccin-latte' +'alacritty_theme_name=catppuccin_latte + ghostty_theme_name=catppuccin-latte + nvim_color_scheme=catppuccin-latte + background_color=#eff1f5 + tmux_bar_unfocused_fg=#4c4f69 + tmux_bar_focused_bg=#4c4f69 + tmux_bar_focused_fg=#eff1f5 + kitty_theme="Catppuccin-Latte"' themes[catppuccin-frappe]=\ - 'ghostty_theme_name=catppuccin-frappe - nvim_color_scheme=catppuccin-frappe' +'alacritty_theme_name=catppuccin_frappe + ghostty_theme_name=catppuccin-frappe + nvim_color_scheme=catppuccin-frappe + background_color=#303446 + tmux_bar_unfocused_fg=#c6d0f5 + tmux_bar_focused_bg=#c6d0f5 + tmux_bar_focused_fg=#303446 + kitty_theme="Catppuccin-Frappe"' themes[gruvbox-original-hard-dark]=\ -'ghostty_theme_name=GruvboxDarkHard +'alacritty_theme_name=gruvbox_dark + ghostty_theme_name=GruvboxDarkHard nvim_color_scheme=gruvbox-material + background_color=#1d2021 + tmux_bar_unfocused_fg=#ebdbb2 + tmux_bar_focused_bg=#ebdbb2 + tmux_bar_focused_fg=#1d2021 additional_nvim_commands="\ vim.g.gruvbox_material_better_performance=1 vim.g.gruvbox_material_background=\"hard\" vim.g.gruvbox_material_foreground=\"original\" vim.g.gruvbox_material_transparent_background=2 -vim.opt.background=\"dark\""' +vim.opt.background=\"dark\"" + kitty_theme="Gruvbox Dark Hard"' themes[gruvbox-original-medium-light]=\ -'ghostty_theme_name=GruvboxLight +'alacritty_theme_name=gruvbox_light + ghostty_theme_name=GruvboxLight nvim_color_scheme=gruvbox-material + background_color=#fbf1c7 + tmux_bar_unfocused_fg=#3c3836 + tmux_bar_focused_bg=#3c3836 + tmux_bar_focused_fg=#fbf1c7 additional_nvim_commands="\ vim.g.gruvbox_material_better_performance=1 vim.g.gruvbox_material_background=\"medium\" vim.g.gruvbox_material_foreground=\"original\" vim.g.gruvbox_material_transparent_background=2 -vim.opt.background=\"light\""' +vim.opt.background=\"light\"" + kitty_theme="Gruvbox Light Medium"' themes[gruvbox-material-hard-dark]=\ 'alacritty_theme_name=gruvbox_dark @@ -50,57 +74,91 @@ vim.opt.background=\"dark\"" kitty_theme="Gruvbox Material Dark Hard"' themes[gruvbox-material-medium-dark]=\ -'ghostty_theme_name=gruvbox-material-medium-dark +'alacritty_theme_name=gruvbox_dark + ghostty_theme_name=gruvbox-material-medium-dark nvim_color_scheme=gruvbox-material + background_color=#282828 + tmux_bar_unfocused_fg=#d4be98 + tmux_bar_focused_bg=#d4be98 + tmux_bar_focused_fg=#282828 additional_nvim_commands="\ vim.g.gruvbox_material_better_performance=1 vim.g.gruvbox_material_background=\"medium\" vim.g.gruvbox_material_foreground=\"material\" vim.g.gruvbox_material_transparent_background=2 -vim.opt.background=\"dark\""' +vim.opt.background=\"dark\"" + kitty_theme="Gruvbox Material Dark Medium"' themes[gruvbox-material-soft-dark]=\ - 'ghostty_theme_name=gruvbox-material-soft-dark +'alacritty_theme_name=gruvbox_dark + ghostty_theme_name=gruvbox-material-soft-dark nvim_color_scheme=gruvbox-material + background_color=#32302f + tmux_bar_unfocused_fg=#d4be98 + tmux_bar_focused_bg=#d4be98 + tmux_bar_focused_fg=#32302f additional_nvim_commands="\ vim.g.gruvbox_material_better_performance=1 vim.g.gruvbox_material_background=\"soft\" vim.g.gruvbox_material_foreground=\"material\" vim.g.gruvbox_material_transparent_background=2 -vim.opt.background=\"dark\""' +vim.opt.background=\"dark\"" + kitty_theme="Gruvbox Material Dark Soft"' themes[gruvbox-material-hard-light]=\ - 'ghostty_theme_name=gruvbox-material-hard-light +'alacritty_theme_name=gruvbox_light + ghostty_theme_name=gruvbox-material-hard-light nvim_color_scheme=gruvbox-material + background_color=#f9f5d7 + tmux_bar_unfocused_fg=#654735 + tmux_bar_focused_bg=#654735 + tmux_bar_focused_fg=#f9f5d7 additional_nvim_commands="\ vim.g.gruvbox_material_better_performance=1 vim.g.gruvbox_material_background=\"hard\" vim.g.gruvbox_material_foreground=\"material\" vim.g.gruvbox_material_transparent_background=2 -vim.opt.background=\"light\""' +vim.opt.background=\"light\"" + kitty_theme="Gruvbox Material Light Hard"' themes[gruvbox-material-medium-light]=\ - 'ghostty_theme_name=gruvbox-material-medium-light +'alacritty_theme_name=gruvbox_light + ghostty_theme_name=gruvbox-material-medium-light + background_color=#fbf1c7 + tmux_bar_unfocused_fg=#654735 + tmux_bar_focused_bg=#654735 + tmux_bar_focused_fg=#fbf1c7 nvim_color_scheme=gruvbox-material additional_nvim_commands="\ vim.g.gruvbox_material_better_performance=1 vim.g.gruvbox_material_background=\"medium\" vim.g.gruvbox_material_foreground=\"material\" vim.g.gruvbox_material_transparent_background=2 -vim.opt.background=\"light\""' +vim.opt.background=\"light\"" + kitty_theme="Gruvbox Material Light Medium"' themes[gruvbox-material-soft-light]=\ - 'ghostty_theme_name=gruvbox-material-soft-light +'alacritty_theme_name=gruvbox_light + ghostty_theme_name=gruvbox-material-soft-light + background_color=#f2e5bc + tmux_bar_unfocused_fg=#654735 + tmux_bar_focused_bg=#654735 + tmux_bar_focused_fg=#f2e5bc nvim_color_scheme=gruvbox-material additional_nvim_commands="\ vim.g.gruvbox_material_better_performance=1 vim.g.gruvbox_material_background=\"soft\" vim.g.gruvbox_material_foreground=\"material\" vim.g.gruvbox_material_transparent_background=2 -vim.opt.background=\"light\""' +vim.opt.background=\"light\"" + kitty_theme="Gruvbox Material Light Soft"' themes[everforest-hard-dark]=\ 'ghostty_theme_name=everforest-hard-dark + background_color=#272e33 + tmux_bar_unfocused_fg=#3c4841 + tmux_bar_focused_bg=#3c4841 + tmux_bar_focused_fg=#d3c6aa nvim_color_scheme=everforest additional_nvim_commands="\ vim.g.everforest_better_performance=1 @@ -110,6 +168,10 @@ vim.opt.background=\"dark\""' themes[everforest-medium-dark]=\ 'ghostty_theme_name=everforest-medium-dark + background_color=#2d353b + tmux_bar_unfocused_fg=#425047 + tmux_bar_focused_bg=#425047 + tmux_bar_focused_fg=#d3c6aa nvim_color_scheme=everforest additional_nvim_commands="\ vim.g.everforest_better_performance=1 @@ -119,6 +181,10 @@ vim.opt.background=\"dark\""' themes[everforest-soft-dark]=\ 'ghostty_theme_name=everforest-soft-dark + background_color=#333c43 + tmux_bar_unfocused_fg=#48584e + tmux_bar_focused_bg=#48584e + tmux_bar_focused_fg=#d3c6aa nvim_color_scheme=everforest additional_nvim_commands="\ vim.g.everforest_better_performance=1 @@ -139,7 +205,14 @@ reload_neovim() { # Change common settings change_theme() { + [[ -n "$alacritty_theme_name" ]] && sed -i '' -e "s|import = \[\"~/.config/alacritty/themes/.*\"\]|import = [\"~/.config/alacritty/themes/${alacritty_theme_name}.toml\"]|g" ~/.config/alacritty/alacritty.toml [[ -n "$ghostty_theme_name" ]] && sed -i '' -E "s/theme =.*$/theme = $ghostty_theme_name/" ~/.config/ghostty/config + [[ -n "$kitty_theme" ]] && kitten themes --reload-in=all "$kitty_theme" + sed -i '' -E "s/set -g status-bg .*$/set -g status-bg \"$background_color\"/" ~/.config/tmux/tmux.conf + sed -i '' -E "s/set -g @unfocused-fg .*$/set -g @unfocused-fg \"$tmux_bar_unfocused_fg\"/" ~/.config/tmux/tmux.conf + sed -i '' -E "s/set -g @focused-bg .*$/set -g @focused-bg \"$tmux_bar_focused_bg\"/" ~/.config/tmux/tmux.conf + sed -i '' -E "s/set -g @focused-fg .*$/set -g @focused-fg \"$tmux_bar_focused_fg\"/" ~/.config/tmux/tmux.conf + tmux source-file ~/.config/tmux/tmux.conf reload_neovim "$nvim_color_scheme" "$additional_nvim_commands" }