From 864e692294b9292af534428ee69aed4d94aa5aa8 Mon Sep 17 00:00:00 2001 From: Parth Date: Thu, 9 Jul 2020 19:56:02 -0400 Subject: [PATCH 001/123] added a handful of aliases --- zsh/lockbook.sh | 8 ++++++++ zsh/zshrc.sh | 4 +--- zsh/zshrc_manager.sh | 20 ++++++++++---------- 3 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 zsh/lockbook.sh diff --git a/zsh/lockbook.sh b/zsh/lockbook.sh new file mode 100644 index 000000000..6be74aeb6 --- /dev/null +++ b/zsh/lockbook.sh @@ -0,0 +1,8 @@ +export LOCKBOOK_EDITOR="vim" + +alias lls="lockbook list | fzf" +alias lvim="lockbook list | fzf | lockbook edit" +alias lcat="lockbook list | fzf | lockbook print" +alias lrm="lockbook list | fzf | lockbook remove" + +alias configure="vim ~/dotfiles/zsh/lockbook.sh" diff --git a/zsh/zshrc.sh b/zsh/zshrc.sh index 048936380..3d4cc389f 100644 --- a/zsh/zshrc.sh +++ b/zsh/zshrc.sh @@ -9,6 +9,7 @@ # Aliases alias v="vim -p" mkdir -p /tmp/log + source ~/dotfiles/zsh/lockbook.sh # This is currently causing problems (fails when you run it anywhere that isn't a git project's root directory) # alias vs="v `git status --porcelain | sed -ne 's/^ M //p'`" @@ -35,9 +36,6 @@ source ~/dotfiles/zsh/plugins/fixls.zsh # Custom cd chpwd() ls -# For vim mappings: - stty -ixon - # Completions # These are all the plugin options available: https://github.com/robbyrussell/oh-my-zsh/tree/291e96dcd034750fbe7473482508c08833b168e3/plugins # diff --git a/zsh/zshrc_manager.sh b/zsh/zshrc_manager.sh index 6d34075a7..2503e957d 100644 --- a/zsh/zshrc_manager.sh +++ b/zsh/zshrc_manager.sh @@ -1,15 +1,15 @@ time_out () { perl -e 'alarm shift; exec @ARGV' "$@"; } -# Run tmux if exists -if command -v tmux>/dev/null; then - if [ "$DISABLE_TMUX" = "true" ]; then - echo "DISABLE_TMUX=true" - else - [ -z $TMUX ] && exec tmux - fi -else - echo "tmux not installed. Run ./deploy to configure dependencies" -fi +# # Run tmux if exists +# if command -v tmux>/dev/null; then +# if [ "$DISABLE_TMUX" = "true" ]; then +# echo "DISABLE_TMUX=true" +# else +# [ -z $TMUX ] && exec tmux +# fi +# else +# echo "tmux not installed. Run ./deploy to configure dependencies" +# fi echo "Checking for updates." ({cd ~/dotfiles && git fetch -q} &> /dev/null) From b0bc21121ddccb99407dfb14a2c2d84c338d4703 Mon Sep 17 00:00:00 2001 From: Parth Date: Thu, 9 Jul 2020 20:01:41 -0400 Subject: [PATCH 002/123] removed old aliases --- zsh/lockbook.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/zsh/lockbook.sh b/zsh/lockbook.sh index 6be74aeb6..df2c23255 100644 --- a/zsh/lockbook.sh +++ b/zsh/lockbook.sh @@ -1,8 +1,6 @@ export LOCKBOOK_EDITOR="vim" -alias lls="lockbook list | fzf" -alias lvim="lockbook list | fzf | lockbook edit" +alias lvim="lockbook list-docs | fzf | lockbook edit" alias lcat="lockbook list | fzf | lockbook print" -alias lrm="lockbook list | fzf | lockbook remove" alias configure="vim ~/dotfiles/zsh/lockbook.sh" From 53e3a21fd38c81a4cd40b580b9cfea8402a3ba5c Mon Sep 17 00:00:00 2001 From: Parth Date: Thu, 9 Jul 2020 20:06:10 -0400 Subject: [PATCH 003/123] edited alias --- zsh/lockbook.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zsh/lockbook.sh b/zsh/lockbook.sh index df2c23255..6b9efa49a 100644 --- a/zsh/lockbook.sh +++ b/zsh/lockbook.sh @@ -1,6 +1,6 @@ export LOCKBOOK_EDITOR="vim" -alias lvim="lockbook list-docs | fzf | lockbook edit" +alias lvim="lockbook list-docs | fzf | lockbook edit && lockbook sync" alias lcat="lockbook list | fzf | lockbook print" alias configure="vim ~/dotfiles/zsh/lockbook.sh" From 792ead7496b5a1b980851ee546b3aea58d7ab052 Mon Sep 17 00:00:00 2001 From: Parth Date: Thu, 9 Jul 2020 20:08:02 -0400 Subject: [PATCH 004/123] lls --- zsh/lockbook.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/zsh/lockbook.sh b/zsh/lockbook.sh index 6b9efa49a..f5d2378f3 100644 --- a/zsh/lockbook.sh +++ b/zsh/lockbook.sh @@ -1,5 +1,6 @@ export LOCKBOOK_EDITOR="vim" +alias lls="lockbook list" alias lvim="lockbook list-docs | fzf | lockbook edit && lockbook sync" alias lcat="lockbook list | fzf | lockbook print" From fc5975773759972c00354de91ae916d174655d53 Mon Sep 17 00:00:00 2001 From: Parth Date: Thu, 9 Jul 2020 20:08:58 -0400 Subject: [PATCH 005/123] added fzf --- zsh/lockbook.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zsh/lockbook.sh b/zsh/lockbook.sh index f5d2378f3..bd530e0c8 100644 --- a/zsh/lockbook.sh +++ b/zsh/lockbook.sh @@ -1,6 +1,6 @@ export LOCKBOOK_EDITOR="vim" -alias lls="lockbook list" +alias lls="lockbook list | fzf" alias lvim="lockbook list-docs | fzf | lockbook edit && lockbook sync" alias lcat="lockbook list | fzf | lockbook print" From c0a34619aa4fca54b79651a13ac702bb9254aad0 Mon Sep 17 00:00:00 2001 From: Parth Date: Sat, 11 Jul 2020 23:26:08 -0400 Subject: [PATCH 006/123] save keybindings --- zsh/keybindings.sh | 2 +- zsh/lockbook.sh | 21 ++++++++++++++++++--- zsh/zshrc.sh | 3 ++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/zsh/keybindings.sh b/zsh/keybindings.sh index 55617d785..926fce5a5 100644 --- a/zsh/keybindings.sh +++ b/zsh/keybindings.sh @@ -46,7 +46,7 @@ zle -N add_sudo bindkey "^s" add_sudo - # Home - Navigates to the current root workspace +# Home - Navigates to the current root workspace function git_root() { BUFFER="cd $(git rev-parse --show-toplevel || echo ".")" zle accept-line diff --git a/zsh/lockbook.sh b/zsh/lockbook.sh index bd530e0c8..f95de11cb 100644 --- a/zsh/lockbook.sh +++ b/zsh/lockbook.sh @@ -1,7 +1,22 @@ export LOCKBOOK_EDITOR="vim" -alias lls="lockbook list | fzf" -alias lvim="lockbook list-docs | fzf | lockbook edit && lockbook sync" -alias lcat="lockbook list | fzf | lockbook print" +alias dirs="lockbook list-folders | fzf --prompt='Select a folder: '" +alias docs="lockbook list-docs | fzf --prompt='Select a document: '" +alias edit='lockbook edit $(docs)' + +function new_document() { + BUFFER='lockbook new $(dirs)' + zle end-of-line +} + +zle -N new_document +bindkey "^l" new_document + +function edit_document() { + BUFFER='lockbook edit $(docs) && lockbook sync' + zle accept-line +} +zle -N edit_document +bindkey "^f" edit_document alias configure="vim ~/dotfiles/zsh/lockbook.sh" diff --git a/zsh/zshrc.sh b/zsh/zshrc.sh index 3d4cc389f..09b3675d2 100644 --- a/zsh/zshrc.sh +++ b/zsh/zshrc.sh @@ -9,7 +9,6 @@ # Aliases alias v="vim -p" mkdir -p /tmp/log - source ~/dotfiles/zsh/lockbook.sh # This is currently causing problems (fails when you run it anywhere that isn't a git project's root directory) # alias vs="v `git status --porcelain | sed -ne 's/^ M //p'`" @@ -78,3 +77,5 @@ fi source ~/dotfiles/zsh/prompt.sh export PATH=$PATH:$HOME/dotfiles/utils + +source ~/dotfiles/zsh/lockbook.sh From 031ba10c1ac174acadf93118ab50cdf8aa22017b Mon Sep 17 00:00:00 2001 From: Parth Date: Fri, 17 Jul 2020 01:13:44 -0400 Subject: [PATCH 007/123] undo accidental tmux deletion, closes #60 --- zsh/lockbook.sh | 3 ++- zsh/zshrc_manager.sh | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/zsh/lockbook.sh b/zsh/lockbook.sh index f95de11cb..86247dcd4 100644 --- a/zsh/lockbook.sh +++ b/zsh/lockbook.sh @@ -1,7 +1,8 @@ export LOCKBOOK_EDITOR="vim" +alias all="lockbook list-all | fzf --prompt='Select a file: '" alias dirs="lockbook list-folders | fzf --prompt='Select a folder: '" -alias docs="lockbook list-docs | fzf --prompt='Select a document: '" +alias docs="lockbook list-docs | grep -v 'parth/trash' | fzf --prompt='Select a document: '" alias edit='lockbook edit $(docs)' function new_document() { diff --git a/zsh/zshrc_manager.sh b/zsh/zshrc_manager.sh index 2503e957d..6d34075a7 100644 --- a/zsh/zshrc_manager.sh +++ b/zsh/zshrc_manager.sh @@ -1,15 +1,15 @@ time_out () { perl -e 'alarm shift; exec @ARGV' "$@"; } -# # Run tmux if exists -# if command -v tmux>/dev/null; then -# if [ "$DISABLE_TMUX" = "true" ]; then -# echo "DISABLE_TMUX=true" -# else -# [ -z $TMUX ] && exec tmux -# fi -# else -# echo "tmux not installed. Run ./deploy to configure dependencies" -# fi +# Run tmux if exists +if command -v tmux>/dev/null; then + if [ "$DISABLE_TMUX" = "true" ]; then + echo "DISABLE_TMUX=true" + else + [ -z $TMUX ] && exec tmux + fi +else + echo "tmux not installed. Run ./deploy to configure dependencies" +fi echo "Checking for updates." ({cd ~/dotfiles && git fetch -q} &> /dev/null) From 62a2ef5005b6332a172021ca60b8dca8c08b6e55 Mon Sep 17 00:00:00 2001 From: Parth Date: Tue, 15 Sep 2020 20:17:09 -0400 Subject: [PATCH 008/123] sync on new --- zsh/lockbook.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zsh/lockbook.sh b/zsh/lockbook.sh index 86247dcd4..82ddc9fda 100644 --- a/zsh/lockbook.sh +++ b/zsh/lockbook.sh @@ -6,7 +6,7 @@ alias docs="lockbook list-docs | grep -v 'parth/trash' | fzf --prompt='Select a alias edit='lockbook edit $(docs)' function new_document() { - BUFFER='lockbook new $(dirs)' + BUFFER='lockbook new $(dirs) && lockbook sync' zle end-of-line } From a478b7594f7941de97927d89d0b7a9be985b53bc Mon Sep 17 00:00:00 2001 From: Parth Date: Wed, 21 Oct 2020 23:41:48 -0400 Subject: [PATCH 009/123] fixed new file command --- zsh/lockbook.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zsh/lockbook.sh b/zsh/lockbook.sh index 82ddc9fda..0a5622c6f 100644 --- a/zsh/lockbook.sh +++ b/zsh/lockbook.sh @@ -6,8 +6,9 @@ alias docs="lockbook list-docs | grep -v 'parth/trash' | fzf --prompt='Select a alias edit='lockbook edit $(docs)' function new_document() { - BUFFER='lockbook new $(dirs) && lockbook sync' + BUFFER='lockbook new $(dirs)' zle end-of-line + BUFFER='lockbook new $(dirs) && lockbook sync' } zle -N new_document From b978d53baee8e6c72fc2567711a3db6475401f3c Mon Sep 17 00:00:00 2001 From: Parth Date: Sun, 9 May 2021 12:25:56 -0400 Subject: [PATCH 010/123] zsh and tmux spring cleaning --- .gitmodules | 6 +- env-vars.env | 5 + utils/copy | 3 +- vim/vimrc.vim | 2 +- zsh/keybindings.sh | 73 +- zsh/plugins/fzf-tab | 1 + zsh/plugins/vi-mode.plugin.zsh | 50 - zsh/plugins/zsh-vi-mode.plugin.zsh | 6 + zsh/plugins/zsh-vi-mode.zsh | 3324 ++++++++++++++++++++++++++++ zsh/zshrc.sh | 78 +- 10 files changed, 3375 insertions(+), 173 deletions(-) create mode 100644 env-vars.env create mode 160000 zsh/plugins/fzf-tab delete mode 100644 zsh/plugins/vi-mode.plugin.zsh create mode 100644 zsh/plugins/zsh-vi-mode.plugin.zsh create mode 100644 zsh/plugins/zsh-vi-mode.zsh diff --git a/.gitmodules b/.gitmodules index c1366da14..8511a1277 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,6 +4,6 @@ [submodule "zsh/plugins/zsh-autosuggestions"] path = zsh/plugins/zsh-autosuggestions url = https://github.com/zsh-users/zsh-autosuggestions.git -[submodule "zsh/plugins/oh-my-zsh"] - path = zsh/plugins/oh-my-zsh - url = https://github.com/robbyrussell/oh-my-zsh.git +[submodule "zsh/plugins/fzf-tab"] + path = zsh/plugins/fzf-tab + url = https://github.com/Aloxaf/fzf-tab diff --git a/env-vars.env b/env-vars.env new file mode 100644 index 000000000..dfdb49692 --- /dev/null +++ b/env-vars.env @@ -0,0 +1,5 @@ +# Set default text editor to vim +export VISUAL=vim + +# Utils +export PATH=$PATH:$HOME/dotfiles/utils diff --git a/utils/copy b/utils/copy index dfdf61fa2..6c8a4c1f2 100755 --- a/utils/copy +++ b/utils/copy @@ -1,3 +1,4 @@ +#!/bin/zsh if [[ $OSTYPE == darwin* ]]; then pbcopy elif [[ $OSTYPE == cygwin* ]]; then @@ -6,7 +7,7 @@ else if (( $+commands[xclip] )); then xclip -in -selection clipboard elif (( $+commands[xsel] )); then - xsel --clipboard --input + xsel --clipboard --input else print "clipcopy: Platform $OSTYPE not supported or xclip/xsel not installed" >&2 return 1 diff --git a/vim/vimrc.vim b/vim/vimrc.vim index 5029c7472..e4dabbce2 100644 --- a/vim/vimrc.vim +++ b/vim/vimrc.vim @@ -1,5 +1,5 @@ " General Vim settings - syntax on + syntax enable let mapleader="," set autoindent set tabstop=4 diff --git a/zsh/keybindings.sh b/zsh/keybindings.sh index 926fce5a5..b4d858657 100644 --- a/zsh/keybindings.sh +++ b/zsh/keybindings.sh @@ -1,55 +1,30 @@ # up - function up_widget() { - BUFFER="cd .." - zle accept-line - } - zle -N up_widget - bindkey "^k" up_widget - -# git - function git_prepare() { - if [ -n "$BUFFER" ]; - then - BUFFER="git add -A && git commit -m \"$BUFFER\" && git push" - fi - - if [ -z "$BUFFER" ]; - then - BUFFER="git add -A && git commit -v && git push" - fi - - zle accept-line - } - zle -N git_prepare - bindkey "^g" git_prepare - -# Edit and rerun - function edit_and_run() { - BUFFER="fc" - zle accept-line - } - zle -N edit_and_run - bindkey "^v" edit_and_run +function up_widget() { + BUFFER="cd .." + zle accept-line +} +zle -N up_widget +bindkey "^k" up_widget # Enter - function enter_line() { - zle accept-line - } - zle -N enter_line - bindkey "^o" enter_line +function enter_line() { + zle accept-line +} +zle -N enter_line +bindkey "^o" enter_line # Sudo - function add_sudo() { - BUFFER="sudo "$BUFFER - zle end-of-line - } - zle -N add_sudo - bindkey "^s" add_sudo - +function add_sudo() { + BUFFER="sudo "$BUFFER + zle end-of-line +} +zle -N add_sudo +bindkey "^s" add_sudo + # Home - Navigates to the current root workspace - function git_root() { - BUFFER="cd $(git rev-parse --show-toplevel || echo ".")" - zle accept-line - } - zle -N git_root - bindkey "^h" git_root +function git_root() { + BUFFER="cd $(git rev-parse --show-toplevel || echo ".")" + zle accept-line +} +zle -N git_root +bindkey "^h" git_root diff --git a/zsh/plugins/fzf-tab b/zsh/plugins/fzf-tab new file mode 160000 index 000000000..3d6aca79b --- /dev/null +++ b/zsh/plugins/fzf-tab @@ -0,0 +1 @@ +Subproject commit 3d6aca79b68b8b98286dda2cb76076f2a2081225 diff --git a/zsh/plugins/vi-mode.plugin.zsh b/zsh/plugins/vi-mode.plugin.zsh deleted file mode 100644 index 82a2f3040..000000000 --- a/zsh/plugins/vi-mode.plugin.zsh +++ /dev/null @@ -1,50 +0,0 @@ -# Updates editor information when the keymap changes. -function zle-keymap-select() { - zle reset-prompt - zle -R -} - -# Ensure that the prompt is redrawn when the terminal size changes. -TRAPWINCH() { - zle && zle -R -} - -zle -N zle-keymap-select -zle -N edit-command-line - - -bindkey -v - -# allow v to edit the command line (standard behaviour) -autoload -Uz edit-command-line -bindkey -M vicmd 'v' edit-command-line - -# allow ctrl-p, ctrl-n for navigate history (standard behaviour) -bindkey '^P' up-history -bindkey '^N' down-history - -# allow ctrl-h, ctrl-w, ctrl-? for char and word deletion (standard behaviour) -bindkey '^?' backward-delete-char -bindkey '^h' backward-delete-char -bindkey '^w' backward-kill-word - -# allow ctrl-r to perform backward search in history -bindkey '^r' history-incremental-search-backward - -# allow ctrl-a and ctrl-e to move to beginning/end of line -bindkey '^a' beginning-of-line -bindkey '^e' end-of-line - -# if mode indicator wasn't setup by theme, define default -if [[ "$MODE_INDICATOR" == "" ]]; then - MODE_INDICATOR="%{$fg_bold[red]%}<%{$fg[red]%}<<%{$reset_color%}" -fi - -function vi_mode_prompt_info() { - echo "${${KEYMAP/vicmd/$MODE_INDICATOR}/(main|viins)/}" -} - -# define right prompt, if it wasn't defined by a theme -if [[ "$RPS1" == "" && "$RPROMPT" == "" ]]; then - RPS1='$(vi_mode_prompt_info)' -fi diff --git a/zsh/plugins/zsh-vi-mode.plugin.zsh b/zsh/plugins/zsh-vi-mode.plugin.zsh new file mode 100644 index 000000000..8fa87254e --- /dev/null +++ b/zsh/plugins/zsh-vi-mode.plugin.zsh @@ -0,0 +1,6 @@ +# According to the standard: +# https://github.com/zdharma/Zsh-100-Commits-Club/blob/master/Zsh-Plugin-Standard.adoc +0="${ZERO:-${${0:#$ZSH_ARGZERO}:-${(%):-%N}}}" +0="${${(M)0:#/*}:-$PWD/$0}" + +source ${0:h}/zsh-vi-mode.zsh diff --git a/zsh/plugins/zsh-vi-mode.zsh b/zsh/plugins/zsh-vi-mode.zsh new file mode 100644 index 000000000..bc43e0219 --- /dev/null +++ b/zsh/plugins/zsh-vi-mode.zsh @@ -0,0 +1,3324 @@ +# zsh-vi-mode.zsh -- A better and friendly vi(vim) mode for Zsh +# https://github.com/jeffreytse/zsh-vi-mode +# +# Copyright (c) 2020 Jeffrey Tse +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# All Settings +# Some of these variables should be set before sourcing this file. +# +# ZVM_VI_ESCAPE_BINDKEY +# the vi escape key for all modes (default is ^[ => ), you can set it +# to whatever you like, such as `jj`, `jk` and so on. +# +# ZVM_VI_INSERT_ESCAPE_BINDKEY +# the vi escape key of insert mode (default is $ZVM_VI_ESCAPE_BINDKEY), you +# can set it to whatever, such as `jj`, `jk` and so on. +# +# ZVM_VI_VISUAL_ESCAPE_BINDKEY +# the vi escape key of visual mode (default is $ZVM_VI_ESCAPE_BINDKEY), you +# can set it to whatever, such as `jj`, `jk` and so on. +# +# ZVM_VI_OPPEND_ESCAPE_BINDKEY +# the vi escape key of operator pendding mode (default is +# $ZVM_VI_ESCAPE_BINDKEY), you can set it to whatever, such as `jj`, `jk` +# and so on. +# +# ZVM_VI_INSERT_MODE_LEGACY_UNDO: +# using legacy undo behavior in vi insert mode +# +# ZVM_VI_HIGHLIGHT_BACKGROUND: +# the behavior of highlight (surrounds, visual-line, etc) in vi mode +# +# For example: +# ZVM_VI_HIGHLIGHT_BACKGROUND=red # Color name +# ZVM_VI_HIGHLIGHT_BACKGROUND=#ff0000 # Hex value +# +# ZVM_VI_SURROUND_BINDKEY +# the key binding mode for surround operating (default is 'classic') +# +# 1. 'classic' mode (verb->s->surround): +# S" Add " for visual selection +# ys" Add " for visual selection +# cs"' Change " to ' +# ds" Delete " +# +# 2. 's-prefix' mode (s->verb->surround): +# sa" Add " for visual selection +# sd" Delete " +# sr"' Change " to ' +# +# How to select surround text object? +# vi" Select the text object inside the quotes +# va( Select the text object including the brackets +# +# Then you can do any operation for the selection: +# +# 1. Add surrounds for text object +# vi" -> S[ or sa[ => "object" -> "[object]" +# +# 2. Delete/Yank/Change text object +# di( or vi( -> d +# ca( or va( -> c +# yi( or vi( -> y +# +# ZVM_READKEY_ENGINE +# the readkey engine for reading and processing the key events, and the +# below engines are supported: +# ZVM_READKEY_ENGINE_NEX (Default) +# ZVM_READKEY_ENGINE_ZLE +# +# the NEX is a better engine for reading and handling the key events than +# the Zsh's ZLE engine, currently the NEX engine is at beta stage, and +# you can change to Zsh's ZLE engine if you want. +# +# ZVM_KEYTIMEOUT: +# the key input timeout for waiting for next key (default is 0.4 seconds) +# +# ZVM_ESCAPE_KEYTIMEOUT: +# the key input timeout for waiting for next key if it is beginning with +# an escape character (default is 0.03 seconds), and this option is just +# available for the NEX readkey engine +# +# ZVM_LINE_INIT_MODE +# the setting for init mode of command line (default is empty), empty will +# keep the last command mode, for the first command line it will be insert +# mode, you can also set it to a specific vi mode to alway keep the mode +# for each command line +# +# For example: +# ZVM_LINE_INIT_MODE=$ZVM_MODE_INSERT +# ZVM_LINE_INIT_MODE=$ZVM_MODE_NORMAL +# +# ZVM_LAZY_KEYBINDINGS: +# the setting for lazy keybindings (default is true), and lazy keybindings +# will postpone the keybindings of vicmd and visual keymaps to the first +# time entering normal mode +# +# ZVM_NORMAL_MODE_CURSOR: +# the prompt cursor in normal mode +# +# ZVM_INSERT_MODE_CURSOR: +# the prompt cursor in insert mode +# +# ZVM_VISUAL_MODE_CURSOR: +# the prompt cursor in visual mode +# +# ZVM_VISUAL_LINE_MODE_CURSOR: +# the prompt cursor in visual line mode +# +# ZVM_OPPEND_MODE_CURSOR: +# the prompt cursor in operator pending mode +# +# You can change the cursor style by below: +# ZVM_INSERT_MODE_CURSOR=$ZVM_CURSOR_BLOCK +# +# and the below cursor style are supported: +# ZVM_CURSOR_USER_DEFAULT +# ZVM_CURSOR_BLOCK +# ZVM_CURSOR_UNDERLINE +# ZVM_CURSOR_BEAM +# ZVM_CURSOR_BLINKING_BLOCK +# ZVM_CURSOR_BLINKING_UNDERLINE +# ZVM_CURSOR_BLINKING_BEAM +# +# ZVM_VI_EDITOR +# the editor to edit your command line (default is $EDITOR) +# +# ZVM_TMPDIR +# the temporary directory (default is $TMPDIR, otherwise it's /tmp/) +# +# ZVM_TERM +# the term for handling terminal sequences, it's important for some +# terminal emulators to show cursor properly (default is $TERM) +# +# ZVM_CURSOR_STYLE_ENABLED +# enable the cursor style feature (default is true) +# + +# Avoid sourcing plugin multiple times +command -v 'zvm_version' >/dev/null && return + +# Plugin information +typeset -gr ZVM_NAME='zsh-vi-mode' +typeset -gr ZVM_DESCRIPTION='💻 A better and friendly vi(vim) mode plugin for ZSH.' +typeset -gr ZVM_REPOSITORY='https://github.com/jeffreytse/zsh-vi-mode' +typeset -gr ZVM_VERSION='0.8.3' + +# Plugin initial status +ZVM_INIT_DONE=false + +# Disable reset prompt (i.e. disable the widget `reset-prompt`) +ZVM_RESET_PROMPT_DISABLED=false + +# Operator pending mode +ZVM_OPPEND_MODE=false + +# Insert mode could be +# `i` (insert) +# `a` (append) +# `I` (insert at the non-blank beginning of current line) +# `A` (append at the end of current line) +ZVM_INSERT_MODE='i' + +# The mode could be the below value: +# `n` (normal) +# `i` (insert) +# `v` (visual) +# `vl` (visual-line) +ZVM_MODE='' + +# The keys typed to invoke this widget, as a literal string +ZVM_KEYS='' + +# The region hilight information +ZVM_REGION_HIGHLIGHT=() + +# Default zvm readkey engines +ZVM_READKEY_ENGINE_NEX='nex' +ZVM_READKEY_ENGINE_ZLE='zle' +ZVM_READKEY_ENGINE_DEFAULT=$ZVM_READKEY_ENGINE_NEX + +# Default alternative character for escape characters +ZVM_ESCAPE_SPACE='\s' +ZVM_ESCAPE_NEWLINE='^J' + +# Default vi modes +ZVM_MODE_LAST='' +ZVM_MODE_NORMAL='n' +ZVM_MODE_INSERT='i' +ZVM_MODE_VISUAL='v' +ZVM_MODE_VISUAL_LINE='vl' +ZVM_MODE_REPLACE='r' + +# Default cursor styles +ZVM_CURSOR_USER_DEFAULT='ud' +ZVM_CURSOR_BLOCK='bl' +ZVM_CURSOR_UNDERLINE='ul' +ZVM_CURSOR_BEAM='be' +ZVM_CURSOR_BLINKING_BLOCK='bbl' +ZVM_CURSOR_BLINKING_UNDERLINE='bul' +ZVM_CURSOR_BLINKING_BEAM='bbe' + +# The commands need to be repeated +ZVM_REPEAT_MODE=false +ZVM_REPEAT_RESET=false +ZVM_REPEAT_COMMANDS=($ZVM_MODE_NORMAL i) + +########################################## +# Initial all default settings + +# Set the readkey engine (default is NEX engine) +: ${ZVM_READKEY_ENGINE:=$ZVM_READKEY_ENGINE_DEFAULT} + +# Set key input timeout (default is 0.4 seconds) +: ${ZVM_KEYTIMEOUT:=0.4} + +# Set the escape key timeout (default is 0.03 seconds) +: ${ZVM_ESCAPE_KEYTIMEOUT:=0.03} + +# Set keybindings mode (default is true) +# The lazy keybindings will post the keybindings of vicmd and visual +# keymaps to the first time entering the normal mode +: ${ZVM_LAZY_KEYBINDINGS:=true} + +# All keybindings for lazy loading +if $ZVM_LAZY_KEYBINDINGS; then + ZVM_LAZY_KEYBINDINGS_LIST=() +fi + +# Set the cursor stlye in defferent vi modes, the value you could use +# the predefined value, such as $ZVM_CURSOR_BLOCK, $ZVM_CURSOR_BEAM, +# $ZVM_CURSOR_BLINKING_BLOCK and so on. +: ${ZVM_INSERT_MODE_CURSOR:=$ZVM_CURSOR_BEAM} +: ${ZVM_NORMAL_MODE_CURSOR:=$ZVM_CURSOR_BLOCK} +: ${ZVM_VISUAL_MODE_CURSOR:=$ZVM_CURSOR_BLOCK} +: ${ZVM_VISUAL_LINE_MODE_CURSOR:=$ZVM_CURSOR_BLOCK} + +# Operator pending mode cursor style (default is underscore) +: ${ZVM_OPPEND_MODE_CURSOR:=$ZVM_CURSOR_UNDERLINE} + +# Set the vi escape key (default is ^[ => ) +: ${ZVM_VI_ESCAPE_BINDKEY:=^[} +: ${ZVM_VI_INSERT_ESCAPE_BINDKEY:=$ZVM_VI_ESCAPE_BINDKEY} +: ${ZVM_VI_VISUAL_ESCAPE_BINDKEY:=$ZVM_VI_ESCAPE_BINDKEY} +: ${ZVM_VI_OPPEND_ESCAPE_BINDKEY:=$ZVM_VI_ESCAPE_BINDKEY} + +# Set the line init mode (empty will keep the last mode) +# you can also set it to others, such as $ZVM_MODE_INSERT. +: ${ZVM_LINE_INIT_MODE:=$ZVM_MODE_LAST} + +: ${ZVM_VI_INSERT_MODE_LEGACY_UNDO:=false} +: ${ZVM_VI_SURROUND_BINDKEY:=classic} +: ${ZVM_VI_HIGHLIGHT_BACKGROUND:=#cc0000} +: ${ZVM_VI_EDITOR:=${EDITOR:-vim}} +: ${ZVM_TMPDIR:=${TMPDIR:-/tmp/}} + +# Set the term for handling terminal sequences, it's important for some +# terminal emulators to show cursor properly (default is $TERM) +: ${ZVM_TERM:=${TERM:-xterm-256color}} + +# Enable the cursor style feature +: ${ZVM_CURSOR_STYLE_ENABLED:=true} + +# All the extra commands +zvm_before_init_commands=() +zvm_after_init_commands=() +zvm_before_select_vi_mode_commands=() +zvm_after_select_vi_mode_commands=() +zvm_before_lazy_keybindings_commands=() +zvm_after_lazy_keybindings_commands=() + +# All the handlers for switching keyword +zvm_switch_keyword_handlers=( + zvm_switch_number + zvm_switch_boolean + zvm_switch_operator + zvm_switch_weekday + zvm_switch_month +) + +# Display version information +function zvm_version() { + echo -e "$ZVM_NAME $ZVM_VERSION" + echo -e "\e[4m$ZVM_REPOSITORY\e[0m" + echo -e "$ZVM_DESCRIPTION" +} + +# The widget wrapper +function zvm_widget_wrapper() { + local rawfunc=$1; + local func=$2; + local -i retval + $func "${@:3}" + return retval +} + +# Define widget function +function zvm_define_widget() { + local widget=$1 + local func=$2 || $1 + local result=($(zle -l -L "${widget}")) + + # Check if existing the same name + if [[ ${#result[@]} == 4 ]]; then + local rawfunc=${result[4]} + local wrapper="zvm_${widget}-wrapper" + eval "$wrapper() { zvm_widget_wrapper $rawfunc $func \"\$@\" }" + func=$wrapper + fi + + zle -N $widget $func +} + +# Get the keys typed to invoke this widget, as a literal string +function zvm_keys() { + local keys=${ZVM_KEYS:-$KEYS} + + # Append the prefix of keys if it is visual or visual-line mode + case "${ZVM_MODE}" in + $ZVM_MODE_VISUAL) + if [[ "$keys" != v* ]]; then + keys="v${keys}" + fi + ;; + $ZVM_MODE_VISUAL_LINE) + if [[ "$keys" != V* ]]; then + keys="V${keys}" + fi + ;; + esac + + # Escape the newline and space characters, otherwise, we can't + # get the output from subshell correctly. + keys=${keys//$'\n'/$ZVM_ESCAPE_NEWLINE} + keys=${keys// /$ZVM_ESCAPE_SPACE} + + echo $keys +} + +# Find the widget on a specified bindkey +function zvm_find_bindkey_widget() { + local keymap=$1 + local keys=$2 + local prefix_mode=${3:-false} + retval=() + + if $prefix_mode; then + local pos=0 + local spos=3 + local prefix_keys= + + # Get the prefix keys + if [[ $prefix_keys ]]; then + prefix_keys=${prefix_keys:0:-1} + + # If the last key is an escape key (e.g. \", \`, \\) we still + # need to remove the escape backslash `\` + if [[ ${prefix_keys: -1} == '\' ]]; then + prefix_keys=${prefix_keys:0:-1} + fi + fi + + local result=$(bindkey -M ${keymap} -p "$prefix_keys")$'\n' + + # Split string to array by newline + for ((i=$spos;i<$#result;i++)); do + + # Save the last whitespace character of the line + # and continue continue handling while meeting `\n` + case "${result:$i:1}" in + ' ') spos=$i; i=$i+1; continue;; + [$'\n']);; + *) continue;; + esac + + # Check if it has the same prefix keys and retrieve the widgets + if [[ "${result:$((pos+1)):$#keys}" == "$keys" ]]; then + + # Get the binding keys + local k=${result:$((pos+1)):$((spos-pos-2))} + + # Escape spaces in key bindings (space -> $ZVM_ESCAPE_SPACE) + k=${k// /$ZVM_ESCAPE_SPACE} + retval+=($k ${result:$((spos+1)):$((i-spos-1))}) + fi + + # Save as new position + pos=$i+1 + + # Skip 3 characters + # One key and quotes at least (i.e \n"_" ) + i=$i+3 + done + else + local result=$(bindkey -M ${keymap} "$keys") + if [[ "${result: -14}" == ' undefined-key' ]]; then + return + fi + + # Escape spaces in key bindings (space -> $ZVM_ESCAPE_SPACE) + for ((i=$#result;i>=0;i--)); do + + # Backward find the first whitespace character + [[ "${result:$i:1}" == ' ' ]] || continue + + # Retrieve the keys and widget + local k=${result:1:$i-2} + + # Escape spaces in key bindings (space -> $ZVM_ESCAPE_SPACE) + k=${k// /$ZVM_ESCAPE_SPACE} + retval+=($k ${result:$i+1}) + + break + done + fi +} + +# Read keys for retrieving widget +function zvm_readkeys() { + local keymap=$1 + local key=${2:-$(zvm_keys)} + local keys= + local widget= + local result= + local pattern= + local timeout= + + # Escape the non-printed characters + pattern=$(zvm_escape_non_printed_characters "${keys}") + pattern=${pattern//$ZVM_ESCAPE_SPACE/ } + + while :; do + # Keep reading key for escape character + if [[ "$key" == '' ]]; then + while :; do + local k= + read -t $ZVM_ESCAPE_KEYTIMEOUT -k 1 k || break + key="${key}${k}" + done + fi + + keys="${keys}${key}" + + # Handle the pattern + if [[ -n "$key" ]]; then + # Transform the non-printed characters + local k=$(zvm_escape_non_printed_characters "${key}") + + # Escape keys + # " -> \" It's a special character in bash syntax + # ` -> \` It's a special character in bash syntax + # -> ` ` It's a special character in bash syntax + k=${k//\"/\\\"} + k=${k//\`/\\\`} + k=${k//$ZVM_ESCAPE_SPACE/ } + + pattern="${pattern}${k}" + fi + + # Find out widgets that match this key pattern + zvm_find_bindkey_widget $keymap "$pattern" true + result=(${retval[@]}) + + # Exit key input if there is only one widget matched + # or no more widget matched. + case ${#result[@]} in + 2) key=; widget=${result[2]}; break;; + 0) break;; + esac + + # Evaluate the readkey timeout + # Special timeout for the escape sequence + if [[ "${keys}" ==  ]]; then + timeout=$ZVM_ESCAPE_KEYTIMEOUT + # Check if there is any one custom escape sequence + for ((i=1; i<=${#result[@]}; i=i+2)); do + if [[ "${result[$i]}" =~ '^\^\[\[?[A-Z0-9]*~?\^\[' ]]; then + timeout=$ZVM_KEYTIMEOUT + break + fi + done + else + timeout=$ZVM_KEYTIMEOUT + fi + + # Wait for reading next key, and we should save the widget + # as the final widget if it is full matching + key= + if [[ "${result[1]}" == "${pattern}" ]]; then + widget=${result[2]} + # Get current widget as final widget when reading key timeout + read -t $timeout -k 1 key || break + else + zvm_enter_oppend_mode + read -k 1 key + fi + done + + # Exit operator pending mode + if $ZVM_OPPEND_MODE; then + zvm_exit_oppend_mode + fi + + if [[ -z "$key" ]]; then + retval=(${keys} $widget) + else + retval=(${keys:0:-$#key} $widget $key) + fi +} + +# Add key bindings +function zvm_bindkey() { + local keymap=$1 + local keys=$2 + local widget=$3 + local params=$4 + local key= + + # We should bind keys with an existing widget + [[ -z $widget ]] && return + + # If lazy keybindings is enabled, we need to add to the lazy list + if [[ ${ZVM_LAZY_KEYBINDINGS_LIST+x} && ${keymap} != viins ]]; then + keys=${keys//\"/\\\"} + keys=${keys//\`/\\\`} + ZVM_LAZY_KEYBINDINGS_LIST+=( + "${keymap} \"${keys}\" ${widget} \"${params}\"" + ) + return + fi + + # Hanle the keybinding of NEX readkey engine + if [[ $ZVM_READKEY_ENGINE == $ZVM_READKEY_ENGINE_NEX ]]; then + # Get the first key (especially check if ctrl characters) + if [[ $#keys -gt 1 && "${keys:0:1}" == '^' ]]; then + key=${keys:0:2} + else + key=${keys:0:1} + fi + bindkey -M $keymap "${key}" zvm_readkeys_handler + fi + + # Wrap params to a new widget + if [[ -n $params ]]; then + local suffix=$(zvm_string_to_hex $params) + eval "$widget:$suffix() { $widget $params }" + widget="$widget:$suffix" + zvm_define_widget $widget + fi + + # Bind keys with with a widget + bindkey -M $keymap "${keys}" $widget +} + +# Convert string to hexadecimal +function zvm_string_to_hex() { + local str= + for ((i=1;i<=$#1;i++)); do + str+=$(printf '%x' "'${1[$i]}") + done + echo "$str" +} + +# Escape non-printed characters +function zvm_escape_non_printed_characters() { + local str= + for ((i=0;i<$#1;i++)); do + local c=${1:$i:1} + if [[ "$c" < ' ' ]]; then + local ord=$(($(printf '%d' "'$c")+64)) + c=$(printf \\$(printf '%03o' $ord)) + str="${str}^${c}" + elif [[ "$c" == '' ]]; then + str="${str}^?" + elif [[ "$c" == '' ]]; then + str="${str}^@" + else + str="${str}${c}" + fi + done + + # Escape the newline and space characters, otherwise, we can't + # get the output from subshell correctly. + str=${str// /$ZVM_ESCAPE_SPACE} + str=${str//$'\n'/$ZVM_ESCAPE_NEWLINE} + + echo -n $str +} + +# Backward remove characters of an emacs region in the line +function zvm_backward_kill_region() { + local bpos=$CURSOR-1 epos=$CURSOR + + # Backward search the boundary of current region + for ((; bpos >= 0; bpos--)); do + # Break when cursor is at the beginning of line + [[ "${BUFFER:$bpos:1}" == $'\n' ]] && break + + # Break when cursor is at the boundary of a word region + [[ "${BUFFER:$bpos:2}" =~ ^\ [^\ $'\n']$ ]] && break + done + + bpos=$bpos+1 + CUTBUFFER=${BUFFER:$bpos:$((epos-bpos))} + BUFFER="${BUFFER:0:$bpos}${BUFFER:$epos}" + CURSOR=$bpos +} + +# Remove all characters between the cursor position and the +# beginning of the line. +function zvm_backward_kill_line() { + BUFFER=${BUFFER:$CURSOR:$#BUFFER} + CURSOR=0 +} + +# Remove all characters between the cursor position and the +# end of the line. +function zvm_forward_kill_line() { + BUFFER=${BUFFER:0:$CURSOR} +} + +# Remove all characters of the line. +function zvm_kill_line() { + local ret=($(zvm_calc_selection $ZVM_MODE_VISUAL_LINE)) + local bpos=${ret[1]} epos=${ret[2]} + CUTBUFFER=${BUFFER:$bpos:$((epos-bpos))}$'\n' + BUFFER="${BUFFER:0:$bpos}${BUFFER:$epos}" + CURSOR=$bpos +} + +# Remove all characters of the whole line. +function zvm_kill_whole_line() { + local ret=($(zvm_calc_selection $ZVM_MODE_VISUAL_LINE)) + local bpos=$ret[1] epos=$ret[2] cpos=$ret[3] + CUTBUFFER=${BUFFER:$bpos:$((epos-bpos))}$'\n' + + # Adjust region range of deletion + if (( $epos < $#BUFFER )); then + epos=$epos+1 + fi + + BUFFER="${BUFFER:0:$bpos}${BUFFER:$epos}" + CURSOR=$cpos +} + +# Exchange the point and mark +function zvm_exchange_point_and_mark() { + cursor=$MARK + MARK=$CURSOR CURSOR=$cursor + zvm_highlight +} + +# Open line below +function zvm_open_line_below() { + local i=$CURSOR + + # If there is a completion suffix, we should break at the + # postion of suffix begin, otherwise, it should break when + # forward finding out the first newline character. + for ((; i<$#BUFFER; i++)); do + if ((SUFFIX_ACTIVE == 1)) && ((i >= SUFFIX_BEGIN)); then + break + fi + if [[ "${BUFFER[$i]}" == $'\n' ]]; then + i=$((i-1)) + break + fi + done + + CURSOR=$i + LBUFFER+=$'\n' + + zvm_reset_repeat_commands $ZVM_MODE_NORMAL o + zvm_select_vi_mode $ZVM_MODE_INSERT +} + +# Open line above +function zvm_open_line_above() { + local i=$CURSOR + + # Break when backward finding out the first newline character. + for ((; i>0; i--)); do + if [[ "${BUFFER[$i]}" == $'\n' ]]; then + break + fi + done + + CURSOR=$i + LBUFFER+=$'\n' + CURSOR=$((CURSOR-1)) + + zvm_reset_repeat_commands $ZVM_MODE_NORMAL O + zvm_select_vi_mode $ZVM_MODE_INSERT +} + +# Replace characters one by one (Replacing mode) +function zvm_vi_replace() { + if [[ $ZVM_MODE == $ZVM_MODE_NORMAL ]]; then + local cursor=$CURSOR + local cache=() + local cmds=() + local key= + + zvm_select_vi_mode $ZVM_MODE_REPLACE + + while :; do + # Redisplay the command line, this is to be called from within + # a user-defined widget to allow changes to become visible + zle -R + + # Read a character for replacing + zvm_update_cursor + read -k 1 key + + # Escape key will break the replacing process, and enter key + # will repace with a newline character. + case $(zvm_escape_non_printed_characters $key) in + '^['|$ZVM_VI_OPPEND_ESCAPE_BINDKEY) break;; + '^M') key=$'\n';; + esac + + # If the key is backspace, we should move backward the cursor + if [[ $key == '' ]]; then + # Cursor position should not be less than zero + if ((cursor > 0)); then + cursor=$((cursor-1)) + fi + + # We should recover the character when cache size is not zero + if ((${#cache[@]} > 0)); then + key=${cache[-1]} + + if [[ $key == '' ]]; then + key= + fi + + cache=(${cache[@]:0:-1}) + BUFFER[$cursor+1]=$key + + # Remove from commands + cmds=(${cmds[@]:0:-1}) + fi + else + # If the key or the character at cursor is a newline character, + # or the cursor is at the end of buffer, we should insert the + # key instead of replacing with the key. + if [[ $key == $'\n' || + $BUFFER[$cursor+1] == $'\n' || + $BUFFER[$cursor+1] == '' + ]]; then + cache+=('') + LBUFFER+=$key + else + cache+=(${BUFFER[$cursor+1]}) + BUFFER[$cursor+1]=$key + fi + + cursor=$((cursor+1)) + + # Push to commands + cmds+=($key) + fi + + # Update next cursor position + CURSOR=$cursor + + zle redisplay + done + + # The cursor position should go back one character after + # exiting the replace mode + zle vi-backward-char + + zvm_select_vi_mode $ZVM_MODE_NORMAL + zvm_reset_repeat_commands $ZVM_MODE R $cmds + elif [[ $ZVM_MODE == $ZVM_MODE_VISUAL ]]; then + zvm_enter_visual_mode V + zvm_vi_change + elif [[ $ZVM_MODE == $ZVM_MODE_VISUAL_LINE ]]; then + zvm_vi_change + fi +} + +# Replace characters in one time +function zvm_vi_replace_chars() { + local cmds=() + local key= + + # Read a character for replacing + zvm_enter_oppend_mode + read -k 1 key + zvm_exit_oppend_mode + + # Escape key will break the replacing process + case $(zvm_escape_non_printed_characters $key) in + $ZVM_VI_OPPEND_ESCAPE_BINDKEY) + zvm_exit_visual_mode + return + esac + + if [[ $ZVM_MODE == $ZVM_MODE_NORMAL ]]; then + cmds+=($key) + BUFFER[$CURSOR+1]=$key + else + local ret=($(zvm_calc_selection)) + local bpos=${ret[1]} epos=${ret[2]} + for ((bpos=bpos+1; bpos<=epos; bpos++)); do + # Newline character is no need to be replaced + if [[ $BUFFER[$bpos] == $'\n' ]]; then + cmds+=($'\n') + continue + fi + + cmds+=($key) + BUFFER[$bpos]=$key + done + zvm_exit_visual_mode + fi + + # Reset the repeat commands + zvm_reset_repeat_commands $ZVM_MODE r $cmds +} + +# Substitute characters of selection +function zvm_vi_substitute() { + # Substitute one character in normal mode + if [[ $ZVM_MODE == $ZVM_MODE_NORMAL ]]; then + BUFFER="${BUFFER:0:$CURSOR}${BUFFER:$((CURSOR+1))}" + zvm_reset_repeat_commands $ZVM_MODE c 0 1 + zvm_select_vi_mode $ZVM_MODE_INSERT + else + zvm_vi_change + fi +} + +# Substitute all characters of a line +function zvm_vi_substitute_whole_line() { + zvm_select_vi_mode $ZVM_MODE_VISUAL_LINE; + zvm_vi_substitute +} + +# Check if cursor is at an empty line +function zvm_is_empty_line() { + local cursor=${1:-$CURSOR} + if [[ ${BUFFER:$cursor:1} == $'\n' && + ${BUFFER:$((cursor-1)):1} == $'\n' ]]; then + return + fi + return 1 +} + +# Get the beginning and end position of selection +function zvm_selection() { + local bpos= epos= + if (( MARK > CURSOR )) ; then + bpos=$CURSOR epos=$((MARK+1)) + else + bpos=$MARK epos=$((CURSOR+1)) + fi + echo $bpos $epos +} + +# Calculate the region of selection +function zvm_calc_selection() { + local ret=($(zvm_selection)) + local bpos=${ret[1]} epos=${ret[2]} cpos= + + # Save the current cursor position + cpos=$bpos + + # Check if it is visual-line mode + if [[ "${1:-$ZVM_MODE}" == $ZVM_MODE_VISUAL_LINE ]]; then + + # Extend the selection to whole line + for ((bpos=$bpos-1; $bpos>0; bpos--)); do + if [[ "${BUFFER:$bpos:1}" == $'\n' ]]; then + bpos=$((bpos+1)) + break + fi + done + for ((epos=$epos-1; $epos<$#BUFFER; epos++)); do + if [[ "${BUFFER:$epos:1}" == $'\n' ]]; then + break + fi + done + + # The begin position must not be less than zero + if (( bpos < 0 )); then + bpos=0 + fi + + ########################################### + # Calculate the new cursor position, here we consider that + # the selection will be delected. + + # Calculate the indent of current cursor line + for ((cpos=$((CURSOR-1)); $cpos>=0; cpos--)); do + [[ "${BUFFER:$cpos:1}" == $'\n' ]] && break + done + + local indent=$((CURSOR-cpos-1)) + + # If the selection includes the last line, the cursor + # will move up to above line. Otherwise the cursor will + # keep in the same line. + + local hpos= # Line head position + local rpos= # Reference position + + if (( $epos < $#BUFFER )); then + # Get the head position of next line + hpos=$((epos+1)) + rpos=$bpos + else + # Get the head position of above line + for ((hpos=$((bpos-2)); $hpos>0; hpos--)); do + if [[ "${BUFFER:$hpos:1}" == $'\n' ]]; then + break + fi + done + if (( $hpos < -1 )); then + hpos=-1 + fi + hpos=$((hpos+1)) + rpos=$hpos + fi + + # Calculate the cursor postion, the indent must be + # less than the line characters. + for ((cpos=$hpos; $cpos<$#BUFFER; cpos++)); do + if [[ "${BUFFER:$cpos:1}" == $'\n' ]]; then + break + fi + if (( $hpos + $indent <= $cpos )); then + break + fi + done + + cpos=$((rpos+cpos-hpos)) + fi + + echo $bpos $epos $cpos +} + +# Yank characters of the marked region +function zvm_yank() { + local ret=($(zvm_calc_selection $1)) + local bpos=$ret[1] epos=$ret[2] cpos=$ret[3] + CUTBUFFER=${BUFFER:$bpos:$((epos-bpos))} + if [[ ${1:-$ZVM_MODE} == $ZVM_MODE_VISUAL_LINE ]]; then + CUTBUFFER=${CUTBUFFER}$'\n' + fi + CURSOR=$bpos MARK=$epos +} + +# Up case of the visual selection +function zvm_vi_up_case() { + local ret=($(zvm_selection)) + local bpos=${ret[1]} epos=${ret[2]} + local content=${BUFFER:$bpos:$((epos-bpos))} + BUFFER="${BUFFER:0:$bpos}${(U)content}${BUFFER:$epos}" + zvm_exit_visual_mode +} + +# Down case of the visual selection +function zvm_vi_down_case() { + local ret=($(zvm_selection)) + local bpos=${ret[1]} epos=${ret[2]} + local content=${BUFFER:$bpos:$((epos-bpos))} + BUFFER="${BUFFER:0:$bpos}${(L)content}${BUFFER:$epos}" + zvm_exit_visual_mode +} + +# Opposite case of the visual selection +function zvm_vi_opp_case() { + local ret=($(zvm_selection)) + local bpos=${ret[1]} epos=${ret[2]} + local content=${BUFFER:$bpos:$((epos-bpos))} + for ((i=1; i<=$#content; i++)); do + if [[ ${content[i]} =~ [A-Z] ]]; then + content[i]=${(L)content[i]} + elif [[ ${content[i]} =~ [a-z] ]]; then + content[i]=${(U)content[i]} + fi + done + BUFFER="${BUFFER:0:$bpos}${content}${BUFFER:$epos}" + zvm_exit_visual_mode +} + +# Yank characters of the visual selection +function zvm_vi_yank() { + zvm_yank + zvm_exit_visual_mode +} + +# Put cutbuffer after the cursor +function zvm_vi_put_after() { + local head= foot= + local content=${CUTBUFFER} + local offset=1 + + if [[ ${content: -1} == $'\n' ]]; then + local pos=${CURSOR} + + # Find the end of current line + for ((; $pos<$#BUFFER; pos++)); do + if [[ ${BUFFER:$pos:1} == $'\n' ]]; then + pos=$pos+1 + break + fi + done + + # Special handling if cursor at an empty line + if zvm_is_empty_line; then + head=${BUFFER:0:$pos} + foot=${BUFFER:$pos} + else + head=${BUFFER:0:$pos} + foot=${BUFFER:$pos} + if [[ $pos == $#BUFFER ]]; then + content=$'\n'${content:0:-1} + pos=$pos+1 + fi + fi + + offset=0 + BUFFER="${head}${content}${foot}" + CURSOR=$pos + else + # Special handling if cursor at an empty line + if zvm_is_empty_line; then + head="${BUFFER:0:$((CURSOR-1))}" + foot="${BUFFER:$CURSOR}" + else + head="${BUFFER:0:$CURSOR}" + foot="${BUFFER:$((CURSOR+1))}" + fi + + BUFFER="${head}${BUFFER:$CURSOR:1}${content}${foot}" + CURSOR=$CURSOR+$#content + fi + + # Reresh display and highlight buffer + zvm_highlight clear + zvm_highlight custom $(($#head+$offset)) $(($#head+$#content+$offset)) +} + +# Put cutbuffer before the cursor +function zvm_vi_put_before() { + local head= foot= + local content=${CUTBUFFER} + + if [[ ${content: -1} == $'\n' ]]; then + local pos=$CURSOR + + # Find the beginning of current line + for ((; $pos>0; pos--)); do + if [[ "${BUFFER:$pos:1}" == $'\n' ]]; then + pos=$pos+1 + break + fi + done + + # Check if it is an empty line + if zvm_is_empty_line; then + head=${BUFFER:0:$((pos-1))} + foot=$'\n'${BUFFER:$pos} + pos=$((pos-1)) + else + head=${BUFFER:0:$pos} + foot=${BUFFER:$pos} + fi + + BUFFER="${head}${content}${foot}" + CURSOR=$pos + else + head="${BUFFER:0:$CURSOR}" + foot="${BUFFER:$((CURSOR+1))}" + BUFFER="${head}${content}${BUFFER:$CURSOR:1}${foot}" + CURSOR=$CURSOR+$#content + CURSOR=$((CURSOR-1)) + fi + + # Reresh display and highlight buffer + zvm_highlight clear + zvm_highlight custom $#head $(($#head+$#content)) +} + +# Delete characters of the visual selection +function zvm_vi_delete() { + local ret=($(zvm_calc_selection)) + local bpos=$ret[1] epos=$ret[2] cpos=$ret[3] + + CUTBUFFER=${BUFFER:$bpos:$((epos-bpos))} + + # Check if it is visual line mode + if [[ $ZVM_MODE == $ZVM_MODE_VISUAL_LINE ]]; then + if (( $epos < $#BUFFER )); then + epos=$epos+1 + elif (( $bpos > 0 )); then + bpos=$bpos-1 + fi + CUTBUFFER=${CUTBUFFER}$'\n' + fi + + BUFFER="${BUFFER:0:$bpos}${BUFFER:$epos}" + CURSOR=$cpos + + zvm_exit_visual_mode ${1:-true} +} + +# Yank characters of the visual selection +function zvm_vi_change() { + local ret=($(zvm_calc_selection)) + local bpos=$ret[1] epos=$ret[2] + + CUTBUFFER=${BUFFER:$bpos:$((epos-bpos))} + + # Check if it is visual line mode + if [[ $ZVM_MODE == $ZVM_MODE_VISUAL_LINE ]]; then + CUTBUFFER=${CUTBUFFER}$'\n' + fi + + BUFFER="${BUFFER:0:$bpos}${BUFFER:$epos}" + CURSOR=$bpos + + # Return when it's repeating mode + $ZVM_REPEAT_MODE && return + + # Reset the repeat commands + if [[ $ZVM_MODE != $ZVM_MODE_NORMAL ]]; then + local npos=0 ncount=0 ccount=0 + # Count the amount of newline character and the amount of + # characters after the last newline character. + while :; do + # Forward find the last newline character's position + npos=$(zvm_substr_pos $CUTBUFFER $'\n' $npos) + if [[ $npos == -1 ]]; then + if (($ncount == 0)); then + ccount=$#CUTBUFFER + fi + break + fi + npos=$((npos+1)) + ncount=$(($ncount + 1)) + ccount=$(($#CUTBUFFER - $npos)) + done + zvm_reset_repeat_commands $ZVM_MODE c $ncount $ccount + fi + + zvm_exit_visual_mode false + zvm_select_vi_mode $ZVM_MODE_INSERT +} + +# Change characters from cursor to the end of current line +function zvm_vi_change_eol() { + local bpos=$CURSOR epos=$CURSOR + + # Find the end of current line + for ((; $epos<$#BUFFER; epos++)); do + if [[ "${BUFFER:$epos:1}" == $'\n' ]]; then + break + fi + done + + CUTBUFFER=${BUFFER:$bpos:$((epos-bpos))} + BUFFER="${BUFFER:0:$bpos}${BUFFER:$epos}" + + zvm_reset_repeat_commands $ZVM_MODE c 0 $#CUTBUFFER + zvm_select_vi_mode $ZVM_MODE_INSERT +} + +# Default handler for unhandled key events +function zvm_default_handler() { + local keys=$(zvm_keys) + local extra_keys=$1 + + # Exit vi mode if keys is the escape keys + case $(zvm_escape_non_printed_characters "$keys") in + '^['|$ZVM_VI_INSERT_ESCAPE_BINDKEY) + zvm_exit_insert_mode + ZVM_KEYS=${extra_keys} + return + ;; + [vV]'^['|[vV]$ZVM_VI_VISUAL_ESCAPE_BINDKEY) + zvm_exit_visual_mode + ZVM_KEYS=${extra_keys} + return + ;; + esac + + case "$KEYMAP" in + vicmd) + case "$keys" in + [vV]c) zvm_vi_change;; + [vV]d) zvm_vi_delete;; + [vV]y) zvm_vi_yank;; + [cdyvV]*) zvm_range_handler "${keys}${extra_keys}";; + *) + for ((i=0;i<$#keys;i++)) do + zvm_navigation_handler ${keys:$i:1} + zvm_highlight + done + ;; + esac + ;; + viins|main) + if [[ "${keys:0:1}" =~ [a-zA-Z0-9\ ] ]]; then + zvm_self_insert "${keys:0:1}" + zle redisplay + ZVM_KEYS="${keys:1}${extra_keys}" + return + fi + ;; + visual) + ;; + esac + + ZVM_KEYS= +} + +# Read keys for retrieving and executing a widget +function zvm_readkeys_handler() { + local keymap=${1} + local keys=${2:-$KEYS} + local key= + local widget= + + # Get the keymap if keymap is empty + if [[ -z $keymap ]]; then + case "$ZVM_MODE" in + $ZVM_MODE_INSERT) keymap=viins;; + $ZVM_MODE_NORMAL) keymap=vicmd;; + $ZVM_MODE_VISUAL|$ZVM_MODE_VISUAL_LINE) keymap=visual;; + esac + fi + + # Read keys and retrieve the widget + zvm_readkeys $keymap $keys + keys=${retval[1]} + widget=${retval[2]} + key=${retval[3]} + + # Escape space in keys + keys=${keys//$ZVM_ESCAPE_SPACE/ } + key=${key//$ZVM_ESCAPE_SPACE/ } + + ZVM_KEYS="${keys}" + + # If the widget is current handler, we should call the default handler + if [[ "${widget}" == "${funcstack[1]}" ]]; then + widget= + fi + + # If the widget isn't matched, we should call the default handler + if [[ -z ${widget} ]]; then + zle zvm_default_handler "$key" + + # Push back to the key input stack + if [[ -n "$ZVM_KEYS" ]]; then + zle -U "$ZVM_KEYS" + fi + else + zle $widget + ZVM_KEYS= + fi +} + +# Find and move cursor to next character +function zvm_find_and_move_cursor() { + local char=$1 + local count=${2:-1} + local forward=${3:-true} + local skip=${4:-false} + local cursor=$CURSOR + + [[ -z $char ]] && return 1 + + # Find the specific character + while :; do + if $forward; then + cursor=$((cursor+1)) + ((cursor > $#BUFFER)) && break + else + cursor=$((cursor-1)) + ((cursor < 0)) && break + fi + if [[ ${BUFFER[$cursor+1]} == $char ]]; then + count=$((count-1)) + fi + ((count == 0)) && break + done + + [[ $count > 0 ]] && return 1 + + # Skip the character + if $skip; then + if $forward; then + cursor=$((cursor-1)) + else + cursor=$((cursor+1)) + fi + fi + + CURSOR=$cursor +} + +# Handle the navigation action +function zvm_navigation_handler() { + # Return if no keys provided + [[ -z $1 ]] && return 1 + + local keys=$1 + local count= + local cmd= + + # Retrieve the calling command + if [[ $keys =~ '^([1-9][0-9]*)?([fFtT].?)$' ]]; then + count=${match[1]:-1} + + # The length of keys must be 2 + if (( ${#match[2]} < 2)); then + zvm_enter_oppend_mode + + read -k 1 cmd + keys+=$cmd + + case "$(zvm_escape_non_printed_characters ${keys[-1]})" in + $ZVM_VI_OPPEND_ESCAPE_BINDKEY) return 1;; + esac + + zvm_exit_oppend_mode + fi + + local forward=true + local skip=false + + [[ ${keys[-2]} =~ '[FT]' ]] && forward=false + [[ ${keys[-2]} =~ '[tT]' ]] && skip=true + + cmd=(zvm_find_and_move_cursor ${keys[-1]} $count $forward $skip) + count=1 + else + count=${keys:0:-1} + case ${keys: -1} in + '^') cmd=(zle vi-first-non-blank);; + '$') cmd=(zle vi-end-of-line);; + ' ') cmd=(zle vi-forward-char);; + '0') cmd=(zle vi-digit-or-beginning-of-line);; + 'h') cmd=(zle vi-backward-char);; + 'j') cmd=(zle down-line-or-history);; + 'k') cmd=(zle up-line-or-history);; + 'l') cmd=(zle vi-forward-char);; + 'w') cmd=(zle vi-forward-word);; + 'W') cmd=(zle vi-forward-blank-word);; + 'e') cmd=(zle vi-forward-word-end);; + 'E') cmd=(zle vi-forward-blank-word-end);; + 'b') cmd=(zle vi-backward-word);; + 'B') cmd=(zle vi-backward-blank-word);; + esac + fi + + # Check widget if the widget is empty + if [[ -z $cmd ]]; then + return 0 + fi + + # Check if keys includes the count + if [[ ! $count =~ ^[0-9]+$ ]]; then + count=1 + fi + + # Call the widget, we can not use variable `i`, since + # some widgets will affect the variable `i`, and it + # will cause an infinite loop. + local init_cursor=$CURSOR + local last_cursor=$CURSOR + local exit_code=0 + for ((c=0; c `word1` + # c2[we] -> `word1 word2` + # ve -> `word1` + # v2e -> `word1 word2` + # vw -> `word1 w` + # v2w -> `word1 word2 w` + # [dy]e -> `word1` + # [dy]2e -> `word1 word2` + # [dy]w -> `word1 ` + # [dy]2w -> `word1 word2 ` + # [cdyv]iw -> `word1` + # [cdyv]aw -> `word1 ` + # [cdyv]2iw -> `word1 ` + # [cdyv]2aw -> `word1 word2 ` + # + # 2. SAMPLE: `a bb c dd`, CURSOR: at `a` + # + # cw -> `a` + # c2w -> `a bb` + # ce -> `a bb` + # c2e -> `a bb c` + # + # 3. SAMPLE: ` .foo. bar. baz.`, CURSOR: at `f` + # + # c[WE] -> `foo.` + # c2[WE] -> `foo. bar.` + # vE -> `foo.` + # v2E -> `foo. bar.` + # vW -> `foo. b` + # v2W -> `foo. bar. b` + # d2W -> `foo. bar. b` + # [dy]E -> `foo.` + # [dy]2E -> `foo. bar.` + # [dy]W -> `foo. ` + # [dy]2W -> `foo. bar. ` + # [cdyv]iW -> `.foo.` + # [cdyv]aW -> `.foo. ` + # [cdyv]2iW -> `.foo. ` + # [cdyv]2aW -> `.foo. bar. ` + # + # 4. SAMPLE: ` .foo.bar.baz.`, CURSOR: at `r` + # + # [cdy]b -> `ba` + # [cdy]B -> `.foo.ba` + # vb -> `bar` + # vB -> `.foo.bar` + # vFf -> `foo.bar` + # vTf -> `oo.bar` + # [cdyv]fz -> `r.baz` + # [cdy]Ff -> `foo.ba` + # [cdyv]tz -> `r.ba` + # [cdy]Tf -> `oo.ba` + # + + # Pre navigation handling + local navkey= + + if [[ $keys =~ '^c([1-9][0-9]*)?[ia][wW]$' ]]; then + count=${match[1]:-1} + navkey=${keys: -2} + elif [[ $keys =~ '^[cdy]([1-9][0-9]*)?[ia][eE]$' ]]; then + navkey= + elif [[ $keys =~ '^c([1-9][0-9]*)?w$' ]]; then + zle vi-backward-char + count=${match[1]:-1} + navkey='e' + elif [[ $keys =~ '^c([1-9][0-9]*)?W$' ]]; then + zle vi-backward-blank-char + count=${match[1]:-1} + navkey='E' + elif [[ $keys =~ '^c([1-9][0-9]*)?e$' ]]; then + count=${match[1]:-1} + navkey='e' + elif [[ $keys =~ '^c([1-9][0-9]*)?E$' ]]; then + count=${match[1]:-1} + navkey='E' + elif [[ $keys =~ '^[cdy]([1-9][0-9]*)?[bB]$' ]]; then + MARK=$((MARK-1)) + count=${match[1]:-1} + navkey=${keys: -1} + elif [[ $keys =~ '^[cdy]([1-9][0-9]*)?([FT].?)$' ]]; then + MARK=$((MARK-1)) + count=${match[1]:-1} + navkey=${match[2]} + elif [[ $keys =~ '^[cdy]([1-9][0-9]*)?j$' ]]; then + # Exit if there is no line below + count=${match[1]:-1} + for ((i=$((CURSOR+1)); i<=$#BUFFER; i++)); do + [[ ${BUFFER[$i]} == $'\n' ]] && navkey='j' + done + elif [[ $keys =~ '^[cdy]([1-9][0-9]*)?k$' ]]; then + # Exit if there is no line above + count=${match[1]:-1} + for ((i=$((CURSOR+1)); i>0; i--)); do + [[ ${BUFFER[$i]} == $'\n' ]] && navkey='k' + done + elif [[ $keys =~ '^[cdy]([1-9][0-9]*)?h$' ]]; then + MARK=$((MARK-1)) + count=${match[1]:-1} + navkey='h' + + # Exit if the cursor is at the beginning of a line + if ((MARK < 0)); then + navkey= + elif [[ ${BUFFER[$MARK+1]} == $'\n' ]]; then + navkey= + fi + elif [[ $keys =~ '^[cdy]([1-9][0-9]*)?l$' ]]; then + count=${match[1]:-1} + count=$((count-1)) + navkey=${count}l + elif [[ $keys =~ '^.([1-9][0-9]*)?([^0-9]+)$' ]]; then + count=${match[1]:-1} + navkey=${match[2]} + else + navkey= + fi + + # Handle navigation + case $navkey in + '') exit_code=1;; + *[ia][wW]) + local widget= + local mark= + + # At least 1 time + if [[ -z $count ]]; then + count=1 + fi + + # Retrieve the widget + case ${navkey: -2} in + iw) widget=select-in-word;; + aw) widget=select-a-word;; + iW) widget=select-in-blank-word;; + aW) widget=select-a-blank-word;; + esac + + # Execute the widget for `count` times, and + # save the `mark` position of the first time + for ((c=0; c= $#BUFFER)); then + break + fi + done + + MARK=$mark + CURSOR=$((CURSOR-1)) + ;; + *) + local retval= + + # Prevent some actions(e.g. w, e) from affecting the auto + # suggestion suffix + BUFFER+=$'\0' + + if zvm_navigation_handler "${count}${navkey}"; then + keys="${keys[1]}${retval}" + else + exit_code=1 + fi + + BUFFER[-1]='' + ;; + esac + + # Check if there is no range selected + if [[ $exit_code != 0 ]]; then + zvm_exit_visual_mode + return + fi + + # Post navigation handling + if [[ $keys =~ '^[cdy]([1-9][0-9]*)?[ia][wW]$' ]]; then + cursor=$MARK + elif [[ $keys =~ '[dy]([1-9][0-9]*)?[wW]' ]]; then + CURSOR=$((CURSOR-1)) + # If the CURSOR is at the newline character, we should + # move backward a character + if [[ "${BUFFER:$CURSOR:1}" == $'\n' ]]; then + CURSOR=$((CURSOR-1)) + fi + else + cursor=$CURSOR + fi + + # Handle operation + case "${keys}" in + c*) zvm_vi_change; cursor=;; + d*) zvm_vi_delete; cursor=;; + y*) zvm_vi_yank;; + [vV]*) cursor=;; + esac + + # Reset the repeat commands when it's changing or deleting + if $ZVM_REPEAT_MODE; then + zvm_exit_visual_mode false + elif [[ $keys =~ '^[cd].*' ]]; then + cmds+=($keys) + zvm_reset_repeat_commands $cmds + fi + + # Change the cursor position if the cursor is not null + if [[ ! -z $cursor ]]; then + CURSOR=$cursor + fi +} + +# Edit command line in EDITOR +function zvm_vi_edit_command_line() { + # Create a temporary file and save the BUFFER to it + local tmp_file=$(mktemp ${ZVM_TMPDIR}zvm.XXXXXX) + echo "$BUFFER" > "$tmp_file" + + # Edit the file with the specific editor, in case of + # the warning about input not from a terminal (e.g. + # vim), we should tell the editor input is from the + # terminal and not from standard input. + $ZVM_VI_EDITOR $tmp_file =0") + local step=$($forward && echo 'i++' || echo 'i--') + for (($init;$condition;$step)); do + if [[ ${1:$i:$slen} == "$2" ]]; then + pos=$i + break + fi + done + echo $pos +} + +# Parse surround from keys +function zvm_parse_surround_keys() { + local keys=${1:-${$(zvm_keys)//$ZVM_ESCAPE_SPACE/ }} + local action= + local surround= + case "${keys}" in + vS*) action=S; surround=${keys:2};; + vsa*) action=a; surround=${keys:3};; + vys*) action=y; surround=${keys:3};; + s[dr]*) action=${keys:1:1}; surround=${keys:2};; + [acd]s*) action=${keys:0:1}; surround=${keys:2};; + [cdvy][ia]*) action=${keys:0:2}; surround=${keys:2};; + esac + echo $action ${surround// /$ZVM_ESCAPE_SPACE} +} + +# Move around code structure (e.g. (..), {..}) +function zvm_move_around_surround() { + local slen= + local bpos=-1 + local epos=-1 + for ((i=$CURSOR;i>=0;i--)); do + # Check if it's one of the surrounds + for s in {\',\",\`,\(,\[,\{,\<}; do + slen=${#s} + if [[ ${BUFFER:$i:$slen} == "$s" ]]; then + bpos=$i + break + fi + done + if (($bpos == -1)); then + continue + fi + # Search the nearest surround + local ret=($(zvm_search_surround "$s")) + if [[ -z ${ret[@]} ]]; then + continue + fi + bpos=${ret[1]} + epos=${ret[2]} + # Move between the openning and close surrounds + if (( $CURSOR > $((bpos-1)) )) && (( $CURSOR < $((bpos+slen)) )); then + CURSOR=$epos + else + CURSOR=$bpos + fi + break + done +} + +# Match the surround pair from the part +function zvm_match_surround() { + local bchar=${1// /$ZVM_ESCAPE_SPACE} + local echar=$bchar + case $bchar in + '(') echar=')';; + '[') echar=']';; + '{') echar='}';; + '<') echar='>';; + ')') bchar='(';echar=')';; + ']') bchar='[';echar=']';; + '}') bchar='{';echar='}';; + '>') bchar='<';echar='>';; + esac + echo $bchar $echar +} + +# Search surround from the string +function zvm_search_surround() { + local ret=($(zvm_match_surround "$1")) + local bchar=${${ret[1]//$ZVM_ESCAPE_SPACE/ }:- } + local echar=${${ret[2]//$ZVM_ESCAPE_SPACE/ }:- } + local bpos=$(zvm_substr_pos $BUFFER $bchar $CURSOR false) + local epos=$(zvm_substr_pos $BUFFER $echar $CURSOR true) + if [[ $bpos == $epos ]]; then + epos=$(zvm_substr_pos $BUFFER $echar $((CURSOR+1)) true) + if [[ $epos == -1 ]]; then + epos=$(zvm_substr_pos $BUFFER $echar $((CURSOR-1)) false) + if [[ $epos != -1 ]]; then + local tmp=$epos; epos=$bpos; bpos=$tmp + fi + fi + fi + if [[ $bpos == -1 ]] || [[ $epos == -1 ]]; then + return + fi + echo $bpos $epos $bchar $echar +} + +# Select surround and highlight it in visual mode +function zvm_select_surround() { + local ret=($(zvm_parse_surround_keys)) + local action=${ret[1]} + local surround=${ret[2]//$ZVM_ESCAPE_SPACE/ } + ret=($(zvm_search_surround ${surround})) + if [[ ${#ret[@]} == 0 ]]; then + zvm_exit_visual_mode + return + fi + local bpos=${ret[1]} + local epos=${ret[2]} + if [[ ${action:1:1} == 'i' ]]; then + ((bpos++)) + else + ((epos++)) + fi + MARK=$bpos; CURSOR=$epos-1 + + # refresh current mode for prompt redraw + zle reset-prompt +} + +# Change surround in vicmd or visual mode +function zvm_change_surround() { + local ret=($(zvm_parse_surround_keys)) + local action=${1:-${ret[1]}} + local surround=${2:-${ret[2]//$ZVM_ESCAPE_SPACE/ }} + local bpos=${3} epos=${4} + local is_appending=false + case $action in + S|y|a) is_appending=true;; + esac + if $is_appending; then + if [[ -z $bpos && -z $epos ]]; then + ret=($(zvm_selection)) + bpos=${ret[1]} epos=${ret[2]} + fi + else + ret=($(zvm_search_surround "$surround")) + (( ${#ret[@]} )) || return + bpos=${ret[1]} epos=${ret[2]} + zvm_highlight custom $bpos $(($bpos+1)) + zvm_highlight custom $epos $(($epos+1)) + fi + local key= + case $action in + c|r) + zvm_enter_oppend_mode + read -k 1 key + zvm_exit_oppend_mode + ;; + S|y|a) key=$surround; [[ -z $@ ]] && zle visual-mode;; + esac + + # Check if it is ESCAPE key ( or ZVM_VI_ESCAPE_BINDKEY) + case "$key" in + ''|"${ZVM_VI_ESCAPE_BINDKEY//\^\[/}") + zvm_highlight clear + return + esac + + # Start changing surround + ret=($(zvm_match_surround "$key")) + local bchar=${${ret[1]//$ZVM_ESCAPE_SPACE/ }:-$key} + local echar=${${ret[2]//$ZVM_ESCAPE_SPACE/ }:-$key} + local value=$($is_appending && echo 0 || echo 1 ) + local head=${BUFFER:0:$bpos} + local body=${BUFFER:$((bpos+value)):$((epos-(bpos+value)))} + local foot=${BUFFER:$((epos+value))} + BUFFER="${head}${bchar}${body}${echar}${foot}" + + # Clear highliht + zvm_highlight clear + + case $action in + S|y|a) zvm_select_vi_mode $ZVM_MODE_NORMAL;; + esac +} + +# Change surround text object +function zvm_change_surround_text_object() { + local ret=($(zvm_parse_surround_keys)) + local action=${ret[1]} + local surround=${ret[2]//$ZVM_ESCAPE_SPACE/ } + ret=($(zvm_search_surround "${surround}")) + if [[ ${#ret[@]} == 0 ]]; then + zvm_select_vi_mode $ZVM_MODE_NORMAL + return + fi + local bpos=${ret[1]} + local epos=${ret[2]} + if [[ ${action:1:1} == 'i' ]]; then + ((bpos++)) + else + ((epos++)) + fi + CUTBUFFER=${BUFFER:$bpos:$(($epos-$bpos))} + case ${action:0:1} in + c) + BUFFER="${BUFFER:0:$bpos}${BUFFER:$epos}" + CURSOR=$bpos + zvm_select_vi_mode $ZVM_MODE_INSERT + ;; + d) + BUFFER="${BUFFER:0:$bpos}${BUFFER:$epos}" + CURSOR=$bpos + ;; + esac +} + +# Repeat last change +function zvm_repeat_change() { + ZVM_REPEAT_MODE=true + + local cmd=${ZVM_REPEAT_COMMANDS[2]} + + # Handle repeat command + case $cmd in + [aioAIO]) zvm_repeat_insert;; + c) zvm_repeat_vi_change;; + [cd]*) zvm_repeat_range_change;; + R) zvm_repeat_replace;; + r) zvm_repeat_replace_chars;; + *) zle vi-repeat-change;; + esac + + zle redisplay + + ZVM_REPEAT_MODE=false +} + +# Repeat inserting characters +function zvm_repeat_insert() { + local cmd=${ZVM_REPEAT_COMMANDS[2]} + local cmds=(${ZVM_REPEAT_COMMANDS[3,-1]}) + + # Pre-handle the command + case $cmd in + a) CURSOR+=1;; + o) + zle vi-backward-char + zle vi-end-of-line + LBUFFER+=$'\n' + ;; + A) + zle vi-end-of-line + CURSOR=$((CURSOR+1)) + ;; + I) zle vi-first-non-blank;; + O) + zle vi-digit-or-beginning-of-line + LBUFFER+=$'\n' + CURSOR=$((CURSOR-1)) + ;; + esac + + # Insert characters + for ((i=1; i<=${#cmds[@]}; i++)); do + cmd="${cmds[$i]}" + + # Hanlde the backspace command + if [[ $cmd == '' ]]; then + if (($#LBUFFER > 0)); then + LBUFFER=${LBUFFER:0:-1} + fi + continue + fi + + # The length of character should be 1 + if (($#cmd == 1)); then + LBUFFER+=$cmd + fi + done +} + +# Repeat changing visual characters +function zvm_repeat_vi_change() { + local mode=${ZVM_REPEAT_COMMANDS[1]} + local cmds=(${ZVM_REPEAT_COMMANDS[3,-1]}) + + # Backward move cursor to the beginning of line + if [[ $mode == $ZVM_MODE_VISUAL_LINE ]]; then + zle vi-digit-or-beginning-of-line + fi + + local ncount=${cmds[1]} + local ccount=${cmds[2]} + local pos=$CURSOR epos=$CURSOR + + # Forward expand the characters to the Nth newline character + for ((i=0; i<$ncount; i++)); do + pos=$(zvm_substr_pos $BUFFER $'\n' $pos) + if [[ $pos == -1 ]]; then + epos=$#BUFFER + break + fi + pos=$((pos+1)) + epos=$pos + done + + # Forward expand the remaining characters + for ((i=0; i<$ccount; i++)); do + local char=${BUFFER[$epos+i]} + if [[ $char == $'\n' || $char == '' ]]; then + ccount=$i + break + fi + done + + epos=$((epos+ccount)) + RBUFFER=${RBUFFER:$((epos-CURSOR))} +} + +# Repeat changing a range of characters +function zvm_repeat_range_change() { + local cmd=${ZVM_REPEAT_COMMANDS[2]} + + # Remove characters + zvm_range_handler $cmd + + # Insert characters + zvm_repeat_insert +} + +# Repeat replacing +function zvm_repeat_replace() { + local cmds=(${ZVM_REPEAT_COMMANDS[3,-1]}) + local cmd= + local cursor=$CURSOR + + for ((i=1; i<=${#cmds[@]}; i++)); do + cmd="${cmds[$i]}" + + # If the cmd or the character at cursor is a newline character, + # or the cursor is at the end of buffer, we should insert the + # cmd instead of replacing with the cmd. + if [[ $cmd == $'\n' || + $BUFFER[$cursor+1] == $'\n' || + $BUFFER[$cursor+1] == '' + ]]; then + LBUFFER+=$cmd + else + BUFFER[$cursor+1]=$cmd + fi + + cursor=$((cursor+1)) + CURSOR=$cursor + done + + # The cursor position should go back one character after + # exiting the replace mode + zle vi-backward-char +} + +# Repeat replacing characters +function zvm_repeat_replace_chars() { + local mode=${ZVM_REPEAT_COMMANDS[1]} + local cmds=(${ZVM_REPEAT_COMMANDS[3,-1]}) + local cmd= + + # Replacment of visual mode should move backward cursor to the + # begin of current line, and replacing to the end of last line. + if [[ $mode == $ZVM_MODE_VISUAL_LINE ]]; then + zle vi-digit-or-beginning-of-line + cmds+=($'\n') + fi + + local cursor=$((CURSOR+1)) + + for ((i=1; i<=${#cmds[@]}; i++)); do + cmd="${cmds[$i]}" + + # If we meet a newline character in the buffer, we should keep + # stop replacing, util we meet next newline character command. + if [[ ${BUFFER[$cursor]} == $'\n' ]]; then + if [[ $cmd == $'\n' ]]; then + cursor=$((cursor+1)) + fi + continue + fi + + # A newline character command should keep replacing with last + # character, until we meet a newline character in the buffer, + # then we use next command. + if [[ $cmd == $'\n' ]]; then + i=$((i-1)) + cmd="${cmds[$i]}" + fi + + # The length of character should be 1 + if (($#cmd == 1)); then + BUFFER[$cursor]="${cmd}" + fi + + cursor=$((cursor+1)) + + # Break when it reaches the end + if ((cursor > $#BUFFER)); then + break + fi + done +} + +# Select a word under the cursor +function zvm_select_in_word() { + local cursor=${1:-$CURSOR} + local buffer=${2:-$BUFFER} + local bpos=$cursor epos=$cursor + local pattern='[0-9a-zA-Z_]' + + if ! [[ "${buffer:$cursor:1}" =~ $pattern ]]; then + pattern="[^${pattern:1:-1} ]" + fi + + for ((; $bpos>=0; bpos--)); do + [[ "${buffer:$bpos:1}" =~ $pattern ]] || break + done + for ((; $epos<$#buffer; epos++)); do + [[ "${buffer:$epos:1}" =~ $pattern ]] || break + done + + bpos=$((bpos+1)) + + # The ending position must be greater than 0 + if (( epos > 0 )); then + epos=$((epos-1)) + fi + + echo $bpos $epos +} + +# Switch keyword +function zvm_switch_keyword() { + local bpos= epos= cpos=$CURSOR + + # Cursor position cases: + # + # 1. Cursor on symbol: + # 2+2 => + + # 2-2 => - + # 2 + 2 => + + # 2 +2 => +2 + # 2 -2 => -2 + # 2 -a => -a + # + # 2. Cursor on number or alpha: + # 2+2 => +2 + # 2-2 => -2 + # 2 + 2 => 2 + # 2 +2 => +2 + # 2 -2 => -2 + # 2 -a => -a + + # If cursor is on the `+` or `-`, we need to check if it is a + # number with a sign or an operator, only the number needs to + # forward the cursor. + if [[ ${BUFFER:$cpos:2} =~ [+-][0-9] ]]; then + if [[ $cpos == 0 || ${BUFFER:$((cpos-1)):1} =~ [^0-9] ]]; then + cpos=$((cpos+1)) + fi + + # If cursor is on the `+` or `-`, we need to check if it is a + # short option, only the short option needs to forward the cursor. + elif [[ ${BUFFER:$cpos:2} =~ [+-][a-zA-Z] ]]; then + if [[ $cpos == 0 || ${BUFFER:$((cpos-1)):1} == ' ' ]]; then + cpos=$((cpos+1)) + fi + fi + + local result=($(zvm_select_in_word $cpos)) + bpos=${result[1]} epos=$((${result[2]}+1)) + + # Move backward the cursor + if [[ $bpos != 0 && ${BUFFER:$((bpos-1)):1} == [+-] ]]; then + bpos=$((bpos-1)) + fi + + local word=${BUFFER:$bpos:$((epos-bpos))} + local keys=$(zvm_keys) + + if [[ $keys == '' ]]; then + local increase=true + else + local increase=false + fi + + # Execute extra commands + for handler in $zvm_switch_keyword_handlers; do + if ! zvm_exist_command ${handler}; then + continue + fi + + result=($($handler $word $increase)); + + if (( $#result == 0 )); then + continue + fi + + epos=$(( bpos + ${result[3]} )) + bpos=$(( bpos + ${result[2]} )) + + if (( cpos < bpos )) || (( cpos >= epos )); then + continue + fi + + BUFFER="${BUFFER:0:$bpos}${result[1]}${BUFFER:$epos}" + CURSOR=$((bpos + ${#result[1]} - 1)) + + zle reset-prompt + return + done +} + +# Switch number keyword +function zvm_switch_number { + local word=$1 + local increase=${2:-true} + local result= bpos= epos= + + # Hexadecimal + if [[ $word =~ [^0-9]?(0[xX][0-9a-fA-F]*) ]]; then + local number=${match[1]} + local prefix=${number:0:2} + bpos=$((mbegin-1)) epos=$mend + + # Hexadecimal cases: + # + # 1. Increment: + # 0xDe => 0xdf + # 0xdE => 0xDF + # 0xde0 => 0xddf + # 0xffffffffffffffff => 0x0000000000000000 + # 0X9 => 0XA + # 0Xdf => 0Xe0 + # + # 2. Decrement: + # 0xdE0 => 0xDDF + # 0xffFf0 => 0xfffef + # 0xfffF0 => 0xFFFEF + # 0x0 => 0xffffffffffffffff + # 0X0 => 0XFFFFFFFFFFFFFFFF + # 0Xf => 0Xe + + local lower=true + if [[ $number =~ [A-Z][0-9]*$ ]]; then + lower=false + fi + + # Fix the number truncated after 15 digits issue + if (( $#number > 17 )); then + local d=$(($#number - 15)) + local h=${number:0:$d} + number="0x${number:$d}" + fi + + local p=$(($#number - 2)) + + if $increase; then + if (( $number == 0x${(l:15::f:)} )); then + h=$(([##16]$h+1)) + h=${h: -1} + number=${(l:15::0:)} + else + h=${h:2} + number=$(([##16]$number + 1)) + fi + else + if (( $number == 0 )); then + if (( ${h:-0} == 0 )); then + h=f + else + h=$(([##16]$h-1)) + h=${h: -1} + fi + number=${(l:15::f:)} + else + h=${h:2} + number=$(([##16]$number - 1)) + fi + fi + + # Padding with zero + if (( $#number < $p )); then + number=${(l:$p::0:)number} + fi + + result="${h}${number}" + + # Transform the case + if $lower; then + result="${(L)result}" + fi + + result="${prefix}${result}" + + # Binary + elif [[ $word =~ [^0-9]?(0[bB][01]*) ]]; then + # Binary cases: + # + # 1. Increment: + # 0b1 => 0b10 + # 0x1111111111111111111111111111111111111111111111111111111111111111 => + # 0x0000000000000000000000000000000000000000000000000000000000000000 + # 0B0 => 0B1 + # + # 2. Decrement: + # 0b1 => 0b0 + # 0b100 => 0b011 + # 0B010 => 0B001 + # 0b0 => + # 0x1111111111111111111111111111111111111111111111111111111111111111 + + local number=${match[1]} + local prefix=${number:0:2} + bpos=$((mbegin-1)) epos=$mend + + # Fix the number truncated after 63 digits issue + if (( $#number > 65 )); then + local d=$(($#number - 63)) + local h=${number:0:$d} + number="0b${number:$d}" + fi + + local p=$(($#number - 2)) + + if $increase; then + if (( $number == 0b${(l:63::1:)} )); then + h=$(([##2]$h+1)) + h=${h: -1} + number=${(l:63::0:)} + else + h=${h:2} + number=$(([##2]$number + 1)) + fi + else + if (( $number == 0b0 )); then + if (( ${h:-0} == 0 )); then + h=1 + else + h=$(([##2]$h-1)) + h=${h: -1} + fi + number=${(l:63::1:)} + else + h=${h:2} + number=$(([##2]$number - 1)) + fi + fi + + # Padding with zero + if (( $#number < $p )); then + number=${(l:$p::0:)number} + fi + + result="${prefix}${number}" + + # Decimal + elif [[ $word =~ ([-+]?[0-9]+) ]]; then + # Decimal cases: + # + # 1. Increment: + # 0 => 1 + # 99 => 100 + # + # 2. Decrement: + # 0 => -1 + # 10 => 9 + # aa1230xa => aa1231xa + # aa1230bb => aa1231bb + # aa123a0bb => aa124a0bb + + local number=${match[1]} + bpos=$((mbegin-1)) epos=$mend + + if $increase; then + result=$(($number + 1)) + else + result=$(($number - 1)) + fi + + # Check if need the plus sign prefix + if [[ ${word:$bpos:1} == '+' ]]; then + result="+${result}" + fi + fi + + if [[ $result ]]; then + echo $result $bpos $epos + fi +} + +# Switch boolean keyword +function zvm_switch_boolean() { + local word=$1 + local increase=$2 + local result= + local bpos=0 epos=$#word + + # Remove option prefix + if [[ $word =~ (^[+-]{0,2}) ]]; then + local prefix=${match[1]} + bpos=$mend + word=${word:$bpos} + fi + + case ${(L)word} in + true) result=false;; + false) result=true;; + yes) result=no;; + no) result=yes;; + on) result=off;; + off) result=on;; + y) result=n;; + n) result=y;; + t) result=f;; + f) result=t;; + *) return;; + esac + + # Transform the case + if [[ $word =~ ^[A-Z]+$ ]]; then + result=${(U)result} + elif [[ $word =~ ^[A-Z] ]]; then + result=${(U)result:0:1}${result:1} + fi + + echo $result $bpos $epos +} + +# Switch weekday keyword +function zvm_switch_weekday() { + local word=$1 + local increase=$2 + local result=${(L)word} + local weekdays=( + sunday + monday + tuesday + wednesday + thursday + friday + saturday + ) + + local i=1 + + for ((; i<=${#weekdays[@]}; i++)); do + if [[ ${weekdays[i]:0:$#result} == ${result} ]]; then + result=${weekdays[i]} + break + fi + done + + # Return if no match + if (( i > ${#weekdays[@]} )); then + return + fi + + if $increase; then + if (( i == ${#weekdays[@]} )); then + i=1 + else + i=$((i+1)) + fi + else + if (( i == 1 )); then + i=${#weekdays[@]} + else + i=$((i-1)) + fi + fi + + # Abbreviation + if (( $#result == $#word )); then + result=${weekdays[i]} + else + result=${weekdays[i]:0:$#word} + fi + + # Transform the case + if [[ $word =~ ^[A-Z]+$ ]]; then + result=${(U)result} + elif [[ $word =~ ^[A-Z] ]]; then + result=${(U)result:0:1}${result:1} + fi + + echo $result 0 $#word +} + +# Switch operator keyword +function zvm_switch_operator() { + local word=$1 + local increase=$2 + local result= + + case ${(L)word} in + '&&') result='||';; + '||') result='&&';; + '++') result='--';; + '--') result='++';; + '==') result='!=';; + '!=') result='==';; + '===') result='!==';; + '!==') result='===';; + '+') result='-';; + '-') result='*';; + '*') result='/';; + '/') result='+';; + 'and') result='or';; + 'or') result='and';; + *) return;; + esac + + # Transform the case + if [[ $word =~ ^[A-Z]+$ ]]; then + result=${(U)result} + elif [[ $word =~ ^[A-Z] ]]; then + result=${(U)result:0:1}${result:1} + fi + + # Since the `echo` command can not print the character + # `-`, here we use `printf` command alternatively. + printf "%s 0 $#word" "${result}" +} + +# Switch month keyword +function zvm_switch_month() { + local word=$1 + local increase=$2 + local result=${(L)word} + local months=( + january + february + march + april + may + june + july + august + september + october + november + december + ) + + local i=1 + + for ((; i<=${#months[@]}; i++)); do + if [[ ${months[i]:0:$#result} == ${result} ]]; then + result=${months[i]} + break + fi + done + + # Return if no match + if (( i > ${#months[@]} )); then + return + fi + + if $increase; then + if (( i == ${#months[@]} )); then + i=1 + else + i=$((i+1)) + fi + else + if (( i == 1 )); then + i=${#months[@]} + else + i=$((i-1)) + fi + fi + + # Abbreviation + if (( $#result == $#word )); then + result=${months[i]} + else + result=${months[i]:0:$#word} + fi + + # Transform the case + if [[ $word =~ ^[A-Z]+$ ]]; then + result=${(U)result} + elif [[ $word =~ ^[A-Z] ]]; then + result=${(U)result:0:1}${result:1} + fi + + echo $result 0 $#word +} + +# Highlight content +function zvm_highlight() { + local opt=${1:-mode} + local region=() + local redraw=false + + # Hanlde region by the option + case "$opt" in + mode) + case "$ZVM_MODE" in + $ZVM_MODE_VISUAL|$ZVM_MODE_VISUAL_LINE) + local ret=($(zvm_calc_selection)) + local bpos=$ret[1] epos=$ret[2] + region=("$((bpos)) $((epos)) bg=$ZVM_VI_HIGHLIGHT_BACKGROUND") + ;; + esac + redraw=true + ;; + custom) + region=("${ZVM_REGION_HIGHLIGHT[@]}") + region+=("$2 $3 bg=${4:-$ZVM_VI_HIGHLIGHT_BACKGROUND}") + redraw=true + ;; + clear) + zle redisplay + redraw=true + ;; + redraw) redraw=true;; + esac + + # Update region highlight + if (( $#region > 0 )) || [[ "$opt" == 'clear' ]]; then + + # Remove old region highlight + local rawhighlight=() + for ((i=1; i<=${#region_highlight[@]}; i++)); do + local raw=true + for ((j=1; j<=${#ZVM_REGION_HIGHLIGHT[@]}; j++)); do + if [[ "${region_highlight[i]}" == "${ZVM_REGION_HIGHLIGHT[j]}" ]]; then + raw=false + break + fi + done + if $raw; then + rawhighlight+=("${region_highlight[i]}") + fi + done + + # Assign new region highlight + ZVM_REGION_HIGHLIGHT=("${region[@]}") + region_highlight=("${rawhighlight[@]}" "${ZVM_REGION_HIGHLIGHT[@]}") + fi + + # Check if we need to refresh the region highlight + if $redraw; then + zle -R + fi +} + +# Enter the visual mode +function zvm_enter_visual_mode() { + local mode= + local last_mode=$ZVM_MODE + local last_region= + + # Exit the visual mode + case $last_mode in + $ZVM_MODE_VISUAL|$ZVM_MODE_VISUAL_LINE) + last_region=($MARK $CURSOR) + zvm_exit_visual_mode + ;; + esac + + case "${1:-$(zvm_keys)}" in + v) mode=$ZVM_MODE_VISUAL;; + V) mode=$ZVM_MODE_VISUAL_LINE;; + esac + + # We should just exit the visual mdoe if current mode + # is the same with last visual mode + if [[ $last_mode == $mode ]]; then + return + fi + + zvm_select_vi_mode $mode + + # Recover the region when changing to another visual mode + if [[ -n $last_region ]]; then + MARK=$last_region[1] + CURSOR=$last_region[2] + zle redisplay + fi +} + +# Exit the visual mode +function zvm_exit_visual_mode() { + case "$ZVM_MODE" in + $ZVM_MODE_VISUAL) zle visual-mode;; + $ZVM_MODE_VISUAL_LINE) zle visual-line-mode;; + esac + zvm_highlight clear + zvm_select_vi_mode $ZVM_MODE_NORMAL ${1:-true} +} + +# Enter the vi insert mode +function zvm_enter_insert_mode() { + local keys=${1:-$(zvm_keys)} + + if [[ $keys == 'i' ]]; then + ZVM_INSERT_MODE='i' + elif [[ $keys == 'a' ]]; then + ZVM_INSERT_MODE='a' + if ! zvm_is_empty_line; then + CURSOR=$((CURSOR+1)) + fi + else + return + fi + + zvm_reset_repeat_commands $ZVM_MODE_NORMAL $ZVM_INSERT_MODE + zvm_select_vi_mode $ZVM_MODE_INSERT +} + +# Exit the vi insert mode +function zvm_exit_insert_mode() { + ZVM_INSERT_MODE= + zvm_select_vi_mode $ZVM_MODE_NORMAL +} + +# Enter the vi operator pending mode +function zvm_enter_oppend_mode() { + ZVM_OPPEND_MODE=true + ${1:-true} && zvm_update_cursor +} + +# Exit the vi operator pending mode +function zvm_exit_oppend_mode() { + ZVM_OPPEND_MODE=false + ${1:-true} && zvm_update_cursor +} + +# Insert at the beginning of the line +function zvm_insert_bol() { + ZVM_INSERT_MODE='I' + zle vi-first-non-blank + zvm_select_vi_mode $ZVM_MODE_INSERT + zvm_reset_repeat_commands $ZVM_MODE_NORMAL $ZVM_INSERT_MODE +} + +# Append at the end of the line +function zvm_append_eol() { + ZVM_INSERT_MODE='A' + zle vi-end-of-line + CURSOR=$((CURSOR+1)) + zvm_select_vi_mode $ZVM_MODE_INSERT + zvm_reset_repeat_commands $ZVM_MODE_NORMAL $ZVM_INSERT_MODE +} + +# Self insert content to cursor position +function zvm_self_insert() { + local keys=${1:-$KEYS} + RBUFFER="${keys}${RBUFFER}" + CURSOR=$((CURSOR+1)) +} + +# Reset the repeat commands +function zvm_reset_repeat_commands() { + ZVM_REPEAT_RESET=true + ZVM_REPEAT_COMMANDS=($@) +} + +# Select vi mode +function zvm_select_vi_mode() { + local mode=$1 + local reset_prompt=${2:-true} + + # Check if current mode is the same with the new mode + if [[ $mode == "$ZVM_MODE" ]]; then + zvm_update_cursor + mode= + fi + + zvm_exec_commands 'before_select_vi_mode' + + # Some plugins would reset the prompt when we select the + # keymap, so here we disable the reset-prompt temporarily. + ZVM_RESET_PROMPT_DISABLED=true + + # Exit operator pending mode + if $ZVM_OPPEND_MODE; then + zvm_exit_oppend_mode false + fi + + case $mode in + $ZVM_MODE_NORMAL) + ZVM_MODE=$ZVM_MODE_NORMAL + zvm_update_cursor + zle vi-cmd-mode + ;; + $ZVM_MODE_INSERT) + ZVM_MODE=$ZVM_MODE_INSERT + zvm_update_cursor + zle vi-insert + ;; + $ZVM_MODE_VISUAL) + ZVM_MODE=$ZVM_MODE_VISUAL + zvm_update_cursor + zle visual-mode + ;; + $ZVM_MODE_VISUAL_LINE) + ZVM_MODE=$ZVM_MODE_VISUAL_LINE + zvm_update_cursor + zle visual-line-mode + ;; + $ZVM_MODE_REPLACE) + ZVM_MODE=$ZVM_MODE_REPLACE + zvm_enter_oppend_mode + ;; + esac + + # This aspect provides you a moment to do something, such as + # update the cursor, prompt and so on. + zvm_exec_commands 'after_select_vi_mode' + + # Enable reset-prompt + ZVM_RESET_PROMPT_DISABLED=false + + $reset_prompt && zle reset-prompt + + # Start the lazy keybindings when the first time entering the + # normal mode, when the mode is the same as last mode, we get + # empty value for $mode. + if [[ $mode == $ZVM_MODE_NORMAL ]] && + (( $#ZVM_LAZY_KEYBINDINGS_LIST > 0 )); then + + zvm_exec_commands 'before_lazy_keybindings' + + # Here we should unset the list for normal keybindings + local list=("${ZVM_LAZY_KEYBINDINGS_LIST[@]}") + unset ZVM_LAZY_KEYBINDINGS_LIST + + for r in "${list[@]}"; do + eval "zvm_bindkey ${r}" + done + + zvm_exec_commands 'after_lazy_keybindings' + fi +} + +# Reset prompt +function zvm_reset_prompt() { + $ZVM_RESET_PROMPT_DISABLED && return + local -i retval + if [[ -z "$rawfunc" ]]; then + zle .reset-prompt -- "$@" + else + $rawfunc -- "$@" + fi + return retval +} + +# Undo action in vi insert mode +# +# CTRL-U Remove all characters between the cursor position and +# the beginning of the line. Previous versions of vim +# deleted all characters on the line. +function zvm_viins_undo() { + if [[ $ZVM_VI_INS_LEGACY_UNDO ]]; then + zvm_kill_line + else + zvm_backward_kill_line + fi +} + +# Change cursor to support for inside/outside tmux +function zvm_set_cursor() { + # Term of vim isn't supported + if [[ -n $VIMRUNTIME ]]; then + return + fi + + # Tmux sequence + if [[ -z $TMUX ]]; then + echo -ne "$1" + else + echo -ne "\ePtmux;\e\e$1\e\\" + fi +} + +# Get the escape sequence of cursor style +function zvm_cursor_style() { + local style=${(L)1} + local term=${2:-$ZVM_TERM} + + case $term in + # For xterm and rxvt and their derivatives use the same escape + # sequences as the VT520 terminal. And screen, konsole, alacritty + # and st implement a superset of VT100 and VT100, they support + # 256 colors the same way xterm does. + xterm*|rxvt*|screen*|tmux*|konsole*|alacritty*|st*) + case $style in + $ZVM_CURSOR_USER_DEFAULT) style='\e[0 q';; + $ZVM_CURSOR_BLOCK) style='\e[2 q';; + $ZVM_CURSOR_UNDERLINE) style='\e[4 q';; + $ZVM_CURSOR_BEAM) style='\e[6 q';; + $ZVM_CURSOR_BLINKING_BLOCK) style='\e[1 q';; + $ZVM_CURSOR_BLINKING_UNDERLINE) style='\e[3 q';; + $ZVM_CURSOR_BLINKING_BEAM) style='\e[5 q';; + esac + ;; + *) style='\e[0 q';; + esac + + echo $style +} + +# Update the cursor according current vi mode +function zvm_update_cursor() { + + # Check if we need to update the cursor style + $ZVM_CURSOR_STYLE_ENABLED || return + + local mode=$1 + local shape= + + # Check if it is operator pending mode + if $ZVM_OPPEND_MODE; then + mode=opp + shape=$(zvm_cursor_style $ZVM_OPPEND_MODE_CURSOR) + fi + + # Get cursor shape by the mode + case "${mode:-$ZVM_MODE}" in + $ZVM_MODE_NORMAL) + shape=$(zvm_cursor_style $ZVM_NORMAL_MODE_CURSOR) + ;; + $ZVM_MODE_INSERT) + shape=$(zvm_cursor_style $ZVM_INSERT_MODE_CURSOR) + ;; + $ZVM_MODE_VISUAL) + shape=$(zvm_cursor_style $ZVM_VISUAL_MODE_CURSOR) + ;; + $ZVM_MODE_VISUAL_LINE) + shape=$(zvm_cursor_style $ZVM_VISUAL_LINE_MODE_CURSOR) + ;; + esac + + if [[ $shape ]]; then + zvm_set_cursor $shape + fi +} + +# Updates highlight region +function zvm_update_highlight() { + case "$ZVM_MODE" in + $ZVM_MODE_VISUAL|$ZVM_MODE_VISUAL_LINE) + zvm_highlight + ;; + esac +} + +# Updates repeat commands +function zvm_update_repeat_commands() { + # We don't need to update the repeat commands if current + # mode is already the repeat mode. + $ZVM_REPEAT_MODE && return + + # We don't need to update the repeat commands if it is + # reseting the repeat commands. + if $ZVM_REPEAT_RESET; then + ZVM_REPEAT_RESET=false + return + fi + + # We update the repeat commands when it's the insert mode + [[ $ZVM_MODE == $ZVM_MODE_INSERT ]] || return + + local char=$KEYS + + # If current key is an arrow key, we should do something + if [[ "$KEYS" =~ '\[[ABCD]' ]]; then + # If last key is also an arrow key, we just replace it + if [[ ${ZVM_REPEAT_COMMANDS[-1]} =~ '\[[ABCD]' ]]; then + ZVM_REPEAT_COMMANDS=(${ZVM_REPEAT_COMMANDS[@]:0:-1}) + fi + else + # If last command is arrow key movement, we should reset + # the repeat commands with i(nsert) command + if [[ ${ZVM_REPEAT_COMMANDS[-1]} =~ '\[[ABCD]' ]]; then + zvm_reset_repeat_commands $ZVM_MODE_NORMAL i + fi + char=${BUFFER[$CURSOR]} + fi + + # If current key is backspace key, we should remove last + # one, until it has only the mode and inital command + if [[ "$KEYS" == '' ]]; then + if ((${#ZVM_REPEAT_COMMANDS[@]} > 2)) && + [[ ${ZVM_REPEAT_COMMANDS[-1]} != '' ]]; then + ZVM_REPEAT_COMMANDS=(${ZVM_REPEAT_COMMANDS[@]:0:-1}) + elif (($#LBUFFER > 0)); then + ZVM_REPEAT_COMMANDS+=($KEYS) + fi + else + ZVM_REPEAT_COMMANDS+=($char) + fi +} + +# Updates editor information when line pre redraw +function zvm_zle-line-pre-redraw() { + # Fix cursor style is not updated in tmux environment, when + # there are one more panel in the same window, the program + # in other panel could change the cursor shape, we need to + # update cursor style when line is redrawing. + zvm_update_cursor + zvm_update_highlight + zvm_update_repeat_commands +} + +# Start every prompt in the correct vi mode +function zvm_zle-line-init() { + # Save last mode + local mode=${ZVM_MODE:-$ZVM_MODE_INSERT} + + # It's neccessary to set to insert mode when line init + # and we don't need to reset prompt. + zvm_select_vi_mode $ZVM_MODE_INSERT false + + # Select line init mode and reset prompt + case ${ZVM_LINE_INIT_MODE:-$mode} in + $ZVM_MODE_INSERT) zvm_select_vi_mode $ZVM_MODE_INSERT;; + *) zvm_select_vi_mode $ZVM_MODE_NORMAL;; + esac +} + +# Restore the user default cursor style after prompt finish +function zvm_zle-line-finish() { + # When we start a program (e.g. vim, bash, etc.) from the + # command line, the cursor style is inherited by other + # programs, so that we need to reset the cursor style to + # default before executing a command and set the custom + # style again when the command exits. This way makes any + # other interactive CLI application would not be affected + # by it. + local shape=$(zvm_cursor_style $ZVM_CURSOR_USER_DEFAULT) + zvm_set_cursor $shape +} + +# Initialize vi-mode for widgets, keybindings, etc. +function zvm_init() { + zvm_exec_commands 'before_init' + + # Correct the readkey engine + case $ZVM_READKEY_ENGINE in + $ZVM_READKEY_ENGINE_NEX|$ZVM_READKEY_ENGINE_ZLE);; + *) + echo -n "Warning: Unsupported readkey engine! " + echo "ZVM_READKEY_ENGINE=$ZVM_READKEY_ENGINE" + ZVM_READKEY_ENGINE=$ZVM_READKEY_ENGINE_DEFAULT + ;; + esac + + # Reduce ESC delay (zle default is 0.4 seconds) + # Set to 0.01 second delay for taking over the key input processing + case $ZVM_READKEY_ENGINE in + $ZVM_READKEY_ENGINE_NEX) KEYTIMEOUT=1;; + $ZVM_READKEY_ENGINE_ZLE) KEYTIMEOUT=$(($ZVM_KEYTIMEOUT*100));; + esac + + # Create User-defined widgets + zvm_define_widget zvm_default_handler + zvm_define_widget zvm_readkeys_handler + zvm_define_widget zvm_backward_kill_region + zvm_define_widget zvm_backward_kill_line + zvm_define_widget zvm_forward_kill_line + zvm_define_widget zvm_kill_line + zvm_define_widget zvm_viins_undo + zvm_define_widget zvm_select_surround + zvm_define_widget zvm_change_surround + zvm_define_widget zvm_move_around_surround + zvm_define_widget zvm_change_surround_text_object + zvm_define_widget zvm_enter_insert_mode + zvm_define_widget zvm_exit_insert_mode + zvm_define_widget zvm_enter_visual_mode + zvm_define_widget zvm_exit_visual_mode + zvm_define_widget zvm_enter_oppend_mode + zvm_define_widget zvm_exit_oppend_mode + zvm_define_widget zvm_exchange_point_and_mark + zvm_define_widget zvm_open_line_below + zvm_define_widget zvm_open_line_above + zvm_define_widget zvm_insert_bol + zvm_define_widget zvm_append_eol + zvm_define_widget zvm_self_insert + zvm_define_widget zvm_vi_replace + zvm_define_widget zvm_vi_replace_chars + zvm_define_widget zvm_vi_substitute + zvm_define_widget zvm_vi_substitute_whole_line + zvm_define_widget zvm_vi_change + zvm_define_widget zvm_vi_change_eol + zvm_define_widget zvm_vi_delete + zvm_define_widget zvm_vi_yank + zvm_define_widget zvm_vi_put_after + zvm_define_widget zvm_vi_put_before + zvm_define_widget zvm_vi_up_case + zvm_define_widget zvm_vi_down_case + zvm_define_widget zvm_vi_opp_case + zvm_define_widget zvm_vi_edit_command_line + zvm_define_widget zvm_repeat_change + zvm_define_widget zvm_switch_keyword + + # Override standard widgets + zvm_define_widget zle-line-pre-redraw zvm_zle-line-pre-redraw + + # Ensure the correct cursor style when an interactive program + # (e.g. vim, bash, etc.) starts and exits + zvm_define_widget zle-line-init zvm_zle-line-init + zvm_define_widget zle-line-finish zvm_zle-line-finish + + # Override reset-prompt widget + zvm_define_widget reset-prompt zvm_reset_prompt + + # All Key bindings + # Emacs-like bindings + # Normal editing + zvm_bindkey viins '^A' beginning-of-line + zvm_bindkey viins '^E' end-of-line + zvm_bindkey viins '^B' backward-char + zvm_bindkey viins '^F' forward-char + zvm_bindkey viins '^K' zvm_forward_kill_line + zvm_bindkey viins '^W' backward-kill-word + zvm_bindkey viins '^U' zvm_viins_undo + zvm_bindkey viins '^Y' yank + zvm_bindkey viins '^_' undo + + # History search + zvm_bindkey viins '^R' history-incremental-search-backward + zvm_bindkey viins '^S' history-incremental-search-forward + zvm_bindkey viins '^P' up-line-or-history + zvm_bindkey viins '^N' down-line-or-history + + # Insert mode + zvm_bindkey vicmd 'i' zvm_enter_insert_mode + zvm_bindkey vicmd 'a' zvm_enter_insert_mode + zvm_bindkey vicmd 'I' zvm_insert_bol + zvm_bindkey vicmd 'A' zvm_append_eol + + # Other key bindings + zvm_bindkey vicmd 'v' zvm_enter_visual_mode + zvm_bindkey vicmd 'V' zvm_enter_visual_mode + zvm_bindkey visual 'o' zvm_exchange_point_and_mark + zvm_bindkey vicmd 'o' zvm_open_line_below + zvm_bindkey vicmd 'O' zvm_open_line_above + zvm_bindkey vicmd 'r' zvm_vi_replace_chars + zvm_bindkey vicmd 'R' zvm_vi_replace + zvm_bindkey vicmd 's' zvm_vi_substitute + zvm_bindkey vicmd 'S' zvm_vi_substitute_whole_line + zvm_bindkey vicmd 'C' zvm_vi_change_eol + zvm_bindkey visual 'c' zvm_vi_change + zvm_bindkey visual 'd' zvm_vi_delete + zvm_bindkey visual 'y' zvm_vi_yank + zvm_bindkey vicmd 'p' zvm_vi_put_after + zvm_bindkey vicmd 'P' zvm_vi_put_before + zvm_bindkey visual 'U' zvm_vi_up_case + zvm_bindkey visual 'u' zvm_vi_down_case + zvm_bindkey visual '~' zvm_vi_opp_case + zvm_bindkey visual 'v' zvm_vi_edit_command_line + zvm_bindkey vicmd '.' zvm_repeat_change + + zvm_bindkey vicmd '^A' zvm_switch_keyword + zvm_bindkey vicmd '^X' zvm_switch_keyword + + # Keybindings for escape key and some specials + local exit_oppend_mode_widget= + local exit_insert_mode_widget= + local exit_visual_mode_widget= + local default_handler_widget= + + case $ZVM_READKEY_ENGINE in + $ZVM_READKEY_ENGINE_NEX) + exit_oppend_mode_widget=zvm_readkeys_handler + exit_insert_mode_widget=zvm_readkeys_handler + exit_visual_mode_widget=zvm_readkeys_handler + ;; + $ZVM_READKEY_ENGINE_ZLE) + exit_insert_mode_widget=zvm_exit_insert_mode + exit_visual_mode_widget=zvm_exit_visual_mode + default_handler_widget=zvm_default_handler + ;; + esac + + # Bind custom escape key + zvm_bindkey vicmd "$ZVM_VI_OPPEND_ESCAPE_BINDKEY" $exit_oppend_mode_widget + zvm_bindkey viins "$ZVM_VI_INSERT_ESCAPE_BINDKEY" $exit_insert_mode_widget + zvm_bindkey visual "$ZVM_VI_VISUAL_ESCAPE_BINDKEY" $exit_visual_mode_widget + + # Bind the default escape key if the escape key is not the default + case "$ZVM_VI_OPPEND_ESCAPE_BINDKEY" in + '^['|'\e') ;; + *) zvm_bindkey vicmd '^[' $exit_oppend_mode_widget;; + esac + case "$ZVM_VI_INSERT_ESCAPE_BINDKEY" in + '^['|'\e') ;; + *) zvm_bindkey viins '^[' $exit_insert_mode_widget;; + esac + case "$ZVM_VI_VISUAL_ESCAPE_BINDKEY" in + '^['|'\e') ;; + *) zvm_bindkey visual '^[' $exit_visual_mode_widget;; + esac + + # Bind and overwrite original y/d/c of vicmd + for c in {y,d,c}; do + zvm_bindkey vicmd "$c" $default_handler_widget + done + + # Surround text-object + # Enable surround text-objects (quotes, brackets) + local surrounds=() + + # Append brackets + for s in ${(s..)^:-'()[]{}<>'}; do + surrounds+=($s) + done + + # Append quotes + for s in {\',\",\`,\ ,'^['}; do + surrounds+=($s) + done + + # Append for escaping visual mode + if $is_custom_escape_key; then + surrounds+=("$ZVM_VI_ESCAPE_BINDKEY") + fi + + # Surround key bindings + for s in $surrounds; do + for c in {a,i}${s}; do + zvm_bindkey visual "$c" zvm_select_surround + done + for c in {c,d,y}{a,i}${s}; do + zvm_bindkey vicmd "$c" zvm_change_surround_text_object + done + if [[ $ZVM_VI_SURROUND_BINDKEY == 's-prefix' ]]; then + for c in s{d,r}${s}; do + zvm_bindkey vicmd "$c" zvm_change_surround + done + for c in sa${s}; do + zvm_bindkey visual "$c" zvm_change_surround + done + else + for c in {d,c}s${s}; do + zvm_bindkey vicmd "$c" zvm_change_surround + done + for c in {S,ys}${s}; do + zvm_bindkey visual "$c" zvm_change_surround + done + fi + done + + # Moving around surrounds + zvm_bindkey vicmd '%' zvm_move_around_surround + + # Fix BACKSPACE was stuck in zsh + # Since normally '^?' (backspace) is bound to vi-backward-delete-char + zvm_bindkey viins '^?' backward-delete-char + + # Enable vi keymap + bindkey -v + + zvm_exec_commands 'after_init' +} + +# Precmd function +function zvm_precmd_function() { + # Init zsh vi mode when starting new command line at first time + if ! $ZVM_INIT_DONE; then + ZVM_INIT_DONE=true + zvm_init + fi +} + +# Check if a command is existed +function zvm_exist_command() { + command -v "$1" >/dev/null +} + +# Execute commands +function zvm_exec_commands() { + local commands="zvm_${1}_commands" + commands=(${(P)commands}) + + # Execute the default command + if zvm_exist_command "zvm_$1"; then + eval "zvm_$1" ${@:2} + fi + + # Execute extra commands + for cmd in $commands; do + if zvm_exist_command ${cmd}; then + cmd="$cmd ${@:2}" + fi + eval $cmd + done +} + +# Initialize the plugin when starting new command line +precmd_functions+=(zvm_precmd_function) + diff --git a/zsh/zshrc.sh b/zsh/zshrc.sh index 09b3675d2..0ecbfeb42 100644 --- a/zsh/zshrc.sh +++ b/zsh/zshrc.sh @@ -1,81 +1,21 @@ # Vars HISTFILE=~/.zsh_history - SAVEHIST=1000 - setopt inc_append_history # To save every command before it is executed - setopt share_history # setopt inc_append_history + SAVEHIST=10000 - git config --global push.default current - -# Aliases - alias v="vim -p" - mkdir -p /tmp/log - - # This is currently causing problems (fails when you run it anywhere that isn't a git project's root directory) - # alias vs="v `git status --porcelain | sed -ne 's/^ M //p'`" - -# Settings - export VISUAL=vim - -source ~/dotfiles/zsh/plugins/fixls.zsh - -#Functions - # Loop a command and show the output in vim - loop() { - echo ":cq to quit\n" > /tmp/log/output - fc -ln -1 > /tmp/log/program - while true; do - cat /tmp/log/program >> /tmp/log/output ; - $(cat /tmp/log/program) |& tee -a /tmp/log/output ; - echo '\n' >> /tmp/log/output - vim + /tmp/log/output || break; - rm -rf /tmp/log/output - done; - } # Custom cd chpwd() ls -# Completions -# These are all the plugin options available: https://github.com/robbyrussell/oh-my-zsh/tree/291e96dcd034750fbe7473482508c08833b168e3/plugins -# -# Edit the array below, or relocate it to ~/.zshrc before anything is sourced -# For help create an issue at github.com/parth/dotfiles - -autoload -U compinit - -plugins=( - docker -) -for plugin ($plugins); do - fpath=(~/dotfiles/zsh/plugins/oh-my-zsh/plugins/$plugin $fpath) -done +autoload -U compinit && compinit -compinit - -source ~/dotfiles/zsh/plugins/oh-my-zsh/lib/history.zsh -source ~/dotfiles/zsh/plugins/oh-my-zsh/lib/key-bindings.zsh -source ~/dotfiles/zsh/plugins/oh-my-zsh/lib/completion.zsh -source ~/dotfiles/zsh/plugins/vi-mode.plugin.zsh +source ~/dotfiles/zsh/plugins/fixls.zsh +source ~/dotfiles/zsh/plugins/zsh-vi-mode.plugin.zsh source ~/dotfiles/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh source ~/dotfiles/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh -source ~/dotfiles/zsh/keybindings.sh - -# Fix for arrow-key searching -# start typing + [Up-Arrow] - fuzzy find history forward -if [[ "${terminfo[kcuu1]}" != "" ]]; then - autoload -U up-line-or-beginning-search - zle -N up-line-or-beginning-search - bindkey "${terminfo[kcuu1]}" up-line-or-beginning-search -fi -# start typing + [Down-Arrow] - fuzzy find history backward -if [[ "${terminfo[kcud1]}" != "" ]]; then - autoload -U down-line-or-beginning-search - zle -N down-line-or-beginning-search - bindkey "${terminfo[kcud1]}" down-line-or-beginning-search -fi - -source ~/dotfiles/zsh/prompt.sh -export PATH=$PATH:$HOME/dotfiles/utils - +source ~/dotfiles/env-vars.env source ~/dotfiles/zsh/lockbook.sh +source ~/dotfiles/zsh/prompt.sh +zvm_after_init_commands+=('source ~/dotfiles/zsh/plugins/fzf-tab/fzf-tab.plugin.zsh') +zvm_after_init_commands+=('source /usr/share/fzf/key-bindings.zsh') +zvm_after_init_commands+=('source /usr/share/fzf/completion.zsh') From bc55e79aa1c8542da022ad8a26b02f10d5a98648 Mon Sep 17 00:00:00 2001 From: Parth Date: Sun, 9 May 2021 12:30:24 -0400 Subject: [PATCH 011/123] fix ls --- zsh/zshrc.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zsh/zshrc.sh b/zsh/zshrc.sh index 0ecbfeb42..6743ed801 100644 --- a/zsh/zshrc.sh +++ b/zsh/zshrc.sh @@ -4,12 +4,13 @@ # Custom cd +source ~/dotfiles/zsh/plugins/fixls.zsh + chpwd() ls autoload -U compinit && compinit -source ~/dotfiles/zsh/plugins/fixls.zsh source ~/dotfiles/zsh/plugins/zsh-vi-mode.plugin.zsh source ~/dotfiles/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh source ~/dotfiles/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh From b318aa2b71272bfaccc6f85f713cad9f118d60ce Mon Sep 17 00:00:00 2001 From: Parth Date: Sun, 9 May 2021 14:18:18 -0400 Subject: [PATCH 012/123] cleanup vim a bit --- vim/vimrc.vim | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/vim/vimrc.vim b/vim/vimrc.vim index e4dabbce2..5ec6c6779 100644 --- a/vim/vimrc.vim +++ b/vim/vimrc.vim @@ -5,7 +5,7 @@ set tabstop=4 set shiftwidth=4 set dir=/tmp/ - set relativenumber + set relativenumber set number autocmd Filetype html setlocal sw=2 expandtab @@ -19,21 +19,9 @@ nnoremap n nzzzv nnoremap N Nzzzv - nnoremap H 0 - nnoremap L $ - nnoremap J G - nnoremap K gg - - map % - - set backspace=indent,eol,start - - nnoremap za - nnoremap z zMzvzz - nnoremap vv 0v$ - set listchars=tab:\|\ + set listchars=tab:\|\ nnoremap :set list! set pastetoggle= set mouse=a @@ -43,15 +31,11 @@ " Tabs so ~/dotfiles/vim/sleuth.vim - " Typescript - autocmd BufNewFile,BufRead *.ts set syntax=javascript - autocmd BufNewFile,BufRead *.tsx set syntax=javascript - " Markup inoremap < I<A>yypa/O -" File and Window Management +" File and Window Management inoremap w :w nnoremap w :w @@ -80,7 +64,7 @@ " https://unix.stackexchange.com/questions/149209/refresh-changed-content-of-file-opened-in-vim/383044#383044 " https://vi.stackexchange.com/questions/13692/prevent-focusgained-autocmd-running-in-command-line-editing-mode autocmd FocusGained,BufEnter,CursorHold,CursorHoldI * if mode() != 'c' | checktime | endif - set autoread + set autoread " Notification after file change " https://vi.stackexchange.com/questions/13091/autocmd-event-for-autoread autocmd FileChangedShellPost * From 77fbb2b14a8ba70ff4cbad0ebc53c34bea5c4fe2 Mon Sep 17 00:00:00 2001 From: Parth Date: Sat, 14 Aug 2021 19:01:58 -0400 Subject: [PATCH 013/123] cleaned up unused plugins --- .gitmodules | 3 --- zsh/plugins/fzf-tab | 1 - zsh/plugins/oh-my-zsh | 1 - zsh/zshrc.sh | 3 --- zsh/zshrc_manager.sh | 11 ----------- 5 files changed, 19 deletions(-) delete mode 160000 zsh/plugins/fzf-tab delete mode 160000 zsh/plugins/oh-my-zsh diff --git a/.gitmodules b/.gitmodules index 8511a1277..740ca3ea2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,6 +4,3 @@ [submodule "zsh/plugins/zsh-autosuggestions"] path = zsh/plugins/zsh-autosuggestions url = https://github.com/zsh-users/zsh-autosuggestions.git -[submodule "zsh/plugins/fzf-tab"] - path = zsh/plugins/fzf-tab - url = https://github.com/Aloxaf/fzf-tab diff --git a/zsh/plugins/fzf-tab b/zsh/plugins/fzf-tab deleted file mode 160000 index 3d6aca79b..000000000 --- a/zsh/plugins/fzf-tab +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3d6aca79b68b8b98286dda2cb76076f2a2081225 diff --git a/zsh/plugins/oh-my-zsh b/zsh/plugins/oh-my-zsh deleted file mode 160000 index 291e96dcd..000000000 --- a/zsh/plugins/oh-my-zsh +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 291e96dcd034750fbe7473482508c08833b168e3 diff --git a/zsh/zshrc.sh b/zsh/zshrc.sh index 6743ed801..7e1cd15a6 100644 --- a/zsh/zshrc.sh +++ b/zsh/zshrc.sh @@ -17,6 +17,3 @@ source ~/dotfiles/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zs source ~/dotfiles/env-vars.env source ~/dotfiles/zsh/lockbook.sh source ~/dotfiles/zsh/prompt.sh -zvm_after_init_commands+=('source ~/dotfiles/zsh/plugins/fzf-tab/fzf-tab.plugin.zsh') -zvm_after_init_commands+=('source /usr/share/fzf/key-bindings.zsh') -zvm_after_init_commands+=('source /usr/share/fzf/completion.zsh') diff --git a/zsh/zshrc_manager.sh b/zsh/zshrc_manager.sh index 6d34075a7..b313be3c9 100644 --- a/zsh/zshrc_manager.sh +++ b/zsh/zshrc_manager.sh @@ -1,16 +1,5 @@ time_out () { perl -e 'alarm shift; exec @ARGV' "$@"; } -# Run tmux if exists -if command -v tmux>/dev/null; then - if [ "$DISABLE_TMUX" = "true" ]; then - echo "DISABLE_TMUX=true" - else - [ -z $TMUX ] && exec tmux - fi -else - echo "tmux not installed. Run ./deploy to configure dependencies" -fi - echo "Checking for updates." ({cd ~/dotfiles && git fetch -q} &> /dev/null) From 3d173732fcba5ebf6d2a3278f910b64be73e1943 Mon Sep 17 00:00:00 2001 From: parth Date: Mon, 19 Jun 2023 22:10:35 -0400 Subject: [PATCH 014/123] nvim experiments --- nvim/after/plugin/fugitive.lua | 1 + nvim/after/plugin/lsp.lua | 67 ++++++++++++ nvim/after/plugin/lualine.lua | 43 ++++++++ nvim/after/plugin/nvim-tree.lua | 4 + nvim/after/plugin/telescope.lua | 4 + nvim/after/plugin/treesitter.lua | 15 +++ nvim/after/plugin/undotree.lua | 1 + nvim/deploy.sh | 3 + nvim/init.lua | 1 + nvim/lua/parth/init.lua | 3 + nvim/lua/parth/packer.lua | 59 ++++++++++ nvim/lua/parth/remap.lua | 21 ++++ nvim/lua/parth/set.lua | 24 +++++ nvim/plugin/packer_compiled.lua | 180 +++++++++++++++++++++++++++++++ 14 files changed, 426 insertions(+) create mode 100644 nvim/after/plugin/fugitive.lua create mode 100644 nvim/after/plugin/lsp.lua create mode 100644 nvim/after/plugin/lualine.lua create mode 100644 nvim/after/plugin/nvim-tree.lua create mode 100644 nvim/after/plugin/telescope.lua create mode 100644 nvim/after/plugin/treesitter.lua create mode 100644 nvim/after/plugin/undotree.lua create mode 100755 nvim/deploy.sh create mode 100644 nvim/init.lua create mode 100644 nvim/lua/parth/init.lua create mode 100644 nvim/lua/parth/packer.lua create mode 100644 nvim/lua/parth/remap.lua create mode 100644 nvim/lua/parth/set.lua create mode 100644 nvim/plugin/packer_compiled.lua diff --git a/nvim/after/plugin/fugitive.lua b/nvim/after/plugin/fugitive.lua new file mode 100644 index 000000000..73b78b85c --- /dev/null +++ b/nvim/after/plugin/fugitive.lua @@ -0,0 +1 @@ +vim.keymap.set("n", "gs", vim.cmd.Git); diff --git a/nvim/after/plugin/lsp.lua b/nvim/after/plugin/lsp.lua new file mode 100644 index 000000000..133185f91 --- /dev/null +++ b/nvim/after/plugin/lsp.lua @@ -0,0 +1,67 @@ +local lsp = require('lsp-zero') + +lsp.preset('recommended') + +lsp.ensure_installed({ + 'rust_analyzer' +}) + +local cmp = require('cmp') +local cmp_select = { behavior = cmp.SelectBehavior.Select } +local cmp_mappings = lsp.defaults.cmp_mappings({ + [''] = cmp.mapping.select_prev_item(cmp_select), + [''] = cmp.mapping.select_next_item(cmp_select), + [''] = cmp.mapping.confirm(cmp_select), + [''] = cmp.mapping.complete(), +}) + + +lsp.setup_nvim_cmp({ + mapping = cmp_mappings +}) + +lsp.set_preferences({ + suggest_lsp_servers = false, + sign_icons = { + error = 'E', + warn = 'W', + hint = 'H', + info = 'I' + } +}) + +local augroup = vim.api.nvim_create_augroup('LspFormatting', {}) +local lsp_format_on_save = function(bufnr) + vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) + vim.api.nvim_create_autocmd('BufWritePre', { + group = augroup, + buffer = bufnr, + callback = function() + vim.lsp.buf.format() + end, + }) +end + + +lsp.on_attach(function(client, bufnr) + lsp_format_on_save(bufnr) + + local opts = { buffer = bufnr, remap = false } + + vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) + vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts) + vim.keymap.set("n", "vws", function() vim.lsp.buf.workspace_symbol() end, opts) + vim.keymap.set("n", "vd", function() vim.diagnostic.open_float() end, opts) + vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts) + vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts) + vim.keymap.set("n", "vca", function() vim.lsp.buf.code_action() end, opts) + vim.keymap.set("n", "vrr", function() vim.lsp.buf.references() end, opts) + vim.keymap.set("n", "vrn", function() vim.lsp.buf.rename() end, opts) + vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) +end) + +lsp.setup() + +vim.diagnostic.config({ + virtual_text = true +}) diff --git a/nvim/after/plugin/lualine.lua b/nvim/after/plugin/lualine.lua new file mode 100644 index 000000000..38b12a303 --- /dev/null +++ b/nvim/after/plugin/lualine.lua @@ -0,0 +1,43 @@ +local lsp_status = require('lsp-status') +lsp_status.register_progress() + +require('lualine').setup { + options = { + icons_enabled = true, + theme = '16color', + component_separators = { left = '', right = ''}, + section_separators = { left = '', right = ''}, + disabled_filetypes = { + statusline = {}, + winbar = {}, + }, + ignore_focus = {}, + always_divide_middle = true, + globalstatus = false, + refresh = { + statusline = 1000, + tabline = 1000, + winbar = 1000, + } + }, + sections = { + lualine_a = {'mode'}, + lualine_b = {'branch', 'diff', 'diagnostics'}, + lualine_c = {'filename'}, + lualine_x = {'encoding', 'fileformat', 'filetype'}, + lualine_y = { "require'lsp-status'.status()" }, + lualine_z = {'location'} + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {'filename'}, + lualine_x = {'location'}, + lualine_y = {}, + lualine_z = {} + }, + tabline = {}, + winbar = {}, + inactive_winbar = {}, + extensions = {} +} diff --git a/nvim/after/plugin/nvim-tree.lua b/nvim/after/plugin/nvim-tree.lua new file mode 100644 index 000000000..d5350e5fa --- /dev/null +++ b/nvim/after/plugin/nvim-tree.lua @@ -0,0 +1,4 @@ +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 + +require("nvim-tree").setup() diff --git a/nvim/after/plugin/telescope.lua b/nvim/after/plugin/telescope.lua new file mode 100644 index 000000000..5d9d91a4a --- /dev/null +++ b/nvim/after/plugin/telescope.lua @@ -0,0 +1,4 @@ +local builtin = require('telescope.builtin') +vim.keymap.set('n', 'T', builtin.find_files, {}) +vim.keymap.set('n', 't', builtin.git_files, {}) +vim.keymap.set('n', 'l', builtin.buffers, {}) diff --git a/nvim/after/plugin/treesitter.lua b/nvim/after/plugin/treesitter.lua new file mode 100644 index 000000000..a54a6152a --- /dev/null +++ b/nvim/after/plugin/treesitter.lua @@ -0,0 +1,15 @@ +require'nvim-treesitter.configs'.setup { + -- A list of parser names, or "all" (the five listed parsers should always be installed) + ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "rust" }, + + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, + + -- Automatically install missing parsers when entering buffer + -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally + auto_install = true, + highlight = { + enable = true, + additional_vim_regex_highlighting = false, + }, +} diff --git a/nvim/after/plugin/undotree.lua b/nvim/after/plugin/undotree.lua new file mode 100644 index 000000000..b6b9276a5 --- /dev/null +++ b/nvim/after/plugin/undotree.lua @@ -0,0 +1 @@ +vim.keymap.set("n", "u", vim.cmd.UndotreeToggle) diff --git a/nvim/deploy.sh b/nvim/deploy.sh new file mode 100755 index 000000000..66422be1d --- /dev/null +++ b/nvim/deploy.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +ln -s $HOME/dotfiles/nvim $HOME/.config/nvim diff --git a/nvim/init.lua b/nvim/init.lua new file mode 100644 index 000000000..5149f6ef6 --- /dev/null +++ b/nvim/init.lua @@ -0,0 +1 @@ +require("parth") diff --git a/nvim/lua/parth/init.lua b/nvim/lua/parth/init.lua new file mode 100644 index 000000000..a6862232f --- /dev/null +++ b/nvim/lua/parth/init.lua @@ -0,0 +1,3 @@ +require("parth.packer") +require("parth.set") +require("parth.remap") diff --git a/nvim/lua/parth/packer.lua b/nvim/lua/parth/packer.lua new file mode 100644 index 000000000..7fe2ca3bf --- /dev/null +++ b/nvim/lua/parth/packer.lua @@ -0,0 +1,59 @@ +-- This file can be loaded by calling `lua require('plugins')` from your init.vim + +-- Only required if you have packer configured as `opt` +vim.cmd [[packadd packer.nvim]] + +return require('packer').startup(function(use) + -- Packer can manage itself + use 'wbthomason/packer.nvim' + + use { + 'nvim-telescope/telescope.nvim', tag = '0.1.1', + -- or , branch = '0.1.x', + requires = { { 'nvim-lua/plenary.nvim' } } + } + + use { + 'nvim-treesitter/nvim-treesitter', + run = ':TSUpdate' + } + + use('mbbill/undotree') + + use('tpope/vim-fugitive') + + + use { + 'VonHeikemen/lsp-zero.nvim', + branch = 'v2.x', + requires = { + -- LSP Support + { 'neovim/nvim-lspconfig' }, -- Required + { -- Optional + 'williamboman/mason.nvim', + run = function() + pcall(vim.cmd, 'MasonUpdate') + end, + }, + { 'williamboman/mason-lspconfig.nvim' }, -- Optional + { 'hrsh7th/nvim-cmp' }, -- Required + { 'hrsh7th/cmp-nvim-lsp' }, -- Required + { 'L3MON4D3/LuaSnip' }, -- Required + } + + } + + use('nvim-lua/lsp-status.nvim') + + use { + 'nvim-lualine/lualine.nvim', + requires = { 'nvim-tree/nvim-web-devicons', opt = true } + } + + use { + 'nvim-tree/nvim-tree.lua', + requires = { + 'nvim-tree/nvim-web-devicons', -- optional + }, + } +end) diff --git a/nvim/lua/parth/remap.lua b/nvim/lua/parth/remap.lua new file mode 100644 index 000000000..6b9bfe59c --- /dev/null +++ b/nvim/lua/parth/remap.lua @@ -0,0 +1,21 @@ +vim.keymap.set("n", "e", vim.cmd.NvimTreeOpen) +vim.keymap.set("n", "", vim.cmd.write) +vim.keymap.set("n", "w", vim.cmd.wq) + +vim.keymap.set("n", "", vim.cmd.tabnew) +vim.keymap.set("n", "1", "1gt") +vim.keymap.set("n", "2", "2gt") +vim.keymap.set("n", "3", "3gt") +vim.keymap.set("n", "4", "4gt") +vim.keymap.set("n", "5", "5gt") +vim.keymap.set("n", "6", "6gt") +vim.keymap.set("n", "7", "7gt") +vim.keymap.set("n", "8", "8gt") +vim.keymap.set("n", "9", "9gt") + +vim.keymap.set("n", "v", vim.cmd.vsplit) +vim.keymap.set("n", "h", vim.cmd.split) +vim.keymap.set("n", "", "") +vim.keymap.set("n", "", "") +vim.keymap.set("n", "", "") +vim.keymap.set("n", "", "") diff --git a/nvim/lua/parth/set.lua b/nvim/lua/parth/set.lua new file mode 100644 index 000000000..63f3b7299 --- /dev/null +++ b/nvim/lua/parth/set.lua @@ -0,0 +1,24 @@ +vim.opt.nu = true +vim.opt.relativenumber = true + +vim.opt.tabstop = 4 +vim.opt.softtabstop = 4 +vim.opt.shiftwidth = 4 +vim.opt.expandtab = true +vim.opt.smartindent = true + +vim.opt.swapfile = false +vim.opt.backup = false +vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir" +vim.opt.undofile = true + +vim.opt.hlsearch = false +vim.opt.incsearch = true + +vim.opt.scrolloff = 8 + +vim.opt.updatetime = 50 + +vim.g.mapleader = " " + +vim.cmd [[autocmd BufWritePre lua vim.lsp.buf.format()]] diff --git a/nvim/plugin/packer_compiled.lua b/nvim/plugin/packer_compiled.lua new file mode 100644 index 000000000..fb7aef544 --- /dev/null +++ b/nvim/plugin/packer_compiled.lua @@ -0,0 +1,180 @@ +-- Automatically generated packer.nvim plugin loader code + +if vim.api.nvim_call_function('has', {'nvim-0.5'}) ~= 1 then + vim.api.nvim_command('echohl WarningMsg | echom "Invalid Neovim version for packer.nvim! | echohl None"') + return +end + +vim.api.nvim_command('packadd packer.nvim') + +local no_errors, error_msg = pcall(function() + +_G._packer = _G._packer or {} +_G._packer.inside_compile = true + +local time +local profile_info +local should_profile = false +if should_profile then + local hrtime = vim.loop.hrtime + profile_info = {} + time = function(chunk, start) + if start then + profile_info[chunk] = hrtime() + else + profile_info[chunk] = (hrtime() - profile_info[chunk]) / 1e6 + end + end +else + time = function(chunk, start) end +end + +local function save_profiles(threshold) + local sorted_times = {} + for chunk_name, time_taken in pairs(profile_info) do + sorted_times[#sorted_times + 1] = {chunk_name, time_taken} + end + table.sort(sorted_times, function(a, b) return a[2] > b[2] end) + local results = {} + for i, elem in ipairs(sorted_times) do + if not threshold or threshold and elem[2] > threshold then + results[i] = elem[1] .. ' took ' .. elem[2] .. 'ms' + end + end + if threshold then + table.insert(results, '(Only showing plugins that took longer than ' .. threshold .. ' ms ' .. 'to load)') + end + + _G._packer.profile_output = results +end + +time([[Luarocks path setup]], true) +local package_path_str = "/home/parth/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?.lua;/home/parth/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?/init.lua;/home/parth/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?.lua;/home/parth/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?/init.lua" +local install_cpath_pattern = "/home/parth/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/?.so" +if not string.find(package.path, package_path_str, 1, true) then + package.path = package.path .. ';' .. package_path_str +end + +if not string.find(package.cpath, install_cpath_pattern, 1, true) then + package.cpath = package.cpath .. ';' .. install_cpath_pattern +end + +time([[Luarocks path setup]], false) +time([[try_loadstring definition]], true) +local function try_loadstring(s, component, name) + local success, result = pcall(loadstring(s), name, _G.packer_plugins[name]) + if not success then + vim.schedule(function() + vim.api.nvim_notify('packer.nvim: Error running ' .. component .. ' for ' .. name .. ': ' .. result, vim.log.levels.ERROR, {}) + end) + end + return result +end + +time([[try_loadstring definition]], false) +time([[Defining packer_plugins]], true) +_G.packer_plugins = { + LuaSnip = { + loaded = true, + path = "/home/parth/.local/share/nvim/site/pack/packer/start/LuaSnip", + url = "https://github.com/L3MON4D3/LuaSnip" + }, + ["cmp-nvim-lsp"] = { + loaded = true, + path = "/home/parth/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp", + url = "https://github.com/hrsh7th/cmp-nvim-lsp" + }, + ["lsp-status.nvim"] = { + loaded = true, + path = "/home/parth/.local/share/nvim/site/pack/packer/start/lsp-status.nvim", + url = "https://github.com/nvim-lua/lsp-status.nvim" + }, + ["lsp-zero.nvim"] = { + loaded = true, + path = "/home/parth/.local/share/nvim/site/pack/packer/start/lsp-zero.nvim", + url = "https://github.com/VonHeikemen/lsp-zero.nvim" + }, + ["lualine.nvim"] = { + loaded = true, + path = "/home/parth/.local/share/nvim/site/pack/packer/start/lualine.nvim", + url = "https://github.com/nvim-lualine/lualine.nvim" + }, + ["mason-lspconfig.nvim"] = { + loaded = true, + path = "/home/parth/.local/share/nvim/site/pack/packer/start/mason-lspconfig.nvim", + url = "https://github.com/williamboman/mason-lspconfig.nvim" + }, + ["mason.nvim"] = { + loaded = true, + path = "/home/parth/.local/share/nvim/site/pack/packer/start/mason.nvim", + url = "https://github.com/williamboman/mason.nvim" + }, + ["nvim-cmp"] = { + loaded = true, + path = "/home/parth/.local/share/nvim/site/pack/packer/start/nvim-cmp", + url = "https://github.com/hrsh7th/nvim-cmp" + }, + ["nvim-lspconfig"] = { + loaded = true, + path = "/home/parth/.local/share/nvim/site/pack/packer/start/nvim-lspconfig", + url = "https://github.com/neovim/nvim-lspconfig" + }, + ["nvim-tree.lua"] = { + loaded = true, + path = "/home/parth/.local/share/nvim/site/pack/packer/start/nvim-tree.lua", + url = "https://github.com/nvim-tree/nvim-tree.lua" + }, + ["nvim-treesitter"] = { + loaded = true, + path = "/home/parth/.local/share/nvim/site/pack/packer/start/nvim-treesitter", + url = "https://github.com/nvim-treesitter/nvim-treesitter" + }, + ["nvim-web-devicons"] = { + loaded = false, + needs_bufread = false, + path = "/home/parth/.local/share/nvim/site/pack/packer/opt/nvim-web-devicons", + url = "https://github.com/nvim-tree/nvim-web-devicons" + }, + ["packer.nvim"] = { + loaded = true, + path = "/home/parth/.local/share/nvim/site/pack/packer/start/packer.nvim", + url = "https://github.com/wbthomason/packer.nvim" + }, + ["plenary.nvim"] = { + loaded = true, + path = "/home/parth/.local/share/nvim/site/pack/packer/start/plenary.nvim", + url = "https://github.com/nvim-lua/plenary.nvim" + }, + ["telescope.nvim"] = { + loaded = true, + path = "/home/parth/.local/share/nvim/site/pack/packer/start/telescope.nvim", + url = "https://github.com/nvim-telescope/telescope.nvim" + }, + undotree = { + loaded = true, + path = "/home/parth/.local/share/nvim/site/pack/packer/start/undotree", + url = "https://github.com/mbbill/undotree" + }, + ["vim-fugitive"] = { + loaded = true, + path = "/home/parth/.local/share/nvim/site/pack/packer/start/vim-fugitive", + url = "https://github.com/tpope/vim-fugitive" + } +} + +time([[Defining packer_plugins]], false) + +_G._packer.inside_compile = false +if _G._packer.needs_bufread == true then + vim.cmd("doautocmd BufRead") +end +_G._packer.needs_bufread = false + +if should_profile then save_profiles() end + +end) + +if not no_errors then + error_msg = error_msg:gsub('"', '\\"') + vim.api.nvim_command('echohl ErrorMsg | echom "Error in packer_compiled: '..error_msg..'" | echom "Please check your config for correctness" | echohl None') +end From 4f2cde7e03e0e16467e7a46d5f4f8b0c60490e24 Mon Sep 17 00:00:00 2001 From: Parth Date: Wed, 21 Jun 2023 15:15:04 -0400 Subject: [PATCH 015/123] add packer to deploy --- nvim/deploy.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nvim/deploy.sh b/nvim/deploy.sh index 66422be1d..bd5b80fa5 100755 --- a/nvim/deploy.sh +++ b/nvim/deploy.sh @@ -1,3 +1,5 @@ #!/bin/bash +git clone --depth 1 https://github.com/wbthomason/packer.nvim\ + ~/.local/share/nvim/site/pack/packer/start/packer.nvim ln -s $HOME/dotfiles/nvim $HOME/.config/nvim From a6a7485746926f24075350e579847ead82b1d61a Mon Sep 17 00:00:00 2001 From: Parth Date: Thu, 22 Jun 2023 15:02:50 -0400 Subject: [PATCH 016/123] save from insert mode --- nvim/lua/parth/remap.lua | 1 + nvim/plugin/packer_compiled.lua | 38 ++++++++++++++++----------------- test.sh | 9 ++++++++ 3 files changed, 29 insertions(+), 19 deletions(-) create mode 100755 test.sh diff --git a/nvim/lua/parth/remap.lua b/nvim/lua/parth/remap.lua index 6b9bfe59c..2dffbca6d 100644 --- a/nvim/lua/parth/remap.lua +++ b/nvim/lua/parth/remap.lua @@ -1,5 +1,6 @@ vim.keymap.set("n", "e", vim.cmd.NvimTreeOpen) vim.keymap.set("n", "", vim.cmd.write) +vim.keymap.set("i", "", vim.cmd.write) vim.keymap.set("n", "w", vim.cmd.wq) vim.keymap.set("n", "", vim.cmd.tabnew) diff --git a/nvim/plugin/packer_compiled.lua b/nvim/plugin/packer_compiled.lua index fb7aef544..0acdb51ff 100644 --- a/nvim/plugin/packer_compiled.lua +++ b/nvim/plugin/packer_compiled.lua @@ -49,8 +49,8 @@ local function save_profiles(threshold) end time([[Luarocks path setup]], true) -local package_path_str = "/home/parth/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?.lua;/home/parth/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?/init.lua;/home/parth/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?.lua;/home/parth/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?/init.lua" -local install_cpath_pattern = "/home/parth/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/?.so" +local package_path_str = "/Users/parth/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?.lua;/Users/parth/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?/init.lua;/Users/parth/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?.lua;/Users/parth/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?/init.lua" +local install_cpath_pattern = "/Users/parth/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/?.so" if not string.find(package.path, package_path_str, 1, true) then package.path = package.path .. ';' .. package_path_str end @@ -76,88 +76,88 @@ time([[Defining packer_plugins]], true) _G.packer_plugins = { LuaSnip = { loaded = true, - path = "/home/parth/.local/share/nvim/site/pack/packer/start/LuaSnip", + path = "/Users/parth/.local/share/nvim/site/pack/packer/start/LuaSnip", url = "https://github.com/L3MON4D3/LuaSnip" }, ["cmp-nvim-lsp"] = { loaded = true, - path = "/home/parth/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp", + path = "/Users/parth/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp", url = "https://github.com/hrsh7th/cmp-nvim-lsp" }, ["lsp-status.nvim"] = { loaded = true, - path = "/home/parth/.local/share/nvim/site/pack/packer/start/lsp-status.nvim", + path = "/Users/parth/.local/share/nvim/site/pack/packer/start/lsp-status.nvim", url = "https://github.com/nvim-lua/lsp-status.nvim" }, ["lsp-zero.nvim"] = { loaded = true, - path = "/home/parth/.local/share/nvim/site/pack/packer/start/lsp-zero.nvim", + path = "/Users/parth/.local/share/nvim/site/pack/packer/start/lsp-zero.nvim", url = "https://github.com/VonHeikemen/lsp-zero.nvim" }, ["lualine.nvim"] = { loaded = true, - path = "/home/parth/.local/share/nvim/site/pack/packer/start/lualine.nvim", + path = "/Users/parth/.local/share/nvim/site/pack/packer/start/lualine.nvim", url = "https://github.com/nvim-lualine/lualine.nvim" }, ["mason-lspconfig.nvim"] = { loaded = true, - path = "/home/parth/.local/share/nvim/site/pack/packer/start/mason-lspconfig.nvim", + path = "/Users/parth/.local/share/nvim/site/pack/packer/start/mason-lspconfig.nvim", url = "https://github.com/williamboman/mason-lspconfig.nvim" }, ["mason.nvim"] = { loaded = true, - path = "/home/parth/.local/share/nvim/site/pack/packer/start/mason.nvim", + path = "/Users/parth/.local/share/nvim/site/pack/packer/start/mason.nvim", url = "https://github.com/williamboman/mason.nvim" }, ["nvim-cmp"] = { loaded = true, - path = "/home/parth/.local/share/nvim/site/pack/packer/start/nvim-cmp", + path = "/Users/parth/.local/share/nvim/site/pack/packer/start/nvim-cmp", url = "https://github.com/hrsh7th/nvim-cmp" }, ["nvim-lspconfig"] = { loaded = true, - path = "/home/parth/.local/share/nvim/site/pack/packer/start/nvim-lspconfig", + path = "/Users/parth/.local/share/nvim/site/pack/packer/start/nvim-lspconfig", url = "https://github.com/neovim/nvim-lspconfig" }, ["nvim-tree.lua"] = { loaded = true, - path = "/home/parth/.local/share/nvim/site/pack/packer/start/nvim-tree.lua", + path = "/Users/parth/.local/share/nvim/site/pack/packer/start/nvim-tree.lua", url = "https://github.com/nvim-tree/nvim-tree.lua" }, ["nvim-treesitter"] = { loaded = true, - path = "/home/parth/.local/share/nvim/site/pack/packer/start/nvim-treesitter", + path = "/Users/parth/.local/share/nvim/site/pack/packer/start/nvim-treesitter", url = "https://github.com/nvim-treesitter/nvim-treesitter" }, ["nvim-web-devicons"] = { loaded = false, needs_bufread = false, - path = "/home/parth/.local/share/nvim/site/pack/packer/opt/nvim-web-devicons", + path = "/Users/parth/.local/share/nvim/site/pack/packer/opt/nvim-web-devicons", url = "https://github.com/nvim-tree/nvim-web-devicons" }, ["packer.nvim"] = { loaded = true, - path = "/home/parth/.local/share/nvim/site/pack/packer/start/packer.nvim", + path = "/Users/parth/.local/share/nvim/site/pack/packer/start/packer.nvim", url = "https://github.com/wbthomason/packer.nvim" }, ["plenary.nvim"] = { loaded = true, - path = "/home/parth/.local/share/nvim/site/pack/packer/start/plenary.nvim", + path = "/Users/parth/.local/share/nvim/site/pack/packer/start/plenary.nvim", url = "https://github.com/nvim-lua/plenary.nvim" }, ["telescope.nvim"] = { loaded = true, - path = "/home/parth/.local/share/nvim/site/pack/packer/start/telescope.nvim", + path = "/Users/parth/.local/share/nvim/site/pack/packer/start/telescope.nvim", url = "https://github.com/nvim-telescope/telescope.nvim" }, undotree = { loaded = true, - path = "/home/parth/.local/share/nvim/site/pack/packer/start/undotree", + path = "/Users/parth/.local/share/nvim/site/pack/packer/start/undotree", url = "https://github.com/mbbill/undotree" }, ["vim-fugitive"] = { loaded = true, - path = "/home/parth/.local/share/nvim/site/pack/packer/start/vim-fugitive", + path = "/Users/parth/.local/share/nvim/site/pack/packer/start/vim-fugitive", url = "https://github.com/tpope/vim-fugitive" } } diff --git a/test.sh b/test.sh new file mode 100755 index 000000000..b9c925327 --- /dev/null +++ b/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# test_commits.sh + +while read -r rev; do + # git checkout "$rev" + echo $rev + du -sh . + # du -sh * +done < <(git rev-list 3d173732fcba5ebf6d2a3278f910b64be73e1943 681e62d2ac243da27924c5a610a2bc087f8f8a3c) From 79ccee67cccc86cb311f349cda757407598ad13c Mon Sep 17 00:00:00 2001 From: Parth Date: Thu, 6 Jul 2023 10:44:58 -0400 Subject: [PATCH 017/123] more nvim config --- nvim/after/plugin/lsp.lua | 20 +++++++++++--------- nvim/after/plugin/nvim-tree.lua | 6 +++++- nvim/after/plugin/telescope.lua | 1 + nvim/lua/parth/remap.lua | 5 +++-- nvim/todo.md | 13 +++++++++++++ 5 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 nvim/todo.md diff --git a/nvim/after/plugin/lsp.lua b/nvim/after/plugin/lsp.lua index 133185f91..7e7dffbc0 100644 --- a/nvim/after/plugin/lsp.lua +++ b/nvim/after/plugin/lsp.lua @@ -48,16 +48,18 @@ lsp.on_attach(function(client, bufnr) local opts = { buffer = bufnr, remap = false } - vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts) - vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts) - vim.keymap.set("n", "vws", function() vim.lsp.buf.workspace_symbol() end, opts) + vim.keymap.set("n", "ld", function() vim.lsp.buf.definition() end, opts) + vim.keymap.set("n", "h", function() vim.lsp.buf.hover() end, opts) + vim.keymap.set("n", "ws", function() vim.lsp.buf.workspace_symbol() end, opts) vim.keymap.set("n", "vd", function() vim.diagnostic.open_float() end, opts) - vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts) - vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts) - vim.keymap.set("n", "vca", function() vim.lsp.buf.code_action() end, opts) - vim.keymap.set("n", "vrr", function() vim.lsp.buf.references() end, opts) - vim.keymap.set("n", "vrn", function() vim.lsp.buf.rename() end, opts) - vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) + vim.keymap.set("n", "nd", function() vim.diagnostic.goto_next() end, opts) + vim.keymap.set("n", "pd", function() vim.diagnostic.goto_prev() end, opts) + vim.keymap.set("n", " ", function() vim.lsp.buf.code_action() end, opts) + vim.keymap.set("n", "fr", function() vim.lsp.buf.references() end, opts) + vim.keymap.set("n", "rn", function() vim.lsp.buf.rename() end, opts) + vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) + vim.keymap.set("n", "clr", function() vim.lsp.codelens.refresh() end, opts) + vim.keymap.set("n", "cl", function() vim.lsp.codelens.run() end, opts) end) lsp.setup() diff --git a/nvim/after/plugin/nvim-tree.lua b/nvim/after/plugin/nvim-tree.lua index d5350e5fa..41f0f908b 100644 --- a/nvim/after/plugin/nvim-tree.lua +++ b/nvim/after/plugin/nvim-tree.lua @@ -1,4 +1,8 @@ vim.g.loaded_netrw = 1 vim.g.loaded_netrwPlugin = 1 -require("nvim-tree").setup() +require("nvim-tree").setup({ + diagnostics = { + enable = true + } +}) diff --git a/nvim/after/plugin/telescope.lua b/nvim/after/plugin/telescope.lua index 5d9d91a4a..d314288da 100644 --- a/nvim/after/plugin/telescope.lua +++ b/nvim/after/plugin/telescope.lua @@ -2,3 +2,4 @@ local builtin = require('telescope.builtin') vim.keymap.set('n', 'T', builtin.find_files, {}) vim.keymap.set('n', 't', builtin.git_files, {}) vim.keymap.set('n', 'l', builtin.buffers, {}) +vim.keymap.set('n', 'lg', builtin.live_grep, {}) diff --git a/nvim/lua/parth/remap.lua b/nvim/lua/parth/remap.lua index 2dffbca6d..6dfbf986e 100644 --- a/nvim/lua/parth/remap.lua +++ b/nvim/lua/parth/remap.lua @@ -1,7 +1,8 @@ vim.keymap.set("n", "e", vim.cmd.NvimTreeOpen) -vim.keymap.set("n", "", vim.cmd.write) -vim.keymap.set("i", "", vim.cmd.write) +vim.keymap.set("n", "", vim.cmd.wall) +vim.keymap.set("i", "", ":w") vim.keymap.set("n", "w", vim.cmd.wq) +vim.keymap.set("n", "", vim.cmd.q) vim.keymap.set("n", "", vim.cmd.tabnew) vim.keymap.set("n", "1", "1gt") diff --git a/nvim/todo.md b/nvim/todo.md new file mode 100644 index 000000000..a5ffe3463 --- /dev/null +++ b/nvim/todo.md @@ -0,0 +1,13 @@ ++ run actions (codelens) ++ still some disatisfactory hanging lsp behaviors ++ flow for hitting cargo clippy and jumping through all the problems ++ git annotate ++ restore the file progress (there are no scrollbars) ++ use clippy instead of cargo check (it's a rust config -- checkOnSave) ++ show full path, so when you gd inside a crate you know where you are ++ rust lsp function accept add () ++ tree goto next diagnostic same way as lsp ++ find current file in tree (cntrl 1 or something) ++ dark mode light mode syntax highlighting is still kinda busted + +read about nvim rust extensions: https://github.com/rust-lang/rust-analyzer/blob/master/docs/dev/lsp-extensions.md From e8c7fa75eceb50816f11d79122a2173c00c2387a Mon Sep 17 00:00:00 2001 From: Parth Date: Sun, 14 Apr 2024 11:13:38 -0400 Subject: [PATCH 018/123] log more complaints with my current setup --- nvim/lua/parth/packer.lua | 3 +-- nvim/lua/parth/remap.lua | 1 + nvim/plugin/packer_compiled.lua | 4 ++-- nvim/todo.md | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/nvim/lua/parth/packer.lua b/nvim/lua/parth/packer.lua index 7fe2ca3bf..f4227211c 100644 --- a/nvim/lua/parth/packer.lua +++ b/nvim/lua/parth/packer.lua @@ -8,8 +8,7 @@ return require('packer').startup(function(use) use 'wbthomason/packer.nvim' use { - 'nvim-telescope/telescope.nvim', tag = '0.1.1', - -- or , branch = '0.1.x', + 'nvim-telescope/telescope.nvim', tag = '0.1.5', requires = { { 'nvim-lua/plenary.nvim' } } } diff --git a/nvim/lua/parth/remap.lua b/nvim/lua/parth/remap.lua index 6dfbf986e..d29fbc858 100644 --- a/nvim/lua/parth/remap.lua +++ b/nvim/lua/parth/remap.lua @@ -21,3 +21,4 @@ vim.keymap.set("n", "", "") vim.keymap.set("n", "", "") vim.keymap.set("n", "", "") vim.keymap.set("n", "", "") +vim.keymap.set("n", "ff", ":NvimTreeFindFile") diff --git a/nvim/plugin/packer_compiled.lua b/nvim/plugin/packer_compiled.lua index 0acdb51ff..c8ba1f389 100644 --- a/nvim/plugin/packer_compiled.lua +++ b/nvim/plugin/packer_compiled.lua @@ -49,8 +49,8 @@ local function save_profiles(threshold) end time([[Luarocks path setup]], true) -local package_path_str = "/Users/parth/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?.lua;/Users/parth/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?/init.lua;/Users/parth/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?.lua;/Users/parth/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?/init.lua" -local install_cpath_pattern = "/Users/parth/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/?.so" +local package_path_str = "/Users/parth/.cache/nvim/packer_hererocks/2.1.1696795921/share/lua/5.1/?.lua;/Users/parth/.cache/nvim/packer_hererocks/2.1.1696795921/share/lua/5.1/?/init.lua;/Users/parth/.cache/nvim/packer_hererocks/2.1.1696795921/lib/luarocks/rocks-5.1/?.lua;/Users/parth/.cache/nvim/packer_hererocks/2.1.1696795921/lib/luarocks/rocks-5.1/?/init.lua" +local install_cpath_pattern = "/Users/parth/.cache/nvim/packer_hererocks/2.1.1696795921/lib/lua/5.1/?.so" if not string.find(package.path, package_path_str, 1, true) then package.path = package.path .. ';' .. package_path_str end diff --git a/nvim/todo.md b/nvim/todo.md index a5ffe3463..16b84abe2 100644 --- a/nvim/todo.md +++ b/nvim/todo.md @@ -9,5 +9,6 @@ + tree goto next diagnostic same way as lsp + find current file in tree (cntrl 1 or something) + dark mode light mode syntax highlighting is still kinda busted ++ use a different key bind for save (lsp) vs format read about nvim rust extensions: https://github.com/rust-lang/rust-analyzer/blob/master/docs/dev/lsp-extensions.md From 87172a1abda9a26b799842865c70644203c01c75 Mon Sep 17 00:00:00 2001 From: Parth Date: Fri, 7 Jun 2024 23:41:42 -0400 Subject: [PATCH 019/123] my nvim config emerges from the ashes --- nvim/after/plugin/fugitive.lua | 1 - nvim/after/plugin/lsp.lua | 69 ---------- nvim/after/plugin/lualine.lua | 43 ------ nvim/after/plugin/nvim-tree.lua | 8 -- nvim/after/plugin/telescope.lua | 5 - nvim/after/plugin/treesitter.lua | 15 --- nvim/after/plugin/undotree.lua | 1 - nvim/deploy.sh | 2 - nvim/init.lua | 6 +- nvim/lazy-lock.json | 19 +++ nvim/lua/{parth/set.lua => config.lua} | 12 +- nvim/lua/keyboard.lua | 75 +++++++++++ nvim/lua/packages.lua | 143 ++++++++++++++++++++ nvim/lua/parth/init.lua | 3 - nvim/lua/parth/packer.lua | 58 -------- nvim/lua/parth/remap.lua | 24 ---- nvim/plugin/packer_compiled.lua | 180 ------------------------- 17 files changed, 245 insertions(+), 419 deletions(-) delete mode 100644 nvim/after/plugin/fugitive.lua delete mode 100644 nvim/after/plugin/lsp.lua delete mode 100644 nvim/after/plugin/lualine.lua delete mode 100644 nvim/after/plugin/nvim-tree.lua delete mode 100644 nvim/after/plugin/telescope.lua delete mode 100644 nvim/after/plugin/treesitter.lua delete mode 100644 nvim/after/plugin/undotree.lua create mode 100644 nvim/lazy-lock.json rename nvim/lua/{parth/set.lua => config.lua} (60%) create mode 100644 nvim/lua/keyboard.lua create mode 100644 nvim/lua/packages.lua delete mode 100644 nvim/lua/parth/init.lua delete mode 100644 nvim/lua/parth/packer.lua delete mode 100644 nvim/lua/parth/remap.lua delete mode 100644 nvim/plugin/packer_compiled.lua diff --git a/nvim/after/plugin/fugitive.lua b/nvim/after/plugin/fugitive.lua deleted file mode 100644 index 73b78b85c..000000000 --- a/nvim/after/plugin/fugitive.lua +++ /dev/null @@ -1 +0,0 @@ -vim.keymap.set("n", "gs", vim.cmd.Git); diff --git a/nvim/after/plugin/lsp.lua b/nvim/after/plugin/lsp.lua deleted file mode 100644 index 7e7dffbc0..000000000 --- a/nvim/after/plugin/lsp.lua +++ /dev/null @@ -1,69 +0,0 @@ -local lsp = require('lsp-zero') - -lsp.preset('recommended') - -lsp.ensure_installed({ - 'rust_analyzer' -}) - -local cmp = require('cmp') -local cmp_select = { behavior = cmp.SelectBehavior.Select } -local cmp_mappings = lsp.defaults.cmp_mappings({ - [''] = cmp.mapping.select_prev_item(cmp_select), - [''] = cmp.mapping.select_next_item(cmp_select), - [''] = cmp.mapping.confirm(cmp_select), - [''] = cmp.mapping.complete(), -}) - - -lsp.setup_nvim_cmp({ - mapping = cmp_mappings -}) - -lsp.set_preferences({ - suggest_lsp_servers = false, - sign_icons = { - error = 'E', - warn = 'W', - hint = 'H', - info = 'I' - } -}) - -local augroup = vim.api.nvim_create_augroup('LspFormatting', {}) -local lsp_format_on_save = function(bufnr) - vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) - vim.api.nvim_create_autocmd('BufWritePre', { - group = augroup, - buffer = bufnr, - callback = function() - vim.lsp.buf.format() - end, - }) -end - - -lsp.on_attach(function(client, bufnr) - lsp_format_on_save(bufnr) - - local opts = { buffer = bufnr, remap = false } - - vim.keymap.set("n", "ld", function() vim.lsp.buf.definition() end, opts) - vim.keymap.set("n", "h", function() vim.lsp.buf.hover() end, opts) - vim.keymap.set("n", "ws", function() vim.lsp.buf.workspace_symbol() end, opts) - vim.keymap.set("n", "vd", function() vim.diagnostic.open_float() end, opts) - vim.keymap.set("n", "nd", function() vim.diagnostic.goto_next() end, opts) - vim.keymap.set("n", "pd", function() vim.diagnostic.goto_prev() end, opts) - vim.keymap.set("n", " ", function() vim.lsp.buf.code_action() end, opts) - vim.keymap.set("n", "fr", function() vim.lsp.buf.references() end, opts) - vim.keymap.set("n", "rn", function() vim.lsp.buf.rename() end, opts) - vim.keymap.set("i", "", function() vim.lsp.buf.signature_help() end, opts) - vim.keymap.set("n", "clr", function() vim.lsp.codelens.refresh() end, opts) - vim.keymap.set("n", "cl", function() vim.lsp.codelens.run() end, opts) -end) - -lsp.setup() - -vim.diagnostic.config({ - virtual_text = true -}) diff --git a/nvim/after/plugin/lualine.lua b/nvim/after/plugin/lualine.lua deleted file mode 100644 index 38b12a303..000000000 --- a/nvim/after/plugin/lualine.lua +++ /dev/null @@ -1,43 +0,0 @@ -local lsp_status = require('lsp-status') -lsp_status.register_progress() - -require('lualine').setup { - options = { - icons_enabled = true, - theme = '16color', - component_separators = { left = '', right = ''}, - section_separators = { left = '', right = ''}, - disabled_filetypes = { - statusline = {}, - winbar = {}, - }, - ignore_focus = {}, - always_divide_middle = true, - globalstatus = false, - refresh = { - statusline = 1000, - tabline = 1000, - winbar = 1000, - } - }, - sections = { - lualine_a = {'mode'}, - lualine_b = {'branch', 'diff', 'diagnostics'}, - lualine_c = {'filename'}, - lualine_x = {'encoding', 'fileformat', 'filetype'}, - lualine_y = { "require'lsp-status'.status()" }, - lualine_z = {'location'} - }, - inactive_sections = { - lualine_a = {}, - lualine_b = {}, - lualine_c = {'filename'}, - lualine_x = {'location'}, - lualine_y = {}, - lualine_z = {} - }, - tabline = {}, - winbar = {}, - inactive_winbar = {}, - extensions = {} -} diff --git a/nvim/after/plugin/nvim-tree.lua b/nvim/after/plugin/nvim-tree.lua deleted file mode 100644 index 41f0f908b..000000000 --- a/nvim/after/plugin/nvim-tree.lua +++ /dev/null @@ -1,8 +0,0 @@ -vim.g.loaded_netrw = 1 -vim.g.loaded_netrwPlugin = 1 - -require("nvim-tree").setup({ - diagnostics = { - enable = true - } -}) diff --git a/nvim/after/plugin/telescope.lua b/nvim/after/plugin/telescope.lua deleted file mode 100644 index d314288da..000000000 --- a/nvim/after/plugin/telescope.lua +++ /dev/null @@ -1,5 +0,0 @@ -local builtin = require('telescope.builtin') -vim.keymap.set('n', 'T', builtin.find_files, {}) -vim.keymap.set('n', 't', builtin.git_files, {}) -vim.keymap.set('n', 'l', builtin.buffers, {}) -vim.keymap.set('n', 'lg', builtin.live_grep, {}) diff --git a/nvim/after/plugin/treesitter.lua b/nvim/after/plugin/treesitter.lua deleted file mode 100644 index a54a6152a..000000000 --- a/nvim/after/plugin/treesitter.lua +++ /dev/null @@ -1,15 +0,0 @@ -require'nvim-treesitter.configs'.setup { - -- A list of parser names, or "all" (the five listed parsers should always be installed) - ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "rust" }, - - -- Install parsers synchronously (only applied to `ensure_installed`) - sync_install = false, - - -- Automatically install missing parsers when entering buffer - -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally - auto_install = true, - highlight = { - enable = true, - additional_vim_regex_highlighting = false, - }, -} diff --git a/nvim/after/plugin/undotree.lua b/nvim/after/plugin/undotree.lua deleted file mode 100644 index b6b9276a5..000000000 --- a/nvim/after/plugin/undotree.lua +++ /dev/null @@ -1 +0,0 @@ -vim.keymap.set("n", "u", vim.cmd.UndotreeToggle) diff --git a/nvim/deploy.sh b/nvim/deploy.sh index bd5b80fa5..66422be1d 100755 --- a/nvim/deploy.sh +++ b/nvim/deploy.sh @@ -1,5 +1,3 @@ #!/bin/bash -git clone --depth 1 https://github.com/wbthomason/packer.nvim\ - ~/.local/share/nvim/site/pack/packer/start/packer.nvim ln -s $HOME/dotfiles/nvim $HOME/.config/nvim diff --git a/nvim/init.lua b/nvim/init.lua index 5149f6ef6..a352f1574 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1 +1,5 @@ -require("parth") +vim.g.mapleader = ' '; + +require("packages") +require("keyboard") +require("config") diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json new file mode 100644 index 000000000..7951c70eb --- /dev/null +++ b/nvim/lazy-lock.json @@ -0,0 +1,19 @@ +{ + "LuaSnip": { "branch": "master", "commit": "50fcf17db7c75af80e6b6109acfbfb4504768780" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, + "lazy.nvim": { "branch": "main", "commit": "b0ba3f9399bf48c86abaa4db1a40bd0b681d5018" }, + "lsp-status.nvim": { "branch": "master", "commit": "54f48eb5017632d81d0fd40112065f1d062d0629" }, + "lsp-zero.nvim": { "branch": "v3.x", "commit": "16de3b18c5f7b6230d89b8e64ce9a4801b6f8d08" }, + "lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "8db12610bcb7ce67013cfdfaba4dd47a23c6e851" }, + "mason.nvim": { "branch": "main", "commit": "0950b15060067f752fde13a779a994f59516ce3d" }, + "neodev.nvim": { "branch": "main", "commit": "02893eeb9d6e8503817bd52385e111cba9a90500" }, + "nvim-cmp": { "branch": "main", "commit": "5260e5e8ecadaf13e6b82cf867a909f54e15fd07" }, + "nvim-lspconfig": { "branch": "master", "commit": "92166b89ab4b3d60f24e58170cac53b7141fd032" }, + "nvim-tree.lua": { "branch": "master", "commit": "26632f496e7e3c0450d8ecff88f49068cecc8bda" }, + "nvim-treesitter": { "branch": "master", "commit": "c5cbd3ec74f6f5ddbac939e6f24b99fe78262b4c" }, + "nvim-web-devicons": { "branch": "master", "commit": "b4b302d6ae229f67df7a87ef69fa79473fe788a9" }, + "plenary.nvim": { "branch": "master", "commit": "a3e3bc82a3f95c5ed0d7201546d5d2c19b20d683" }, + "telescope.nvim": { "branch": "master", "commit": "6312868392331c9c0f22725041f1ec2bef57c751" }, + "vim-illuminate": { "branch": "master", "commit": "5eeb7951fc630682c322e88a9bbdae5c224ff0aa" } +} \ No newline at end of file diff --git a/nvim/lua/parth/set.lua b/nvim/lua/config.lua similarity index 60% rename from nvim/lua/parth/set.lua rename to nvim/lua/config.lua index 63f3b7299..207bc429f 100644 --- a/nvim/lua/parth/set.lua +++ b/nvim/lua/config.lua @@ -1,5 +1,4 @@ vim.opt.nu = true -vim.opt.relativenumber = true vim.opt.tabstop = 4 vim.opt.softtabstop = 4 @@ -12,13 +11,8 @@ vim.opt.backup = false vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir" vim.opt.undofile = true -vim.opt.hlsearch = false +vim.opt.hlsearch = true vim.opt.incsearch = true -vim.opt.scrolloff = 8 - -vim.opt.updatetime = 50 - -vim.g.mapleader = " " - -vim.cmd [[autocmd BufWritePre lua vim.lsp.buf.format()]] +vim.opt.cursorline = true +vim.api.nvim_set_hl(0, 'CursorLine', {underline=true}) diff --git a/nvim/lua/keyboard.lua b/nvim/lua/keyboard.lua new file mode 100644 index 000000000..e2e8d7a9f --- /dev/null +++ b/nvim/lua/keyboard.lua @@ -0,0 +1,75 @@ +vim.keymap.set("n", "", vim.cmd.wall) +vim.keymap.set("i", "", ":w") +vim.keymap.set("n", "w", vim.cmd.wq) +vim.keymap.set("n", "", vim.cmd.q) + +local builtin = require('telescope.builtin') +vim.keymap.set('n', 't', builtin.find_files, {}) +vim.keymap.set('n', 'T', builtin.git_files, {}) +vim.keymap.set('n', 'l', builtin.buffers, {}) +vim.keymap.set('n', 'g', builtin.grep_string, {}) +vim.keymap.set('n', 'lg', builtin.live_grep, {}) +vim.keymap.set("n", "ff", ":NvimTreeFindFile") +vim.keymap.set("n", "", "") +vim.keymap.set("n", "", "") +vim.keymap.set("n", "", "") +vim.keymap.set("n", "", "") + +vim.keymap.set('n', 'gd', vim.lsp.buf.definition, {}) + +-- LSP keybindings +vim.api.nvim_create_autocmd('LspAttach', { + desc = 'LSP actions', + callback = function(event) + local opts = {buffer = event.buf} + + vim.keymap.set('n', 'K', 'lua vim.lsp.buf.hover()', opts) + vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + vim.keymap.set('n', 'fr', builtin.lsp_references, opts) + vim.keymap.set('n', 'ws', builtin.lsp_workspace_symbols, opts) + vim.keymap.set('n', 'ds', builtin.lsp_document_symbols, opts) + vim.keymap.set('n', 'rn', 'lua vim.lsp.buf.rename()', opts) + vim.keymap.set('n', 'fmt', 'lua vim.lsp.buf.format()', opts) + vim.keymap.set('i', '', 'lua vim.lsp.buf.signature_help()', opts) + vim.keymap.set('n', 'vd', 'lua vim.diagnostic.open_float()', opts) + vim.keymap.set('n', 'nd', 'lua vim.diagnostic.goto_prev()', opts) + vim.keymap.set('n', 'pd', 'lua vim.diagnostic.goto_next()', opts) + vim.keymap.set('n', 'nr', function() require('illuminate').goto_next_reference(wrap) end, opts) + vim.keymap.set('n', 'pr', function() require('illuminate').goto_prev_reference(wrap) end, opts) + end +}) + + +-- Completion related keybindings +local cmp = require('cmp') +cmp.setup({ + sources = { + {name = 'nvim_lsp'}, + }, + mapping = { + [''] = cmp.mapping.confirm({select = false}), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.select_prev_item({behavior = 'select'}), + [''] = cmp.mapping.select_next_item({behavior = 'select'}), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item({behavior = 'insert'}) + else + cmp.complete() + end + end), + [''] = cmp.mapping(function() + if cmp.visible() then + cmp.select_next_item({behavior = 'insert'}) + else + cmp.complete() + end + end), + }, + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, +}) diff --git a/nvim/lua/packages.lua b/nvim/lua/packages.lua new file mode 100644 index 000000000..2d157e0cf --- /dev/null +++ b/nvim/lua/packages.lua @@ -0,0 +1,143 @@ +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not (vim.uv or vim.loop).fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) + +require("lazy").setup( + { + -- treesitter: richer syntax highlighting + { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + config = function () + local configs = require("nvim-treesitter.configs") + + configs.setup({ + ensure_installed = { "c", "lua", "vim", "rust", "go" }, + sync_install = false, + highlight = { enable = true }, + indent = { enable = true }, + }) + end + }, + + -- telescope + { + 'nvim-telescope/telescope.nvim', + tag = '0.1.6', + dependencies = { 'nvim-lua/plenary.nvim' } + }, + + -- lsp-zero + {'VonHeikemen/lsp-zero.nvim', branch = 'v3.x'}, + {'neovim/nvim-lspconfig'}, + {'hrsh7th/cmp-nvim-lsp'}, + {'hrsh7th/nvim-cmp'}, + {'L3MON4D3/LuaSnip'}, + {'williamboman/mason.nvim'}, + {'williamboman/mason-lspconfig.nvim'}, + + -- for nvim config lsp support + { "folke/neodev.nvim", opts = {} }, + + -- highlight words + { 'RRethy/vim-illuminate' }, + + -- lua line + { + 'nvim-lualine/lualine.nvim', + dependencies = { 'nvim-tree/nvim-web-devicons' } + }, + + -- lsp-status populated in lua line + { 'nvim-lua/lsp-status.nvim' }, + + -- nvim-tree + { + 'nvim-tree/nvim-tree.lua', + dependencies = { 'nvim-tree/nvim-web-devicons' } + } + }, + { + install = { + colorscheme = { "default" } + } + } +) + +require('lsp-zero') +require('mason').setup({}) +require('mason-lspconfig').setup({ + ensure_installed = { "rust_analyzer", "lua_ls", "gopls" }, + handlers = { + function(server_name) + require('lspconfig')[server_name].setup({}) + end, + }, +}) + +-- illuminate +require("illuminate").configure{} +vim.api.nvim_set_hl(0, "IlluminatedWordText", { link = "CursorLine" }) +vim.api.nvim_set_hl(0, "IlluminatedWordRead", { link = "CursorLine" }) +vim.api.nvim_set_hl(0, "IlluminatedWordWrite", { link = "CursorLine" }) + +-- for status line things +require('lsp-status').register_progress() +require('lualine').setup { + options = { + icons_enabled = true, + theme = '16color', + component_separators = { left = '', right = ''}, + section_separators = { left = '', right = ''}, + disabled_filetypes = { + statusline = {}, + winbar = {}, + }, + ignore_focus = {}, + always_divide_middle = true, + globalstatus = false, + refresh = { + statusline = 1000, + tabline = 1000, + winbar = 1000, + } + }, + sections = { + lualine_a = {'mode'}, + lualine_b = {'branch', 'diff', 'diagnostics'}, + lualine_c = {'filename'}, + lualine_x = {'encoding', 'fileformat', 'filetype'}, + lualine_y = { "require'lsp-status'.status()" }, + lualine_z = {'location'} + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = {'filename'}, + lualine_x = {'location'}, + lualine_y = {}, + lualine_z = {} + }, + tabline = {}, + winbar = {}, + inactive_winbar = {}, + extensions = {} +} + +-- for tree things +vim.g.loaded_netrw = 1 +vim.g.loaded_netrwPlugin = 1 +require("nvim-tree").setup({ + diagnostics = { + enable = true + } +}) diff --git a/nvim/lua/parth/init.lua b/nvim/lua/parth/init.lua deleted file mode 100644 index a6862232f..000000000 --- a/nvim/lua/parth/init.lua +++ /dev/null @@ -1,3 +0,0 @@ -require("parth.packer") -require("parth.set") -require("parth.remap") diff --git a/nvim/lua/parth/packer.lua b/nvim/lua/parth/packer.lua deleted file mode 100644 index f4227211c..000000000 --- a/nvim/lua/parth/packer.lua +++ /dev/null @@ -1,58 +0,0 @@ --- This file can be loaded by calling `lua require('plugins')` from your init.vim - --- Only required if you have packer configured as `opt` -vim.cmd [[packadd packer.nvim]] - -return require('packer').startup(function(use) - -- Packer can manage itself - use 'wbthomason/packer.nvim' - - use { - 'nvim-telescope/telescope.nvim', tag = '0.1.5', - requires = { { 'nvim-lua/plenary.nvim' } } - } - - use { - 'nvim-treesitter/nvim-treesitter', - run = ':TSUpdate' - } - - use('mbbill/undotree') - - use('tpope/vim-fugitive') - - - use { - 'VonHeikemen/lsp-zero.nvim', - branch = 'v2.x', - requires = { - -- LSP Support - { 'neovim/nvim-lspconfig' }, -- Required - { -- Optional - 'williamboman/mason.nvim', - run = function() - pcall(vim.cmd, 'MasonUpdate') - end, - }, - { 'williamboman/mason-lspconfig.nvim' }, -- Optional - { 'hrsh7th/nvim-cmp' }, -- Required - { 'hrsh7th/cmp-nvim-lsp' }, -- Required - { 'L3MON4D3/LuaSnip' }, -- Required - } - - } - - use('nvim-lua/lsp-status.nvim') - - use { - 'nvim-lualine/lualine.nvim', - requires = { 'nvim-tree/nvim-web-devicons', opt = true } - } - - use { - 'nvim-tree/nvim-tree.lua', - requires = { - 'nvim-tree/nvim-web-devicons', -- optional - }, - } -end) diff --git a/nvim/lua/parth/remap.lua b/nvim/lua/parth/remap.lua deleted file mode 100644 index d29fbc858..000000000 --- a/nvim/lua/parth/remap.lua +++ /dev/null @@ -1,24 +0,0 @@ -vim.keymap.set("n", "e", vim.cmd.NvimTreeOpen) -vim.keymap.set("n", "", vim.cmd.wall) -vim.keymap.set("i", "", ":w") -vim.keymap.set("n", "w", vim.cmd.wq) -vim.keymap.set("n", "", vim.cmd.q) - -vim.keymap.set("n", "", vim.cmd.tabnew) -vim.keymap.set("n", "1", "1gt") -vim.keymap.set("n", "2", "2gt") -vim.keymap.set("n", "3", "3gt") -vim.keymap.set("n", "4", "4gt") -vim.keymap.set("n", "5", "5gt") -vim.keymap.set("n", "6", "6gt") -vim.keymap.set("n", "7", "7gt") -vim.keymap.set("n", "8", "8gt") -vim.keymap.set("n", "9", "9gt") - -vim.keymap.set("n", "v", vim.cmd.vsplit) -vim.keymap.set("n", "h", vim.cmd.split) -vim.keymap.set("n", "", "") -vim.keymap.set("n", "", "") -vim.keymap.set("n", "", "") -vim.keymap.set("n", "", "") -vim.keymap.set("n", "ff", ":NvimTreeFindFile") diff --git a/nvim/plugin/packer_compiled.lua b/nvim/plugin/packer_compiled.lua deleted file mode 100644 index c8ba1f389..000000000 --- a/nvim/plugin/packer_compiled.lua +++ /dev/null @@ -1,180 +0,0 @@ --- Automatically generated packer.nvim plugin loader code - -if vim.api.nvim_call_function('has', {'nvim-0.5'}) ~= 1 then - vim.api.nvim_command('echohl WarningMsg | echom "Invalid Neovim version for packer.nvim! | echohl None"') - return -end - -vim.api.nvim_command('packadd packer.nvim') - -local no_errors, error_msg = pcall(function() - -_G._packer = _G._packer or {} -_G._packer.inside_compile = true - -local time -local profile_info -local should_profile = false -if should_profile then - local hrtime = vim.loop.hrtime - profile_info = {} - time = function(chunk, start) - if start then - profile_info[chunk] = hrtime() - else - profile_info[chunk] = (hrtime() - profile_info[chunk]) / 1e6 - end - end -else - time = function(chunk, start) end -end - -local function save_profiles(threshold) - local sorted_times = {} - for chunk_name, time_taken in pairs(profile_info) do - sorted_times[#sorted_times + 1] = {chunk_name, time_taken} - end - table.sort(sorted_times, function(a, b) return a[2] > b[2] end) - local results = {} - for i, elem in ipairs(sorted_times) do - if not threshold or threshold and elem[2] > threshold then - results[i] = elem[1] .. ' took ' .. elem[2] .. 'ms' - end - end - if threshold then - table.insert(results, '(Only showing plugins that took longer than ' .. threshold .. ' ms ' .. 'to load)') - end - - _G._packer.profile_output = results -end - -time([[Luarocks path setup]], true) -local package_path_str = "/Users/parth/.cache/nvim/packer_hererocks/2.1.1696795921/share/lua/5.1/?.lua;/Users/parth/.cache/nvim/packer_hererocks/2.1.1696795921/share/lua/5.1/?/init.lua;/Users/parth/.cache/nvim/packer_hererocks/2.1.1696795921/lib/luarocks/rocks-5.1/?.lua;/Users/parth/.cache/nvim/packer_hererocks/2.1.1696795921/lib/luarocks/rocks-5.1/?/init.lua" -local install_cpath_pattern = "/Users/parth/.cache/nvim/packer_hererocks/2.1.1696795921/lib/lua/5.1/?.so" -if not string.find(package.path, package_path_str, 1, true) then - package.path = package.path .. ';' .. package_path_str -end - -if not string.find(package.cpath, install_cpath_pattern, 1, true) then - package.cpath = package.cpath .. ';' .. install_cpath_pattern -end - -time([[Luarocks path setup]], false) -time([[try_loadstring definition]], true) -local function try_loadstring(s, component, name) - local success, result = pcall(loadstring(s), name, _G.packer_plugins[name]) - if not success then - vim.schedule(function() - vim.api.nvim_notify('packer.nvim: Error running ' .. component .. ' for ' .. name .. ': ' .. result, vim.log.levels.ERROR, {}) - end) - end - return result -end - -time([[try_loadstring definition]], false) -time([[Defining packer_plugins]], true) -_G.packer_plugins = { - LuaSnip = { - loaded = true, - path = "/Users/parth/.local/share/nvim/site/pack/packer/start/LuaSnip", - url = "https://github.com/L3MON4D3/LuaSnip" - }, - ["cmp-nvim-lsp"] = { - loaded = true, - path = "/Users/parth/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp", - url = "https://github.com/hrsh7th/cmp-nvim-lsp" - }, - ["lsp-status.nvim"] = { - loaded = true, - path = "/Users/parth/.local/share/nvim/site/pack/packer/start/lsp-status.nvim", - url = "https://github.com/nvim-lua/lsp-status.nvim" - }, - ["lsp-zero.nvim"] = { - loaded = true, - path = "/Users/parth/.local/share/nvim/site/pack/packer/start/lsp-zero.nvim", - url = "https://github.com/VonHeikemen/lsp-zero.nvim" - }, - ["lualine.nvim"] = { - loaded = true, - path = "/Users/parth/.local/share/nvim/site/pack/packer/start/lualine.nvim", - url = "https://github.com/nvim-lualine/lualine.nvim" - }, - ["mason-lspconfig.nvim"] = { - loaded = true, - path = "/Users/parth/.local/share/nvim/site/pack/packer/start/mason-lspconfig.nvim", - url = "https://github.com/williamboman/mason-lspconfig.nvim" - }, - ["mason.nvim"] = { - loaded = true, - path = "/Users/parth/.local/share/nvim/site/pack/packer/start/mason.nvim", - url = "https://github.com/williamboman/mason.nvim" - }, - ["nvim-cmp"] = { - loaded = true, - path = "/Users/parth/.local/share/nvim/site/pack/packer/start/nvim-cmp", - url = "https://github.com/hrsh7th/nvim-cmp" - }, - ["nvim-lspconfig"] = { - loaded = true, - path = "/Users/parth/.local/share/nvim/site/pack/packer/start/nvim-lspconfig", - url = "https://github.com/neovim/nvim-lspconfig" - }, - ["nvim-tree.lua"] = { - loaded = true, - path = "/Users/parth/.local/share/nvim/site/pack/packer/start/nvim-tree.lua", - url = "https://github.com/nvim-tree/nvim-tree.lua" - }, - ["nvim-treesitter"] = { - loaded = true, - path = "/Users/parth/.local/share/nvim/site/pack/packer/start/nvim-treesitter", - url = "https://github.com/nvim-treesitter/nvim-treesitter" - }, - ["nvim-web-devicons"] = { - loaded = false, - needs_bufread = false, - path = "/Users/parth/.local/share/nvim/site/pack/packer/opt/nvim-web-devicons", - url = "https://github.com/nvim-tree/nvim-web-devicons" - }, - ["packer.nvim"] = { - loaded = true, - path = "/Users/parth/.local/share/nvim/site/pack/packer/start/packer.nvim", - url = "https://github.com/wbthomason/packer.nvim" - }, - ["plenary.nvim"] = { - loaded = true, - path = "/Users/parth/.local/share/nvim/site/pack/packer/start/plenary.nvim", - url = "https://github.com/nvim-lua/plenary.nvim" - }, - ["telescope.nvim"] = { - loaded = true, - path = "/Users/parth/.local/share/nvim/site/pack/packer/start/telescope.nvim", - url = "https://github.com/nvim-telescope/telescope.nvim" - }, - undotree = { - loaded = true, - path = "/Users/parth/.local/share/nvim/site/pack/packer/start/undotree", - url = "https://github.com/mbbill/undotree" - }, - ["vim-fugitive"] = { - loaded = true, - path = "/Users/parth/.local/share/nvim/site/pack/packer/start/vim-fugitive", - url = "https://github.com/tpope/vim-fugitive" - } -} - -time([[Defining packer_plugins]], false) - -_G._packer.inside_compile = false -if _G._packer.needs_bufread == true then - vim.cmd("doautocmd BufRead") -end -_G._packer.needs_bufread = false - -if should_profile then save_profiles() end - -end) - -if not no_errors then - error_msg = error_msg:gsub('"', '\\"') - vim.api.nvim_command('echohl ErrorMsg | echom "Error in packer_compiled: '..error_msg..'" | echom "Please check your config for correctness" | echohl None') -end From c1692b2335e88f1ddd034b08f7e9e120fe3b6438 Mon Sep 17 00:00:00 2001 From: Parth Date: Sat, 15 Jun 2024 13:52:45 -0400 Subject: [PATCH 020/123] more tweaks to nvim --- nvim/lua/keyboard.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nvim/lua/keyboard.lua b/nvim/lua/keyboard.lua index e2e8d7a9f..b86b480c4 100644 --- a/nvim/lua/keyboard.lua +++ b/nvim/lua/keyboard.lua @@ -9,11 +9,13 @@ vim.keymap.set('n', 'T', builtin.git_files, {}) vim.keymap.set('n', 'l', builtin.buffers, {}) vim.keymap.set('n', 'g', builtin.grep_string, {}) vim.keymap.set('n', 'lg', builtin.live_grep, {}) +vim.keymap.set('n', 'o', builtin.oldfiles, {}) vim.keymap.set("n", "ff", ":NvimTreeFindFile") vim.keymap.set("n", "", "") vim.keymap.set("n", "", "") vim.keymap.set("n", "", "") vim.keymap.set("n", "", "") +vim.keymap.set("n", "/", vim.cmd.nohlsearch) vim.keymap.set('n', 'gd', vim.lsp.buf.definition, {}) @@ -30,16 +32,16 @@ vim.api.nvim_create_autocmd('LspAttach', { vim.keymap.set('n', 'ds', builtin.lsp_document_symbols, opts) vim.keymap.set('n', 'rn', 'lua vim.lsp.buf.rename()', opts) vim.keymap.set('n', 'fmt', 'lua vim.lsp.buf.format()', opts) - vim.keymap.set('i', '', 'lua vim.lsp.buf.signature_help()', opts) + vim.keymap.set('i', '', 'lua vim.lsp.buf.signature_help()', opts) vim.keymap.set('n', 'vd', 'lua vim.diagnostic.open_float()', opts) vim.keymap.set('n', 'nd', 'lua vim.diagnostic.goto_prev()', opts) vim.keymap.set('n', 'pd', 'lua vim.diagnostic.goto_next()', opts) + vim.keymap.set('n', ' ', 'lua vim.lsp.buf.code_action()', opts) vim.keymap.set('n', 'nr', function() require('illuminate').goto_next_reference(wrap) end, opts) vim.keymap.set('n', 'pr', function() require('illuminate').goto_prev_reference(wrap) end, opts) end }) - -- Completion related keybindings local cmp = require('cmp') cmp.setup({ From af427bbd33bc5b0df77da469904c576eb853b095 Mon Sep 17 00:00:00 2001 From: Parth Date: Sun, 14 Jul 2024 15:26:41 -0400 Subject: [PATCH 021/123] blame --- nvim/lazy-lock.json | 1 + nvim/lua/keyboard.lua | 6 +- nvim/lua/packages.lua | 188 ++++++++++++++++++++++-------------------- nvim/todo.md | 2 - 4 files changed, 104 insertions(+), 93 deletions(-) diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json index 7951c70eb..77edae7b2 100644 --- a/nvim/lazy-lock.json +++ b/nvim/lazy-lock.json @@ -1,5 +1,6 @@ { "LuaSnip": { "branch": "master", "commit": "50fcf17db7c75af80e6b6109acfbfb4504768780" }, + "blame.nvim": { "branch": "main", "commit": "dedbcdce857f708c63f261287ac7491a893912d0" }, "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, "lazy.nvim": { "branch": "main", "commit": "b0ba3f9399bf48c86abaa4db1a40bd0b681d5018" }, "lsp-status.nvim": { "branch": "master", "commit": "54f48eb5017632d81d0fd40112065f1d062d0629" }, diff --git a/nvim/lua/keyboard.lua b/nvim/lua/keyboard.lua index b86b480c4..03dc02139 100644 --- a/nvim/lua/keyboard.lua +++ b/nvim/lua/keyboard.lua @@ -16,9 +16,10 @@ vim.keymap.set("n", "", "") vim.keymap.set("n", "", "") vim.keymap.set("n", "", "") vim.keymap.set("n", "/", vim.cmd.nohlsearch) - vim.keymap.set('n', 'gd', vim.lsp.buf.definition, {}) +vim.keymap.set("i", "", vim.cmd.BlameToggle) + -- LSP keybindings vim.api.nvim_create_autocmd('LspAttach', { desc = 'LSP actions', @@ -75,3 +76,6 @@ cmp.setup({ end, }, }) + + +-- blame diff --git a/nvim/lua/packages.lua b/nvim/lua/packages.lua index 2d157e0cf..950f07380 100644 --- a/nvim/lua/packages.lua +++ b/nvim/lua/packages.lua @@ -1,57 +1,57 @@ local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not (vim.uv or vim.loop).fs_stat(lazypath) then - vim.fn.system({ - "git", - "clone", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", - lazypath, - }) + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", + lazypath, + }) end vim.opt.rtp:prepend(lazypath) require("lazy").setup( - { - -- treesitter: richer syntax highlighting - { - "nvim-treesitter/nvim-treesitter", - build = ":TSUpdate", - config = function () - local configs = require("nvim-treesitter.configs") + { + -- treesitter: richer syntax highlighting + { + "nvim-treesitter/nvim-treesitter", + build = ":TSUpdate", + config = function() + local configs = require("nvim-treesitter.configs") - configs.setup({ - ensure_installed = { "c", "lua", "vim", "rust", "go" }, - sync_install = false, - highlight = { enable = true }, - indent = { enable = true }, - }) - end - }, + configs.setup({ + ensure_installed = { "c", "lua", "vim", "rust", "go" }, + sync_install = false, + highlight = { enable = true }, + indent = { enable = true }, + }) + end + }, - -- telescope - { - 'nvim-telescope/telescope.nvim', - tag = '0.1.6', - dependencies = { 'nvim-lua/plenary.nvim' } - }, + -- telescope + { + 'nvim-telescope/telescope.nvim', + tag = '0.1.6', + dependencies = { 'nvim-lua/plenary.nvim' } + }, - -- lsp-zero - {'VonHeikemen/lsp-zero.nvim', branch = 'v3.x'}, - {'neovim/nvim-lspconfig'}, - {'hrsh7th/cmp-nvim-lsp'}, - {'hrsh7th/nvim-cmp'}, - {'L3MON4D3/LuaSnip'}, - {'williamboman/mason.nvim'}, - {'williamboman/mason-lspconfig.nvim'}, + -- lsp-zero + { 'VonHeikemen/lsp-zero.nvim', branch = 'v3.x' }, + { 'neovim/nvim-lspconfig' }, + { 'hrsh7th/cmp-nvim-lsp' }, + { 'hrsh7th/nvim-cmp' }, + { 'L3MON4D3/LuaSnip' }, + { 'williamboman/mason.nvim' }, + { 'williamboman/mason-lspconfig.nvim' }, -- for nvim config lsp support - { "folke/neodev.nvim", opts = {} }, + { "folke/neodev.nvim", opts = {} }, - -- highlight words + -- highlight words { 'RRethy/vim-illuminate' }, - -- lua line + -- lua line { 'nvim-lualine/lualine.nvim', dependencies = { 'nvim-tree/nvim-web-devicons' } @@ -64,28 +64,33 @@ require("lazy").setup( { 'nvim-tree/nvim-tree.lua', dependencies = { 'nvim-tree/nvim-web-devicons' } + }, + + -- blame + { + "FabijanZulj/blame.nvim", + } + }, + { + install = { + colorscheme = { "default" } } - }, - { - install = { - colorscheme = { "default" } - } - } + } ) require('lsp-zero') require('mason').setup({}) require('mason-lspconfig').setup({ - ensure_installed = { "rust_analyzer", "lua_ls", "gopls" }, - handlers = { - function(server_name) - require('lspconfig')[server_name].setup({}) - end, - }, + ensure_installed = { "rust_analyzer", "lua_ls", "gopls" }, + handlers = { + function(server_name) + require('lspconfig')[server_name].setup({}) + end, + }, }) -- illuminate -require("illuminate").configure{} +require("illuminate").configure {} vim.api.nvim_set_hl(0, "IlluminatedWordText", { link = "CursorLine" }) vim.api.nvim_set_hl(0, "IlluminatedWordRead", { link = "CursorLine" }) vim.api.nvim_set_hl(0, "IlluminatedWordWrite", { link = "CursorLine" }) @@ -93,44 +98,44 @@ vim.api.nvim_set_hl(0, "IlluminatedWordWrite", { link = "CursorLine" }) -- for status line things require('lsp-status').register_progress() require('lualine').setup { - options = { - icons_enabled = true, - theme = '16color', - component_separators = { left = '', right = ''}, - section_separators = { left = '', right = ''}, - disabled_filetypes = { - statusline = {}, - winbar = {}, + options = { + icons_enabled = true, + theme = '16color', + component_separators = { left = '', right = '' }, + section_separators = { left = '', right = '' }, + disabled_filetypes = { + statusline = {}, + winbar = {}, + }, + ignore_focus = {}, + always_divide_middle = true, + globalstatus = false, + refresh = { + statusline = 1000, + tabline = 1000, + winbar = 1000, + } }, - ignore_focus = {}, - always_divide_middle = true, - globalstatus = false, - refresh = { - statusline = 1000, - tabline = 1000, - winbar = 1000, - } - }, - sections = { - lualine_a = {'mode'}, - lualine_b = {'branch', 'diff', 'diagnostics'}, - lualine_c = {'filename'}, - lualine_x = {'encoding', 'fileformat', 'filetype'}, - lualine_y = { "require'lsp-status'.status()" }, - lualine_z = {'location'} - }, - inactive_sections = { - lualine_a = {}, - lualine_b = {}, - lualine_c = {'filename'}, - lualine_x = {'location'}, - lualine_y = {}, - lualine_z = {} - }, - tabline = {}, - winbar = {}, - inactive_winbar = {}, - extensions = {} + sections = { + lualine_a = { 'mode' }, + lualine_b = { 'branch', 'diff', 'diagnostics' }, + lualine_c = { 'filename' }, + lualine_x = { 'encoding', 'fileformat', 'filetype' }, + lualine_y = { "require'lsp-status'.status()" }, + lualine_z = { 'location' } + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { 'filename' }, + lualine_x = { 'location' }, + lualine_y = {}, + lualine_z = {} + }, + tabline = {}, + winbar = {}, + inactive_winbar = {}, + extensions = {} } -- for tree things @@ -141,3 +146,6 @@ require("nvim-tree").setup({ enable = true } }) + +-- blame +require("blame").setup() diff --git a/nvim/todo.md b/nvim/todo.md index 16b84abe2..efa3bab7c 100644 --- a/nvim/todo.md +++ b/nvim/todo.md @@ -1,7 +1,6 @@ + run actions (codelens) + still some disatisfactory hanging lsp behaviors + flow for hitting cargo clippy and jumping through all the problems -+ git annotate + restore the file progress (there are no scrollbars) + use clippy instead of cargo check (it's a rust config -- checkOnSave) + show full path, so when you gd inside a crate you know where you are @@ -9,6 +8,5 @@ + tree goto next diagnostic same way as lsp + find current file in tree (cntrl 1 or something) + dark mode light mode syntax highlighting is still kinda busted -+ use a different key bind for save (lsp) vs format read about nvim rust extensions: https://github.com/rust-lang/rust-analyzer/blob/master/docs/dev/lsp-extensions.md From 2cbf66e8420d12bc3acad7237fbb8ce97d79fbe3 Mon Sep 17 00:00:00 2001 From: Parth Date: Fri, 13 Sep 2024 13:16:32 -0400 Subject: [PATCH 022/123] fix jumping diagnostics --- nvim/lua/keyboard.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nvim/lua/keyboard.lua b/nvim/lua/keyboard.lua index 03dc02139..c63eb3cd9 100644 --- a/nvim/lua/keyboard.lua +++ b/nvim/lua/keyboard.lua @@ -19,6 +19,7 @@ vim.keymap.set("n", "/", vim.cmd.nohlsearch) vim.keymap.set('n', 'gd', vim.lsp.buf.definition, {}) vim.keymap.set("i", "", vim.cmd.BlameToggle) +vim.keymap.set("n", "", vim.cmd.BlameToggle) -- LSP keybindings vim.api.nvim_create_autocmd('LspAttach', { @@ -35,8 +36,8 @@ vim.api.nvim_create_autocmd('LspAttach', { vim.keymap.set('n', 'fmt', 'lua vim.lsp.buf.format()', opts) vim.keymap.set('i', '', 'lua vim.lsp.buf.signature_help()', opts) vim.keymap.set('n', 'vd', 'lua vim.diagnostic.open_float()', opts) - vim.keymap.set('n', 'nd', 'lua vim.diagnostic.goto_prev()', opts) - vim.keymap.set('n', 'pd', 'lua vim.diagnostic.goto_next()', opts) + vim.keymap.set('n', 'nd', 'lua vim.diagnostic.goto_next()', opts) + vim.keymap.set('n', 'pd', 'lua vim.diagnostic.goto_prev()', opts) vim.keymap.set('n', ' ', 'lua vim.lsp.buf.code_action()', opts) vim.keymap.set('n', 'nr', function() require('illuminate').goto_next_reference(wrap) end, opts) vim.keymap.set('n', 'pr', function() require('illuminate').goto_prev_reference(wrap) end, opts) From 3dfd18f03f466a2db8daf69b864be1ce88bb5e1d Mon Sep 17 00:00:00 2001 From: parth Date: Mon, 18 Nov 2024 23:58:17 -0500 Subject: [PATCH 023/123] experimenting with nix --- nix/configuration.nix | 154 ++++++++++++++++++++++++++++++++++++++++++ nix/deploy.sh | 5 ++ 2 files changed, 159 insertions(+) create mode 100644 nix/configuration.nix create mode 100755 nix/deploy.sh diff --git a/nix/configuration.nix b/nix/configuration.nix new file mode 100644 index 000000000..987a46430 --- /dev/null +++ b/nix/configuration.nix @@ -0,0 +1,154 @@ +# Edit this configuration file to define what should be installed on +# your system. Help is available in the configuration.nix(5) man page +# and in the NixOS manual (accessible by running ‘nixos-help’). + +{ config, pkgs, ... }: + +let + home-manager = builtins.fetchTarball "https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz"; +in +{ + imports = + [ # Include the results of the hardware scan. + ./hardware-configuration.nix + (import "${home-manager}/nixos") + ]; + + # Bootloader. + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + + networking.hostName = "nixos"; # Define your hostname. + # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant. + + # Configure network proxy if necessary + # networking.proxy.default = "http://user:password@proxy:port/"; + # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain"; + + # Enable networking + networking.networkmanager.enable = true; + + # Set your time zone. + time.timeZone = "America/New_York"; + + # Select internationalisation properties. + i18n.defaultLocale = "en_US.UTF-8"; + + i18n.extraLocaleSettings = { + LC_ADDRESS = "en_US.UTF-8"; + LC_IDENTIFICATION = "en_US.UTF-8"; + LC_MEASUREMENT = "en_US.UTF-8"; + LC_MONETARY = "en_US.UTF-8"; + LC_NAME = "en_US.UTF-8"; + LC_NUMERIC = "en_US.UTF-8"; + LC_PAPER = "en_US.UTF-8"; + LC_TELEPHONE = "en_US.UTF-8"; + LC_TIME = "en_US.UTF-8"; + }; + + home-manager.users.parth = { + /* The home.stateVersion option does not have a default and must be set */ + home.stateVersion = "18.09"; + /* Here goes the rest of your home-manager config, e.g. home.packages = [ pkgs.foo ]; */ + programs.git = { + enable = true; + userName = "parth"; + userEmail = "parth@mehrotra.me"; + }; + }; + + # Enable the X11 windowing system. + services.xserver.enable = true; + + # Enable the GNOME Desktop Environment. + services.xserver.displayManager.gdm.enable = true; + services.xserver.desktopManager.gnome.enable = true; + + # Configure keymap in X11 + services.xserver.xkb = { + layout = "us"; + variant = ""; + }; + + # Enable CUPS to print documents. + services.printing.enable = true; + + # Enable sound with pipewire. + hardware.pulseaudio.enable = false; + security.rtkit.enable = true; + services.pipewire = { + enable = true; + alsa.enable = true; + alsa.support32Bit = true; + pulse.enable = true; + # If you want to use JACK applications, uncomment this + #jack.enable = true; + + # use the example session manager (no others are packaged yet so this is enabled by default, + # no need to redefine it in your config for now) + #media-session.enable = true; + }; + + # Enable touchpad support (enabled default in most desktopManager). + # services.xserver.libinput.enable = true; + + # Define a user account. Don't forget to set a password with ‘passwd’. + users.users.parth = { + isNormalUser = true; + description = "parth"; + extraGroups = [ "networkmanager" "wheel" ]; + packages = with pkgs; [ + # thunderbird + ]; + }; + + # Enable automatic login for the user. + services.xserver.displayManager.autoLogin.enable = true; + services.xserver.displayManager.autoLogin.user = "parth"; + + # Workaround for GNOME autologin: https://github.com/NixOS/nixpkgs/issues/103746#issuecomment-945091229 + systemd.services."getty@tty1".enable = false; + systemd.services."autovt@tty1".enable = false; + + # Install firefox. + programs.firefox.enable = true; + + # Allow unfree packages + nixpkgs.config.allowUnfree = true; + + # List packages installed in system profile. To search, run: + # $ nix search wget + environment.systemPackages = with pkgs; [ + git + neovim + ]; + + + + # Some programs need SUID wrappers, can be configured further or are + # started in user sessions. + # programs.mtr.enable = true; + # programs.gnupg.agent = { + # enable = true; + # enableSSHSupport = true; + # }; + + # List services that you want to enable: + + # Enable the OpenSSH daemon. + # services.openssh.enable = true; + + # Open ports in the firewall. + # networking.firewall.allowedTCPPorts = [ ... ]; + # networking.firewall.allowedUDPPorts = [ ... ]; + # Or disable the firewall altogether. + # networking.firewall.enable = false; + + # This value determines the NixOS release from which the default + # settings for stateful data, like file locations and database versions + # on your system were taken. It‘s perfectly fine and recommended to leave + # this value at the release version of the first install of this system. + # Before changing this value read the documentation for this option + # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). + system.stateVersion = "24.05"; # Did you read the comment? +} diff --git a/nix/deploy.sh b/nix/deploy.sh new file mode 100755 index 000000000..573235ab4 --- /dev/null +++ b/nix/deploy.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# strangely i can copy / paste this command but not run this script + +sudo ln -s $HOME/dotfiles/nix/configuration.nix /etc/nixos/ From 49b26570ab6186eec10fc0af05e1c47bc0718d51 Mon Sep 17 00:00:00 2001 From: parth Date: Tue, 19 Nov 2024 20:28:40 -0500 Subject: [PATCH 024/123] cleanup some old --- README.md | 96 +- alacritty/alacritty.yml | 29 - deploy | 101 - nix/configuration.nix | 2 +- nix/deploy.sh | 2 +- test.sh | 9 - tmux/tmux-keybindings.conf | 30 - tmux/tmux.conf | 30 - vim/sleuth.vim | 206 -- vim/vimrc.vim | 79 - zsh/keybindings.sh | 30 - zsh/lockbook.sh | 24 - zsh/plugins/fixls.zsh | 45 - zsh/plugins/zsh-autosuggestions | 1 - zsh/plugins/zsh-syntax-highlighting | 1 - zsh/plugins/zsh-vi-mode.plugin.zsh | 6 - zsh/plugins/zsh-vi-mode.zsh | 3324 --------------------------- zsh/prompt.sh | 63 - zsh/zshrc.sh | 19 - zsh/zshrc_manager.sh | 16 - 20 files changed, 6 insertions(+), 4107 deletions(-) delete mode 100644 alacritty/alacritty.yml delete mode 100755 deploy delete mode 100755 test.sh delete mode 100644 tmux/tmux-keybindings.conf delete mode 100644 tmux/tmux.conf delete mode 100644 vim/sleuth.vim delete mode 100644 vim/vimrc.vim delete mode 100644 zsh/keybindings.sh delete mode 100644 zsh/lockbook.sh delete mode 100644 zsh/plugins/fixls.zsh delete mode 160000 zsh/plugins/zsh-autosuggestions delete mode 160000 zsh/plugins/zsh-syntax-highlighting delete mode 100644 zsh/plugins/zsh-vi-mode.plugin.zsh delete mode 100644 zsh/plugins/zsh-vi-mode.zsh delete mode 100644 zsh/prompt.sh delete mode 100644 zsh/zshrc.sh delete mode 100644 zsh/zshrc_manager.sh diff --git a/README.md b/README.md index 456391482..241d023e4 100644 --- a/README.md +++ b/README.md @@ -1,97 +1,9 @@ # Awesome Dotfiles -Simple, but extensive customization of ZSH, TMUX, and Vim. +A snapshot of my current configuration. -[![VideoWalkthrough](https://img.youtube.com/vi/UgDz_9i2nwc/0.jpg)](https://www.youtube.com/watch?v=UgDz_9i2nwc) - -## Setup Options - -There are 3 ways in which you can use this, depending on how much you think you'll be customizing. - -One of the key features is that this implementation stays in sync across all your machines. So depending on how much you'd like to customize your configuration, you have a few options: - -- Little Customization: Just clone this repo and jump to [Installation](#installation). -- Mild Customization: [Fork]() this repo, and clone your own fork. Keep an eye on this repo for bugfixes and other improvements that you'd like to incorporate into your fork. Then jump to [Installation](#installation). -- Most Customization: Building your own dotfiles from scratch! Read through these docs, watch the video above, star this repo, and create your own dotfiles! You can add this repository as a [git module](https://git-scm.com/book/en/v2/Git-Tools-Submodules) and source the parts you like. - -If you're unsure, just read the docs, watch the video, clone this repository, and jump to [Installation](#installation). - -## Installation - -Once the repo is cloned, execute the deploy script: - -```shell -./deploy -``` - -This script guides you through the following: - -1. Checks to see if you have zsh, tmux, and vim installed. -2. Installs them using your default package manager if you don't have some of them installed. -3. Checks to see if your default shell is zsh. -4. Sets zsh to your default shell. -5. Backs up your old configuration files. - -Pretty convenient for configuring new servers. - -## **Summary of Changes** - -## Basic runtime operations - -All default dotfiles (`.zshrc`, `.vimrc`, etc) source something within the dotfiles repository. This helps separate changes that are synced across all your machines with system-specific changes. +You can see an older snapshot in video form here: -Upon launching a new shell, the first thing that's evaluated is `zshrc_manager.sh`. This script first launches tmux. Then once zsh logs in, within tmux, it updates the dotfiles repository, and sources the changes. - -## [Zsh](https://en.wikipedia.org/wiki/Z_shell) - -- `cd` has been reassigned to `cd` and `ls`. Every time you navigate to a new directory, it will display the content of that directory. -- `v` has been aliased too: `vim -p`. This lets you open multiple files in vim as tabs. - -### Prompt - -The prompt takes on the form: - -```shell -[plugin, plugin, ...]: -``` - -Each plugin is sensitive to where you are and what you're doing, they reveal themselves when it's contextually relevant. Plugins include: - -- `PWD plugin`: always present, tells you where you are. Always the first plugin. -- `Status code plugin`: appears anytime a program returns with a non-zero status code. Tells you what status code the program completed with. -- `Git plugin`: appears when you're in a git repository. Tells you what branch you're on, and how many files have been changed since the last commit. -- `Sudo plugin`: tells you when you can sudo without a password. Or when you're logged in as root. -- `Time plugin`: appears when a program took more than 1s to execute. Tells you how long it took to execute. -- `PID plugin`: appears when you background a task. Tells you what the PID of the task is. - -### Keybindings - -| Key Stroke | What It Does | -| ---------- | ------------------------------------------------------------------------------------------| -| Ctrl-H | Goes to the root of a git project, runs `cd $(git rev-parse --show-toplevel || echo ".")` | -| Ctrl-K | Runs `cd ..` | -| Ctrl-G | Runs `git add -A; git commit -v && git push` | -| Ctrl-V | Runs `fc`. Takes last command and puts it in a vim buffer. | -| Ctrl-S | Adds `sudo` to the beginning of the buffer. | -| Ctrl-L | Runs `ls`. | -| Ctrl-O | Equivalent to hitting `Enter`. | -| Ctrl-P | Equivalent to pressing `Up Arrow`. | - -### Plugins - -- [zsh-autosuggestions](https://github.com/zsh-users/zsh-autosuggestions): Searches your history while you type and provides suggestions. -- [zsh-syntax-highlighting](https://github.com/zsh-users/zsh-syntax-highlighting/tree/ad522a091429ba180c930f84b2a023b40de4dbcc): Provides fish style syntax highlighting for zsh. -- [ohmyzsh](https://github.com/robbyrussell/oh-my-zsh/tree/291e96dcd034750fbe7473482508c08833b168e3): Borrowed things like tab completion, fixing ls, tmux's vi-mode plugin. -- [vimode-zsh](https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/vi-mode) allows you to hit `esc` and navigate the current buffer using vim movement keys. - -## [Vim]() - -- Leader key has been remapped to `,` - -## [Tmux](https://en.wikipedia.org/wiki/Tmux) +[![VideoWalkthrough](https://img.youtube.com/vi/UgDz_9i2nwc/0.jpg)](https://www.youtube.com/watch?v=UgDz_9i2nwc) -- Ctrl-B has been remapped to the backtick character (`). If you want to type the actual backtick character (`) itself, just hit the key twice. -- `%` has been remapped to `v`. -- Use vim movement keys for moving between panes. -- Copy buffer is copied to xclip. -- Status bar tells you date, time, user, and hostname. Especially useful with nested ssh sessions. +The date on the video should serve as a reasonable indication for the commit you may be looking for. diff --git a/alacritty/alacritty.yml b/alacritty/alacritty.yml deleted file mode 100644 index 435ebdb9c..000000000 --- a/alacritty/alacritty.yml +++ /dev/null @@ -1,29 +0,0 @@ -draw_bold_text_with_bright_colors: false - -colors: - primary: - background: '0x2D2A2E' - foreground: '0xFCFCFA' - - normal: - black: '0x403E41' - red: '0xFF6188' - green: '0xA9DC76' - yellow: '0xFFD866' - blue: '0xFC9867' - magenta: '0xAB9DF2' - cyan: '0x78DCE8' - white: '0xFCFCFA' - - bright: - black: '0x727072' - red: '0xFF6188' - green: '0xA9DC76' - yellow: '0xFFD866' - blue: '0xFC9867' - magenta: '0xAB9DF2' - cyan: '0x78DCE8' - white: '0xFCFCFA' - -key_bindings: -- { key: N, mods: Command, action: SpawnNewInstance } diff --git a/deploy b/deploy deleted file mode 100755 index 13e48d429..000000000 --- a/deploy +++ /dev/null @@ -1,101 +0,0 @@ -prompt_install() { - echo -n "$1 is not installed. Would you like to install it? (y/n) " >&2 - old_stty_cfg=$(stty -g) - stty raw -echo - answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done ) - stty $old_stty_cfg && echo - if echo "$answer" | grep -iq "^y" ;then - # This could def use community support - if [ -x "$(command -v apt-get)" ]; then - sudo apt-get install $1 -y - - elif [ -x "$(command -v brew)" ]; then - brew install $1 - - elif [ -x "$(command -v pkg)" ]; then - sudo pkg install $1 - - elif [ -x "$(command -v pacman)" ]; then - sudo pacman -S $1 - - else - echo "I'm not sure what your package manager is! Please install $1 on your own and run this deploy script again. Tests for package managers are in the deploy script you just ran starting at line 13. Feel free to make a pull request at https://github.com/parth/dotfiles :)" - fi - fi -} - -check_for_software() { - echo "Checking to see if $1 is installed" - if ! [ -x "$(command -v $1)" ]; then - prompt_install $1 - else - echo "$1 is installed." - fi -} - -check_default_shell() { - if [ -z "${SHELL##*zsh*}" ] ;then - echo "Default shell is zsh." - else - echo -n "Default shell is not zsh. Do you want to chsh -s \$(which zsh)? (y/n)" - old_stty_cfg=$(stty -g) - stty raw -echo - answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done ) - stty $old_stty_cfg && echo - if echo "$answer" | grep -iq "^y" ;then - chsh -s $(which zsh) - else - echo "Warning: Your configuration won't work properly. If you exec zsh, it'll exec tmux which will exec your default shell which isn't zsh." - fi - fi -} - -echo "We're going to do the following:" -echo "1. Grab dependencies" -echo "2. Check to make sure you have zsh, vim, and tmux installed" -echo "3. We'll help you install them if you don't" -echo "4. We're going to check to see if your default shell is zsh" -echo "5. We'll try to change it if it's not" - -echo "Let's get started? (y/n)" -old_stty_cfg=$(stty -g) -stty raw -echo -answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done ) -stty $old_stty_cfg -if echo "$answer" | grep -iq "^y" ;then - echo -else - echo "Quitting, nothing was changed." - exit 0 -fi - -git submodule update --init --recursive -check_for_software zsh -echo -check_for_software vim -echo -check_for_software tmux -echo - -check_default_shell - -echo -echo -n "Would you like to backup your current dotfiles? (y/n) " -old_stty_cfg=$(stty -g) -stty raw -echo -answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done ) -stty $old_stty_cfg -if echo "$answer" | grep -iq "^y" ;then - mv ~/.zshrc ~/.zshrc.old - mv ~/.tmux.conf ~/.tmux.conf.old - mv ~/.vimrc ~/.vimrc.old -else - echo -e "\nNot backing up old dotfiles." -fi - -printf "source '$HOME/dotfiles/zsh/zshrc_manager.sh'" > ~/.zshrc -printf "so $HOME/dotfiles/vim/vimrc.vim" > ~/.vimrc -printf "source-file $HOME/dotfiles/tmux/tmux.conf" > ~/.tmux.conf - -echo -echo "Please log out and log back in for default shell to be initialized." diff --git a/nix/configuration.nix b/nix/configuration.nix index 987a46430..5803b45bf 100644 --- a/nix/configuration.nix +++ b/nix/configuration.nix @@ -62,7 +62,7 @@ in # Enable the GNOME Desktop Environment. services.xserver.displayManager.gdm.enable = true; - services.xserver.desktopManager.gnome.enable = true; + services.xserver.desktopManager.kde.enable = true; # Configure keymap in X11 services.xserver.xkb = { diff --git a/nix/deploy.sh b/nix/deploy.sh index 573235ab4..bbe6e5325 100755 --- a/nix/deploy.sh +++ b/nix/deploy.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # strangely i can copy / paste this command but not run this script diff --git a/test.sh b/test.sh deleted file mode 100755 index b9c925327..000000000 --- a/test.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash -# test_commits.sh - -while read -r rev; do - # git checkout "$rev" - echo $rev - du -sh . - # du -sh * -done < <(git rev-list 3d173732fcba5ebf6d2a3278f910b64be73e1943 681e62d2ac243da27924c5a610a2bc087f8f8a3c) diff --git a/tmux/tmux-keybindings.conf b/tmux/tmux-keybindings.conf deleted file mode 100644 index 72ff8db38..000000000 --- a/tmux/tmux-keybindings.conf +++ /dev/null @@ -1,30 +0,0 @@ -# Prefix -unbind C-b -set -g prefix ` -bind ` send-prefix - -# New window -unbind '"' -unbind % -bind '"' split-window -c "#{pane_current_path}" -bind v split-window -h -c "#{pane_current_path}" -bind c new-window -c "#{pane_current_path}" - -# Easy Config Reloads -bind r source-file ~/.tmux.conf - -# Direction -bind h select-pane -L -bind j select-pane -D -bind k select-pane -U -bind l select-pane -R - -# Vim selection: -unbind [ -bind Escape copy-mode -unbind p -bind p paste-buffer -bind-key -Tcopy-mode-vi 'v' send -X begin-selection -bind-key -Tcopy-mode-vi 'y' send -X copy-pipe "~/dotfiles/utils/copy" - -setw -g mode-keys vi diff --git a/tmux/tmux.conf b/tmux/tmux.conf deleted file mode 100644 index 28a41ec68..000000000 --- a/tmux/tmux.conf +++ /dev/null @@ -1,30 +0,0 @@ -set -g default-terminal "screen-256color" -source-file ~/dotfiles/tmux/tmux-keybindings.conf -set -g focus-events on - -# Enable mouse mode (tmux 2.1 and above) -set -g mouse on - -# Quiet -set-option -g visual-activity off -set-option -g visual-bell off -set-option -g visual-silence off -set-window-option -g monitor-activity off -set-option -g bell-action none - -# Panes -set -g pane-border-style fg=black,bright -set -g pane-active-border-style fg=yellow -set -g base-index 1 - -# Statusbarset -g status-style bg=black -set -g status-style bg=yellow -set -g status-left '' -set -g status-right '#[fg=black,bg=yellow] #(whoami)@#H ' -set -g status-right-length 70 -setw -g window-status-current-format '#[fg=yellow,bg=black] #I #W #F ' -setw -g window-status-format '#[fg=black,bg=yellow][#I #W #F]' -set -g window-status-separator '' -set-option -g history-limit 250000 - -set-option -g renumber-windows on diff --git a/vim/sleuth.vim b/vim/sleuth.vim deleted file mode 100644 index e5f635500..000000000 --- a/vim/sleuth.vim +++ /dev/null @@ -1,206 +0,0 @@ -" sleuth.vim - Heuristically set buffer options -" Maintainer: Tim Pope -" Version: 1.1 -" GetLatestVimScripts: 4375 1 :AutoInstall: sleuth.vim - -if exists("g:loaded_sleuth") || v:version < 700 || &cp - finish -endif -let g:loaded_sleuth = 1 - -function! s:guess(lines) abort - let options = {} - let heuristics = {'spaces': 0, 'hard': 0, 'soft': 0} - let ccomment = 0 - let podcomment = 0 - let triplequote = 0 - let backtick = 0 - let xmlcomment = 0 - let softtab = repeat(' ', 8) - - for line in a:lines - if !len(line) || line =~# '^\s*$' - continue - endif - - if line =~# '^\s*/\*' - let ccomment = 1 - endif - if ccomment - if line =~# '\*/' - let ccomment = 0 - endif - continue - endif - - if line =~# '^=\w' - let podcomment = 1 - endif - if podcomment - if line =~# '^=\%(end\|cut\)\>' - let podcomment = 0 - endif - continue - endif - - if triplequote - if line =~# '^[^"]*"""[^"]*$' - let triplequote = 0 - endif - continue - elseif line =~# '^[^"]*"""[^"]*$' - let triplequote = 1 - endif - - if backtick - if line =~# '^[^`]*`[^`]*$' - let backtick = 0 - endif - continue - elseif line =~# '^[^`]*`[^`]*$' - let backtick = 1 - endif - - if line =~# '^\s*<\!--' - let xmlcomment = 1 - endif - if xmlcomment - if line =~# '-->' - let xmlcomment = 0 - endif - continue - endif - - if line =~# '^\t' - let heuristics.hard += 1 - elseif line =~# '^' . softtab - let heuristics.soft += 1 - endif - if line =~# '^ ' - let heuristics.spaces += 1 - endif - let indent = len(matchstr(substitute(line, '\t', softtab, 'g'), '^ *')) - if indent > 1 && (indent < 4 || indent % 2 == 0) && - \ get(options, 'shiftwidth', 99) > indent - let options.shiftwidth = indent - endif - endfor - - if heuristics.hard && !heuristics.spaces - return {'expandtab': 0, 'shiftwidth': &tabstop} - elseif heuristics.soft != heuristics.hard - let options.expandtab = heuristics.soft > heuristics.hard - if heuristics.hard - let options.tabstop = 8 - endif - endif - - return options -endfunction - -function! s:patterns_for(type) abort - if a:type ==# '' - return [] - endif - if !exists('s:patterns') - redir => capture - silent autocmd BufRead - redir END - let patterns = { - \ 'c': ['*.c'], - \ 'html': ['*.html'], - \ 'sh': ['*.sh'], - \ 'vim': ['vimrc', '.vimrc', '_vimrc'], - \ } - let setfpattern = '\s\+\%(setf\%[iletype]\s\+\|set\%[local]\s\+\%(ft\|filetype\)=\|call SetFileTypeSH(["'']\%(ba\|k\)\=\%(sh\)\@=\)' - for line in split(capture, "\n") - let match = matchlist(line, '^\s*\(\S\+\)\='.setfpattern.'\(\w\+\)') - if !empty(match) - call extend(patterns, {match[2]: []}, 'keep') - call extend(patterns[match[2]], [match[1] ==# '' ? last : match[1]]) - endif - let last = matchstr(line, '\S.*') - endfor - let s:patterns = patterns - endif - return copy(get(s:patterns, a:type, [])) -endfunction - -function! s:apply_if_ready(options) abort - if !has_key(a:options, 'expandtab') || !has_key(a:options, 'shiftwidth') - return 0 - else - for [option, value] in items(a:options) - call setbufvar('', '&'.option, value) - endfor - return 1 - endif -endfunction - -function! s:detect() abort - if &buftype ==# 'help' - return - endif - - let options = s:guess(getline(1, 1024)) - if s:apply_if_ready(options) - return - endif - let c = get(b:, 'sleuth_neighbor_limit', get(g:, 'sleuth_neighbor_limit', 20)) - let patterns = c > 0 ? s:patterns_for(&filetype) : [] - call filter(patterns, 'v:val !~# "/"') - let dir = expand('%:p:h') - while isdirectory(dir) && dir !=# fnamemodify(dir, ':h') && c > 0 - for pattern in patterns - for neighbor in split(glob(dir.'/'.pattern), "\n")[0:7] - if neighbor !=# expand('%:p') && filereadable(neighbor) - call extend(options, s:guess(readfile(neighbor, '', 256)), 'keep') - let c -= 1 - endif - if s:apply_if_ready(options) - let b:sleuth_culprit = neighbor - return - endif - if c <= 0 - break - endif - endfor - if c <= 0 - break - endif - endfor - let dir = fnamemodify(dir, ':h') - endwhile - if has_key(options, 'shiftwidth') - return s:apply_if_ready(extend({'expandtab': 1}, options)) - endif -endfunction - -setglobal smarttab - -if !exists('g:did_indent_on') - filetype indent on -endif - -function! SleuthIndicator() abort - let sw = &shiftwidth ? &shiftwidth : &tabstop - if &expandtab - return 'sw='.sw - elseif &tabstop == sw - return 'ts='.&tabstop - else - return 'sw='.sw.',ts='.&tabstop - endif -endfunction - -augroup sleuth - autocmd! - autocmd FileType * - \ if get(b:, 'sleuth_automatic', get(g:, 'sleuth_automatic', 1)) - \ | call s:detect() | endif - autocmd User Flags call Hoist('buffer', 5, 'SleuthIndicator') -augroup END - -command! -bar -bang Sleuth call s:detect() - -" vim:set et sw=2: diff --git a/vim/vimrc.vim b/vim/vimrc.vim deleted file mode 100644 index 5ec6c6779..000000000 --- a/vim/vimrc.vim +++ /dev/null @@ -1,79 +0,0 @@ -" General Vim settings - syntax enable - let mapleader="," - set autoindent - set tabstop=4 - set shiftwidth=4 - set dir=/tmp/ - set relativenumber - set number - - autocmd Filetype html setlocal sw=2 expandtab - autocmd Filetype javascript setlocal sw=4 expandtab - - set hlsearch - nnoremap :nohl:echo "Search Cleared" - nnoremap :set norelativenumber:set nonumber:echo "Line numbers turned off." - nnoremap :set relativenumber:set number:echo "Line numbers turned on." - - nnoremap n nzzzv - nnoremap N Nzzzv - - nnoremap vv 0v$ - - set listchars=tab:\|\ - nnoremap :set list! - set pastetoggle= - set mouse=a - set incsearch - -" Language Specific - " Tabs - so ~/dotfiles/vim/sleuth.vim - - " Markup - inoremap < I<A>yypa/O - - -" File and Window Management - inoremap w :w - nnoremap w :w - - inoremap q :q - nnoremap q :q - - inoremap x :x - nnoremap x :x - - nnoremap e :Ex - nnoremap t :tabnew:Ex - nnoremap v :vsplit:w:Ex - nnoremap s :split:w:Ex - -" Return to the same line you left off at - augroup line_return - au! - au BufReadPost * - \ if line("'\"") > 0 && line("'\"") <= line("$") | - \ execute 'normal! g`"zvzz' | - \ endif - augroup END - -" Auto load - " Triger `autoread` when files changes on disk - " https://unix.stackexchange.com/questions/149209/refresh-changed-content-of-file-opened-in-vim/383044#383044 - " https://vi.stackexchange.com/questions/13692/prevent-focusgained-autocmd-running-in-command-line-editing-mode - autocmd FocusGained,BufEnter,CursorHold,CursorHoldI * if mode() != 'c' | checktime | endif - set autoread - " Notification after file change - " https://vi.stackexchange.com/questions/13091/autocmd-event-for-autoread - autocmd FileChangedShellPost * - \ echohl WarningMsg | echo "File changed on disk. Buffer reloaded." | echohl None - -" Future stuff - "Swap line - "Insert blank below and above - -" Fix for: https://github.com/fatih/vim-go/issues/1509 - -filetype plugin indent on diff --git a/zsh/keybindings.sh b/zsh/keybindings.sh deleted file mode 100644 index b4d858657..000000000 --- a/zsh/keybindings.sh +++ /dev/null @@ -1,30 +0,0 @@ -# up -function up_widget() { - BUFFER="cd .." - zle accept-line -} -zle -N up_widget -bindkey "^k" up_widget - -# Enter -function enter_line() { - zle accept-line -} -zle -N enter_line -bindkey "^o" enter_line - -# Sudo -function add_sudo() { - BUFFER="sudo "$BUFFER - zle end-of-line -} -zle -N add_sudo -bindkey "^s" add_sudo - -# Home - Navigates to the current root workspace -function git_root() { - BUFFER="cd $(git rev-parse --show-toplevel || echo ".")" - zle accept-line -} -zle -N git_root -bindkey "^h" git_root diff --git a/zsh/lockbook.sh b/zsh/lockbook.sh deleted file mode 100644 index 0a5622c6f..000000000 --- a/zsh/lockbook.sh +++ /dev/null @@ -1,24 +0,0 @@ -export LOCKBOOK_EDITOR="vim" - -alias all="lockbook list-all | fzf --prompt='Select a file: '" -alias dirs="lockbook list-folders | fzf --prompt='Select a folder: '" -alias docs="lockbook list-docs | grep -v 'parth/trash' | fzf --prompt='Select a document: '" -alias edit='lockbook edit $(docs)' - -function new_document() { - BUFFER='lockbook new $(dirs)' - zle end-of-line - BUFFER='lockbook new $(dirs) && lockbook sync' -} - -zle -N new_document -bindkey "^l" new_document - -function edit_document() { - BUFFER='lockbook edit $(docs) && lockbook sync' - zle accept-line -} -zle -N edit_document -bindkey "^f" edit_document - -alias configure="vim ~/dotfiles/zsh/lockbook.sh" diff --git a/zsh/plugins/fixls.zsh b/zsh/plugins/fixls.zsh deleted file mode 100644 index 4dc8e9345..000000000 --- a/zsh/plugins/fixls.zsh +++ /dev/null @@ -1,45 +0,0 @@ -# https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/theme-and-appearance.zsh - -# ls colors -autoload -U colors && colors - -# Enable ls colors -export LSCOLORS="Gxfxcxdxbxegedabagacad" - -# TODO organise this chaotic logic - -if [[ "$DISABLE_LS_COLORS" != "true" ]]; then - # Find the option for using colors in ls, depending on the version - if [[ "$OSTYPE" == netbsd* ]]; then - # On NetBSD, test if "gls" (GNU ls) is installed (this one supports colors); - # otherwise, leave ls as is, because NetBSD's ls doesn't support -G - gls --color -d . &>/dev/null && alias ls='gls --color=tty' - elif [[ "$OSTYPE" == openbsd* ]]; then - # On OpenBSD, "gls" (ls from GNU coreutils) and "colorls" (ls from base, - # with color and multibyte support) are available from ports. "colorls" - # will be installed on purpose and can't be pulled in by installing - # coreutils, so prefer it to "gls". - gls --color -d . &>/dev/null && alias ls='gls --color=tty' - colorls -G -d . &>/dev/null && alias ls='colorls -G' - elif [[ "$OSTYPE" == darwin* ]]; then - # this is a good alias, it works by default just using $LSCOLORS - ls -G . &>/dev/null && alias ls='ls -G' - - # only use coreutils ls if there is a dircolors customization present ($LS_COLORS or .dircolors file) - # otherwise, gls will use the default color scheme which is ugly af - [[ -n "$LS_COLORS" || -f "$HOME/.dircolors" ]] && gls --color -d . &>/dev/null && alias ls='gls --color=tty' - else - # For GNU ls, we use the default ls color theme. They can later be overwritten by themes. - if [[ -z "$LS_COLORS" ]]; then - (( $+commands[dircolors] )) && eval "$(dircolors -b)" - fi - - ls --color -d . &>/dev/null && alias ls='ls --color=tty' || { ls -G . &>/dev/null && alias ls='ls -G' } - - # Take advantage of $LS_COLORS for completion as well. - zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" - fi -fi - -setopt auto_cd -setopt multios diff --git a/zsh/plugins/zsh-autosuggestions b/zsh/plugins/zsh-autosuggestions deleted file mode 160000 index fedc22e9b..000000000 --- a/zsh/plugins/zsh-autosuggestions +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fedc22e9bbd046867860e772d7d6787f5dae9d4c diff --git a/zsh/plugins/zsh-syntax-highlighting b/zsh/plugins/zsh-syntax-highlighting deleted file mode 160000 index ad522a091..000000000 --- a/zsh/plugins/zsh-syntax-highlighting +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ad522a091429ba180c930f84b2a023b40de4dbcc diff --git a/zsh/plugins/zsh-vi-mode.plugin.zsh b/zsh/plugins/zsh-vi-mode.plugin.zsh deleted file mode 100644 index 8fa87254e..000000000 --- a/zsh/plugins/zsh-vi-mode.plugin.zsh +++ /dev/null @@ -1,6 +0,0 @@ -# According to the standard: -# https://github.com/zdharma/Zsh-100-Commits-Club/blob/master/Zsh-Plugin-Standard.adoc -0="${ZERO:-${${0:#$ZSH_ARGZERO}:-${(%):-%N}}}" -0="${${(M)0:#/*}:-$PWD/$0}" - -source ${0:h}/zsh-vi-mode.zsh diff --git a/zsh/plugins/zsh-vi-mode.zsh b/zsh/plugins/zsh-vi-mode.zsh deleted file mode 100644 index bc43e0219..000000000 --- a/zsh/plugins/zsh-vi-mode.zsh +++ /dev/null @@ -1,3324 +0,0 @@ -# zsh-vi-mode.zsh -- A better and friendly vi(vim) mode for Zsh -# https://github.com/jeffreytse/zsh-vi-mode -# -# Copyright (c) 2020 Jeffrey Tse -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -# -# All Settings -# Some of these variables should be set before sourcing this file. -# -# ZVM_VI_ESCAPE_BINDKEY -# the vi escape key for all modes (default is ^[ => ), you can set it -# to whatever you like, such as `jj`, `jk` and so on. -# -# ZVM_VI_INSERT_ESCAPE_BINDKEY -# the vi escape key of insert mode (default is $ZVM_VI_ESCAPE_BINDKEY), you -# can set it to whatever, such as `jj`, `jk` and so on. -# -# ZVM_VI_VISUAL_ESCAPE_BINDKEY -# the vi escape key of visual mode (default is $ZVM_VI_ESCAPE_BINDKEY), you -# can set it to whatever, such as `jj`, `jk` and so on. -# -# ZVM_VI_OPPEND_ESCAPE_BINDKEY -# the vi escape key of operator pendding mode (default is -# $ZVM_VI_ESCAPE_BINDKEY), you can set it to whatever, such as `jj`, `jk` -# and so on. -# -# ZVM_VI_INSERT_MODE_LEGACY_UNDO: -# using legacy undo behavior in vi insert mode -# -# ZVM_VI_HIGHLIGHT_BACKGROUND: -# the behavior of highlight (surrounds, visual-line, etc) in vi mode -# -# For example: -# ZVM_VI_HIGHLIGHT_BACKGROUND=red # Color name -# ZVM_VI_HIGHLIGHT_BACKGROUND=#ff0000 # Hex value -# -# ZVM_VI_SURROUND_BINDKEY -# the key binding mode for surround operating (default is 'classic') -# -# 1. 'classic' mode (verb->s->surround): -# S" Add " for visual selection -# ys" Add " for visual selection -# cs"' Change " to ' -# ds" Delete " -# -# 2. 's-prefix' mode (s->verb->surround): -# sa" Add " for visual selection -# sd" Delete " -# sr"' Change " to ' -# -# How to select surround text object? -# vi" Select the text object inside the quotes -# va( Select the text object including the brackets -# -# Then you can do any operation for the selection: -# -# 1. Add surrounds for text object -# vi" -> S[ or sa[ => "object" -> "[object]" -# -# 2. Delete/Yank/Change text object -# di( or vi( -> d -# ca( or va( -> c -# yi( or vi( -> y -# -# ZVM_READKEY_ENGINE -# the readkey engine for reading and processing the key events, and the -# below engines are supported: -# ZVM_READKEY_ENGINE_NEX (Default) -# ZVM_READKEY_ENGINE_ZLE -# -# the NEX is a better engine for reading and handling the key events than -# the Zsh's ZLE engine, currently the NEX engine is at beta stage, and -# you can change to Zsh's ZLE engine if you want. -# -# ZVM_KEYTIMEOUT: -# the key input timeout for waiting for next key (default is 0.4 seconds) -# -# ZVM_ESCAPE_KEYTIMEOUT: -# the key input timeout for waiting for next key if it is beginning with -# an escape character (default is 0.03 seconds), and this option is just -# available for the NEX readkey engine -# -# ZVM_LINE_INIT_MODE -# the setting for init mode of command line (default is empty), empty will -# keep the last command mode, for the first command line it will be insert -# mode, you can also set it to a specific vi mode to alway keep the mode -# for each command line -# -# For example: -# ZVM_LINE_INIT_MODE=$ZVM_MODE_INSERT -# ZVM_LINE_INIT_MODE=$ZVM_MODE_NORMAL -# -# ZVM_LAZY_KEYBINDINGS: -# the setting for lazy keybindings (default is true), and lazy keybindings -# will postpone the keybindings of vicmd and visual keymaps to the first -# time entering normal mode -# -# ZVM_NORMAL_MODE_CURSOR: -# the prompt cursor in normal mode -# -# ZVM_INSERT_MODE_CURSOR: -# the prompt cursor in insert mode -# -# ZVM_VISUAL_MODE_CURSOR: -# the prompt cursor in visual mode -# -# ZVM_VISUAL_LINE_MODE_CURSOR: -# the prompt cursor in visual line mode -# -# ZVM_OPPEND_MODE_CURSOR: -# the prompt cursor in operator pending mode -# -# You can change the cursor style by below: -# ZVM_INSERT_MODE_CURSOR=$ZVM_CURSOR_BLOCK -# -# and the below cursor style are supported: -# ZVM_CURSOR_USER_DEFAULT -# ZVM_CURSOR_BLOCK -# ZVM_CURSOR_UNDERLINE -# ZVM_CURSOR_BEAM -# ZVM_CURSOR_BLINKING_BLOCK -# ZVM_CURSOR_BLINKING_UNDERLINE -# ZVM_CURSOR_BLINKING_BEAM -# -# ZVM_VI_EDITOR -# the editor to edit your command line (default is $EDITOR) -# -# ZVM_TMPDIR -# the temporary directory (default is $TMPDIR, otherwise it's /tmp/) -# -# ZVM_TERM -# the term for handling terminal sequences, it's important for some -# terminal emulators to show cursor properly (default is $TERM) -# -# ZVM_CURSOR_STYLE_ENABLED -# enable the cursor style feature (default is true) -# - -# Avoid sourcing plugin multiple times -command -v 'zvm_version' >/dev/null && return - -# Plugin information -typeset -gr ZVM_NAME='zsh-vi-mode' -typeset -gr ZVM_DESCRIPTION='💻 A better and friendly vi(vim) mode plugin for ZSH.' -typeset -gr ZVM_REPOSITORY='https://github.com/jeffreytse/zsh-vi-mode' -typeset -gr ZVM_VERSION='0.8.3' - -# Plugin initial status -ZVM_INIT_DONE=false - -# Disable reset prompt (i.e. disable the widget `reset-prompt`) -ZVM_RESET_PROMPT_DISABLED=false - -# Operator pending mode -ZVM_OPPEND_MODE=false - -# Insert mode could be -# `i` (insert) -# `a` (append) -# `I` (insert at the non-blank beginning of current line) -# `A` (append at the end of current line) -ZVM_INSERT_MODE='i' - -# The mode could be the below value: -# `n` (normal) -# `i` (insert) -# `v` (visual) -# `vl` (visual-line) -ZVM_MODE='' - -# The keys typed to invoke this widget, as a literal string -ZVM_KEYS='' - -# The region hilight information -ZVM_REGION_HIGHLIGHT=() - -# Default zvm readkey engines -ZVM_READKEY_ENGINE_NEX='nex' -ZVM_READKEY_ENGINE_ZLE='zle' -ZVM_READKEY_ENGINE_DEFAULT=$ZVM_READKEY_ENGINE_NEX - -# Default alternative character for escape characters -ZVM_ESCAPE_SPACE='\s' -ZVM_ESCAPE_NEWLINE='^J' - -# Default vi modes -ZVM_MODE_LAST='' -ZVM_MODE_NORMAL='n' -ZVM_MODE_INSERT='i' -ZVM_MODE_VISUAL='v' -ZVM_MODE_VISUAL_LINE='vl' -ZVM_MODE_REPLACE='r' - -# Default cursor styles -ZVM_CURSOR_USER_DEFAULT='ud' -ZVM_CURSOR_BLOCK='bl' -ZVM_CURSOR_UNDERLINE='ul' -ZVM_CURSOR_BEAM='be' -ZVM_CURSOR_BLINKING_BLOCK='bbl' -ZVM_CURSOR_BLINKING_UNDERLINE='bul' -ZVM_CURSOR_BLINKING_BEAM='bbe' - -# The commands need to be repeated -ZVM_REPEAT_MODE=false -ZVM_REPEAT_RESET=false -ZVM_REPEAT_COMMANDS=($ZVM_MODE_NORMAL i) - -########################################## -# Initial all default settings - -# Set the readkey engine (default is NEX engine) -: ${ZVM_READKEY_ENGINE:=$ZVM_READKEY_ENGINE_DEFAULT} - -# Set key input timeout (default is 0.4 seconds) -: ${ZVM_KEYTIMEOUT:=0.4} - -# Set the escape key timeout (default is 0.03 seconds) -: ${ZVM_ESCAPE_KEYTIMEOUT:=0.03} - -# Set keybindings mode (default is true) -# The lazy keybindings will post the keybindings of vicmd and visual -# keymaps to the first time entering the normal mode -: ${ZVM_LAZY_KEYBINDINGS:=true} - -# All keybindings for lazy loading -if $ZVM_LAZY_KEYBINDINGS; then - ZVM_LAZY_KEYBINDINGS_LIST=() -fi - -# Set the cursor stlye in defferent vi modes, the value you could use -# the predefined value, such as $ZVM_CURSOR_BLOCK, $ZVM_CURSOR_BEAM, -# $ZVM_CURSOR_BLINKING_BLOCK and so on. -: ${ZVM_INSERT_MODE_CURSOR:=$ZVM_CURSOR_BEAM} -: ${ZVM_NORMAL_MODE_CURSOR:=$ZVM_CURSOR_BLOCK} -: ${ZVM_VISUAL_MODE_CURSOR:=$ZVM_CURSOR_BLOCK} -: ${ZVM_VISUAL_LINE_MODE_CURSOR:=$ZVM_CURSOR_BLOCK} - -# Operator pending mode cursor style (default is underscore) -: ${ZVM_OPPEND_MODE_CURSOR:=$ZVM_CURSOR_UNDERLINE} - -# Set the vi escape key (default is ^[ => ) -: ${ZVM_VI_ESCAPE_BINDKEY:=^[} -: ${ZVM_VI_INSERT_ESCAPE_BINDKEY:=$ZVM_VI_ESCAPE_BINDKEY} -: ${ZVM_VI_VISUAL_ESCAPE_BINDKEY:=$ZVM_VI_ESCAPE_BINDKEY} -: ${ZVM_VI_OPPEND_ESCAPE_BINDKEY:=$ZVM_VI_ESCAPE_BINDKEY} - -# Set the line init mode (empty will keep the last mode) -# you can also set it to others, such as $ZVM_MODE_INSERT. -: ${ZVM_LINE_INIT_MODE:=$ZVM_MODE_LAST} - -: ${ZVM_VI_INSERT_MODE_LEGACY_UNDO:=false} -: ${ZVM_VI_SURROUND_BINDKEY:=classic} -: ${ZVM_VI_HIGHLIGHT_BACKGROUND:=#cc0000} -: ${ZVM_VI_EDITOR:=${EDITOR:-vim}} -: ${ZVM_TMPDIR:=${TMPDIR:-/tmp/}} - -# Set the term for handling terminal sequences, it's important for some -# terminal emulators to show cursor properly (default is $TERM) -: ${ZVM_TERM:=${TERM:-xterm-256color}} - -# Enable the cursor style feature -: ${ZVM_CURSOR_STYLE_ENABLED:=true} - -# All the extra commands -zvm_before_init_commands=() -zvm_after_init_commands=() -zvm_before_select_vi_mode_commands=() -zvm_after_select_vi_mode_commands=() -zvm_before_lazy_keybindings_commands=() -zvm_after_lazy_keybindings_commands=() - -# All the handlers for switching keyword -zvm_switch_keyword_handlers=( - zvm_switch_number - zvm_switch_boolean - zvm_switch_operator - zvm_switch_weekday - zvm_switch_month -) - -# Display version information -function zvm_version() { - echo -e "$ZVM_NAME $ZVM_VERSION" - echo -e "\e[4m$ZVM_REPOSITORY\e[0m" - echo -e "$ZVM_DESCRIPTION" -} - -# The widget wrapper -function zvm_widget_wrapper() { - local rawfunc=$1; - local func=$2; - local -i retval - $func "${@:3}" - return retval -} - -# Define widget function -function zvm_define_widget() { - local widget=$1 - local func=$2 || $1 - local result=($(zle -l -L "${widget}")) - - # Check if existing the same name - if [[ ${#result[@]} == 4 ]]; then - local rawfunc=${result[4]} - local wrapper="zvm_${widget}-wrapper" - eval "$wrapper() { zvm_widget_wrapper $rawfunc $func \"\$@\" }" - func=$wrapper - fi - - zle -N $widget $func -} - -# Get the keys typed to invoke this widget, as a literal string -function zvm_keys() { - local keys=${ZVM_KEYS:-$KEYS} - - # Append the prefix of keys if it is visual or visual-line mode - case "${ZVM_MODE}" in - $ZVM_MODE_VISUAL) - if [[ "$keys" != v* ]]; then - keys="v${keys}" - fi - ;; - $ZVM_MODE_VISUAL_LINE) - if [[ "$keys" != V* ]]; then - keys="V${keys}" - fi - ;; - esac - - # Escape the newline and space characters, otherwise, we can't - # get the output from subshell correctly. - keys=${keys//$'\n'/$ZVM_ESCAPE_NEWLINE} - keys=${keys// /$ZVM_ESCAPE_SPACE} - - echo $keys -} - -# Find the widget on a specified bindkey -function zvm_find_bindkey_widget() { - local keymap=$1 - local keys=$2 - local prefix_mode=${3:-false} - retval=() - - if $prefix_mode; then - local pos=0 - local spos=3 - local prefix_keys= - - # Get the prefix keys - if [[ $prefix_keys ]]; then - prefix_keys=${prefix_keys:0:-1} - - # If the last key is an escape key (e.g. \", \`, \\) we still - # need to remove the escape backslash `\` - if [[ ${prefix_keys: -1} == '\' ]]; then - prefix_keys=${prefix_keys:0:-1} - fi - fi - - local result=$(bindkey -M ${keymap} -p "$prefix_keys")$'\n' - - # Split string to array by newline - for ((i=$spos;i<$#result;i++)); do - - # Save the last whitespace character of the line - # and continue continue handling while meeting `\n` - case "${result:$i:1}" in - ' ') spos=$i; i=$i+1; continue;; - [$'\n']);; - *) continue;; - esac - - # Check if it has the same prefix keys and retrieve the widgets - if [[ "${result:$((pos+1)):$#keys}" == "$keys" ]]; then - - # Get the binding keys - local k=${result:$((pos+1)):$((spos-pos-2))} - - # Escape spaces in key bindings (space -> $ZVM_ESCAPE_SPACE) - k=${k// /$ZVM_ESCAPE_SPACE} - retval+=($k ${result:$((spos+1)):$((i-spos-1))}) - fi - - # Save as new position - pos=$i+1 - - # Skip 3 characters - # One key and quotes at least (i.e \n"_" ) - i=$i+3 - done - else - local result=$(bindkey -M ${keymap} "$keys") - if [[ "${result: -14}" == ' undefined-key' ]]; then - return - fi - - # Escape spaces in key bindings (space -> $ZVM_ESCAPE_SPACE) - for ((i=$#result;i>=0;i--)); do - - # Backward find the first whitespace character - [[ "${result:$i:1}" == ' ' ]] || continue - - # Retrieve the keys and widget - local k=${result:1:$i-2} - - # Escape spaces in key bindings (space -> $ZVM_ESCAPE_SPACE) - k=${k// /$ZVM_ESCAPE_SPACE} - retval+=($k ${result:$i+1}) - - break - done - fi -} - -# Read keys for retrieving widget -function zvm_readkeys() { - local keymap=$1 - local key=${2:-$(zvm_keys)} - local keys= - local widget= - local result= - local pattern= - local timeout= - - # Escape the non-printed characters - pattern=$(zvm_escape_non_printed_characters "${keys}") - pattern=${pattern//$ZVM_ESCAPE_SPACE/ } - - while :; do - # Keep reading key for escape character - if [[ "$key" == '' ]]; then - while :; do - local k= - read -t $ZVM_ESCAPE_KEYTIMEOUT -k 1 k || break - key="${key}${k}" - done - fi - - keys="${keys}${key}" - - # Handle the pattern - if [[ -n "$key" ]]; then - # Transform the non-printed characters - local k=$(zvm_escape_non_printed_characters "${key}") - - # Escape keys - # " -> \" It's a special character in bash syntax - # ` -> \` It's a special character in bash syntax - # -> ` ` It's a special character in bash syntax - k=${k//\"/\\\"} - k=${k//\`/\\\`} - k=${k//$ZVM_ESCAPE_SPACE/ } - - pattern="${pattern}${k}" - fi - - # Find out widgets that match this key pattern - zvm_find_bindkey_widget $keymap "$pattern" true - result=(${retval[@]}) - - # Exit key input if there is only one widget matched - # or no more widget matched. - case ${#result[@]} in - 2) key=; widget=${result[2]}; break;; - 0) break;; - esac - - # Evaluate the readkey timeout - # Special timeout for the escape sequence - if [[ "${keys}" ==  ]]; then - timeout=$ZVM_ESCAPE_KEYTIMEOUT - # Check if there is any one custom escape sequence - for ((i=1; i<=${#result[@]}; i=i+2)); do - if [[ "${result[$i]}" =~ '^\^\[\[?[A-Z0-9]*~?\^\[' ]]; then - timeout=$ZVM_KEYTIMEOUT - break - fi - done - else - timeout=$ZVM_KEYTIMEOUT - fi - - # Wait for reading next key, and we should save the widget - # as the final widget if it is full matching - key= - if [[ "${result[1]}" == "${pattern}" ]]; then - widget=${result[2]} - # Get current widget as final widget when reading key timeout - read -t $timeout -k 1 key || break - else - zvm_enter_oppend_mode - read -k 1 key - fi - done - - # Exit operator pending mode - if $ZVM_OPPEND_MODE; then - zvm_exit_oppend_mode - fi - - if [[ -z "$key" ]]; then - retval=(${keys} $widget) - else - retval=(${keys:0:-$#key} $widget $key) - fi -} - -# Add key bindings -function zvm_bindkey() { - local keymap=$1 - local keys=$2 - local widget=$3 - local params=$4 - local key= - - # We should bind keys with an existing widget - [[ -z $widget ]] && return - - # If lazy keybindings is enabled, we need to add to the lazy list - if [[ ${ZVM_LAZY_KEYBINDINGS_LIST+x} && ${keymap} != viins ]]; then - keys=${keys//\"/\\\"} - keys=${keys//\`/\\\`} - ZVM_LAZY_KEYBINDINGS_LIST+=( - "${keymap} \"${keys}\" ${widget} \"${params}\"" - ) - return - fi - - # Hanle the keybinding of NEX readkey engine - if [[ $ZVM_READKEY_ENGINE == $ZVM_READKEY_ENGINE_NEX ]]; then - # Get the first key (especially check if ctrl characters) - if [[ $#keys -gt 1 && "${keys:0:1}" == '^' ]]; then - key=${keys:0:2} - else - key=${keys:0:1} - fi - bindkey -M $keymap "${key}" zvm_readkeys_handler - fi - - # Wrap params to a new widget - if [[ -n $params ]]; then - local suffix=$(zvm_string_to_hex $params) - eval "$widget:$suffix() { $widget $params }" - widget="$widget:$suffix" - zvm_define_widget $widget - fi - - # Bind keys with with a widget - bindkey -M $keymap "${keys}" $widget -} - -# Convert string to hexadecimal -function zvm_string_to_hex() { - local str= - for ((i=1;i<=$#1;i++)); do - str+=$(printf '%x' "'${1[$i]}") - done - echo "$str" -} - -# Escape non-printed characters -function zvm_escape_non_printed_characters() { - local str= - for ((i=0;i<$#1;i++)); do - local c=${1:$i:1} - if [[ "$c" < ' ' ]]; then - local ord=$(($(printf '%d' "'$c")+64)) - c=$(printf \\$(printf '%03o' $ord)) - str="${str}^${c}" - elif [[ "$c" == '' ]]; then - str="${str}^?" - elif [[ "$c" == '' ]]; then - str="${str}^@" - else - str="${str}${c}" - fi - done - - # Escape the newline and space characters, otherwise, we can't - # get the output from subshell correctly. - str=${str// /$ZVM_ESCAPE_SPACE} - str=${str//$'\n'/$ZVM_ESCAPE_NEWLINE} - - echo -n $str -} - -# Backward remove characters of an emacs region in the line -function zvm_backward_kill_region() { - local bpos=$CURSOR-1 epos=$CURSOR - - # Backward search the boundary of current region - for ((; bpos >= 0; bpos--)); do - # Break when cursor is at the beginning of line - [[ "${BUFFER:$bpos:1}" == $'\n' ]] && break - - # Break when cursor is at the boundary of a word region - [[ "${BUFFER:$bpos:2}" =~ ^\ [^\ $'\n']$ ]] && break - done - - bpos=$bpos+1 - CUTBUFFER=${BUFFER:$bpos:$((epos-bpos))} - BUFFER="${BUFFER:0:$bpos}${BUFFER:$epos}" - CURSOR=$bpos -} - -# Remove all characters between the cursor position and the -# beginning of the line. -function zvm_backward_kill_line() { - BUFFER=${BUFFER:$CURSOR:$#BUFFER} - CURSOR=0 -} - -# Remove all characters between the cursor position and the -# end of the line. -function zvm_forward_kill_line() { - BUFFER=${BUFFER:0:$CURSOR} -} - -# Remove all characters of the line. -function zvm_kill_line() { - local ret=($(zvm_calc_selection $ZVM_MODE_VISUAL_LINE)) - local bpos=${ret[1]} epos=${ret[2]} - CUTBUFFER=${BUFFER:$bpos:$((epos-bpos))}$'\n' - BUFFER="${BUFFER:0:$bpos}${BUFFER:$epos}" - CURSOR=$bpos -} - -# Remove all characters of the whole line. -function zvm_kill_whole_line() { - local ret=($(zvm_calc_selection $ZVM_MODE_VISUAL_LINE)) - local bpos=$ret[1] epos=$ret[2] cpos=$ret[3] - CUTBUFFER=${BUFFER:$bpos:$((epos-bpos))}$'\n' - - # Adjust region range of deletion - if (( $epos < $#BUFFER )); then - epos=$epos+1 - fi - - BUFFER="${BUFFER:0:$bpos}${BUFFER:$epos}" - CURSOR=$cpos -} - -# Exchange the point and mark -function zvm_exchange_point_and_mark() { - cursor=$MARK - MARK=$CURSOR CURSOR=$cursor - zvm_highlight -} - -# Open line below -function zvm_open_line_below() { - local i=$CURSOR - - # If there is a completion suffix, we should break at the - # postion of suffix begin, otherwise, it should break when - # forward finding out the first newline character. - for ((; i<$#BUFFER; i++)); do - if ((SUFFIX_ACTIVE == 1)) && ((i >= SUFFIX_BEGIN)); then - break - fi - if [[ "${BUFFER[$i]}" == $'\n' ]]; then - i=$((i-1)) - break - fi - done - - CURSOR=$i - LBUFFER+=$'\n' - - zvm_reset_repeat_commands $ZVM_MODE_NORMAL o - zvm_select_vi_mode $ZVM_MODE_INSERT -} - -# Open line above -function zvm_open_line_above() { - local i=$CURSOR - - # Break when backward finding out the first newline character. - for ((; i>0; i--)); do - if [[ "${BUFFER[$i]}" == $'\n' ]]; then - break - fi - done - - CURSOR=$i - LBUFFER+=$'\n' - CURSOR=$((CURSOR-1)) - - zvm_reset_repeat_commands $ZVM_MODE_NORMAL O - zvm_select_vi_mode $ZVM_MODE_INSERT -} - -# Replace characters one by one (Replacing mode) -function zvm_vi_replace() { - if [[ $ZVM_MODE == $ZVM_MODE_NORMAL ]]; then - local cursor=$CURSOR - local cache=() - local cmds=() - local key= - - zvm_select_vi_mode $ZVM_MODE_REPLACE - - while :; do - # Redisplay the command line, this is to be called from within - # a user-defined widget to allow changes to become visible - zle -R - - # Read a character for replacing - zvm_update_cursor - read -k 1 key - - # Escape key will break the replacing process, and enter key - # will repace with a newline character. - case $(zvm_escape_non_printed_characters $key) in - '^['|$ZVM_VI_OPPEND_ESCAPE_BINDKEY) break;; - '^M') key=$'\n';; - esac - - # If the key is backspace, we should move backward the cursor - if [[ $key == '' ]]; then - # Cursor position should not be less than zero - if ((cursor > 0)); then - cursor=$((cursor-1)) - fi - - # We should recover the character when cache size is not zero - if ((${#cache[@]} > 0)); then - key=${cache[-1]} - - if [[ $key == '' ]]; then - key= - fi - - cache=(${cache[@]:0:-1}) - BUFFER[$cursor+1]=$key - - # Remove from commands - cmds=(${cmds[@]:0:-1}) - fi - else - # If the key or the character at cursor is a newline character, - # or the cursor is at the end of buffer, we should insert the - # key instead of replacing with the key. - if [[ $key == $'\n' || - $BUFFER[$cursor+1] == $'\n' || - $BUFFER[$cursor+1] == '' - ]]; then - cache+=('') - LBUFFER+=$key - else - cache+=(${BUFFER[$cursor+1]}) - BUFFER[$cursor+1]=$key - fi - - cursor=$((cursor+1)) - - # Push to commands - cmds+=($key) - fi - - # Update next cursor position - CURSOR=$cursor - - zle redisplay - done - - # The cursor position should go back one character after - # exiting the replace mode - zle vi-backward-char - - zvm_select_vi_mode $ZVM_MODE_NORMAL - zvm_reset_repeat_commands $ZVM_MODE R $cmds - elif [[ $ZVM_MODE == $ZVM_MODE_VISUAL ]]; then - zvm_enter_visual_mode V - zvm_vi_change - elif [[ $ZVM_MODE == $ZVM_MODE_VISUAL_LINE ]]; then - zvm_vi_change - fi -} - -# Replace characters in one time -function zvm_vi_replace_chars() { - local cmds=() - local key= - - # Read a character for replacing - zvm_enter_oppend_mode - read -k 1 key - zvm_exit_oppend_mode - - # Escape key will break the replacing process - case $(zvm_escape_non_printed_characters $key) in - $ZVM_VI_OPPEND_ESCAPE_BINDKEY) - zvm_exit_visual_mode - return - esac - - if [[ $ZVM_MODE == $ZVM_MODE_NORMAL ]]; then - cmds+=($key) - BUFFER[$CURSOR+1]=$key - else - local ret=($(zvm_calc_selection)) - local bpos=${ret[1]} epos=${ret[2]} - for ((bpos=bpos+1; bpos<=epos; bpos++)); do - # Newline character is no need to be replaced - if [[ $BUFFER[$bpos] == $'\n' ]]; then - cmds+=($'\n') - continue - fi - - cmds+=($key) - BUFFER[$bpos]=$key - done - zvm_exit_visual_mode - fi - - # Reset the repeat commands - zvm_reset_repeat_commands $ZVM_MODE r $cmds -} - -# Substitute characters of selection -function zvm_vi_substitute() { - # Substitute one character in normal mode - if [[ $ZVM_MODE == $ZVM_MODE_NORMAL ]]; then - BUFFER="${BUFFER:0:$CURSOR}${BUFFER:$((CURSOR+1))}" - zvm_reset_repeat_commands $ZVM_MODE c 0 1 - zvm_select_vi_mode $ZVM_MODE_INSERT - else - zvm_vi_change - fi -} - -# Substitute all characters of a line -function zvm_vi_substitute_whole_line() { - zvm_select_vi_mode $ZVM_MODE_VISUAL_LINE; - zvm_vi_substitute -} - -# Check if cursor is at an empty line -function zvm_is_empty_line() { - local cursor=${1:-$CURSOR} - if [[ ${BUFFER:$cursor:1} == $'\n' && - ${BUFFER:$((cursor-1)):1} == $'\n' ]]; then - return - fi - return 1 -} - -# Get the beginning and end position of selection -function zvm_selection() { - local bpos= epos= - if (( MARK > CURSOR )) ; then - bpos=$CURSOR epos=$((MARK+1)) - else - bpos=$MARK epos=$((CURSOR+1)) - fi - echo $bpos $epos -} - -# Calculate the region of selection -function zvm_calc_selection() { - local ret=($(zvm_selection)) - local bpos=${ret[1]} epos=${ret[2]} cpos= - - # Save the current cursor position - cpos=$bpos - - # Check if it is visual-line mode - if [[ "${1:-$ZVM_MODE}" == $ZVM_MODE_VISUAL_LINE ]]; then - - # Extend the selection to whole line - for ((bpos=$bpos-1; $bpos>0; bpos--)); do - if [[ "${BUFFER:$bpos:1}" == $'\n' ]]; then - bpos=$((bpos+1)) - break - fi - done - for ((epos=$epos-1; $epos<$#BUFFER; epos++)); do - if [[ "${BUFFER:$epos:1}" == $'\n' ]]; then - break - fi - done - - # The begin position must not be less than zero - if (( bpos < 0 )); then - bpos=0 - fi - - ########################################### - # Calculate the new cursor position, here we consider that - # the selection will be delected. - - # Calculate the indent of current cursor line - for ((cpos=$((CURSOR-1)); $cpos>=0; cpos--)); do - [[ "${BUFFER:$cpos:1}" == $'\n' ]] && break - done - - local indent=$((CURSOR-cpos-1)) - - # If the selection includes the last line, the cursor - # will move up to above line. Otherwise the cursor will - # keep in the same line. - - local hpos= # Line head position - local rpos= # Reference position - - if (( $epos < $#BUFFER )); then - # Get the head position of next line - hpos=$((epos+1)) - rpos=$bpos - else - # Get the head position of above line - for ((hpos=$((bpos-2)); $hpos>0; hpos--)); do - if [[ "${BUFFER:$hpos:1}" == $'\n' ]]; then - break - fi - done - if (( $hpos < -1 )); then - hpos=-1 - fi - hpos=$((hpos+1)) - rpos=$hpos - fi - - # Calculate the cursor postion, the indent must be - # less than the line characters. - for ((cpos=$hpos; $cpos<$#BUFFER; cpos++)); do - if [[ "${BUFFER:$cpos:1}" == $'\n' ]]; then - break - fi - if (( $hpos + $indent <= $cpos )); then - break - fi - done - - cpos=$((rpos+cpos-hpos)) - fi - - echo $bpos $epos $cpos -} - -# Yank characters of the marked region -function zvm_yank() { - local ret=($(zvm_calc_selection $1)) - local bpos=$ret[1] epos=$ret[2] cpos=$ret[3] - CUTBUFFER=${BUFFER:$bpos:$((epos-bpos))} - if [[ ${1:-$ZVM_MODE} == $ZVM_MODE_VISUAL_LINE ]]; then - CUTBUFFER=${CUTBUFFER}$'\n' - fi - CURSOR=$bpos MARK=$epos -} - -# Up case of the visual selection -function zvm_vi_up_case() { - local ret=($(zvm_selection)) - local bpos=${ret[1]} epos=${ret[2]} - local content=${BUFFER:$bpos:$((epos-bpos))} - BUFFER="${BUFFER:0:$bpos}${(U)content}${BUFFER:$epos}" - zvm_exit_visual_mode -} - -# Down case of the visual selection -function zvm_vi_down_case() { - local ret=($(zvm_selection)) - local bpos=${ret[1]} epos=${ret[2]} - local content=${BUFFER:$bpos:$((epos-bpos))} - BUFFER="${BUFFER:0:$bpos}${(L)content}${BUFFER:$epos}" - zvm_exit_visual_mode -} - -# Opposite case of the visual selection -function zvm_vi_opp_case() { - local ret=($(zvm_selection)) - local bpos=${ret[1]} epos=${ret[2]} - local content=${BUFFER:$bpos:$((epos-bpos))} - for ((i=1; i<=$#content; i++)); do - if [[ ${content[i]} =~ [A-Z] ]]; then - content[i]=${(L)content[i]} - elif [[ ${content[i]} =~ [a-z] ]]; then - content[i]=${(U)content[i]} - fi - done - BUFFER="${BUFFER:0:$bpos}${content}${BUFFER:$epos}" - zvm_exit_visual_mode -} - -# Yank characters of the visual selection -function zvm_vi_yank() { - zvm_yank - zvm_exit_visual_mode -} - -# Put cutbuffer after the cursor -function zvm_vi_put_after() { - local head= foot= - local content=${CUTBUFFER} - local offset=1 - - if [[ ${content: -1} == $'\n' ]]; then - local pos=${CURSOR} - - # Find the end of current line - for ((; $pos<$#BUFFER; pos++)); do - if [[ ${BUFFER:$pos:1} == $'\n' ]]; then - pos=$pos+1 - break - fi - done - - # Special handling if cursor at an empty line - if zvm_is_empty_line; then - head=${BUFFER:0:$pos} - foot=${BUFFER:$pos} - else - head=${BUFFER:0:$pos} - foot=${BUFFER:$pos} - if [[ $pos == $#BUFFER ]]; then - content=$'\n'${content:0:-1} - pos=$pos+1 - fi - fi - - offset=0 - BUFFER="${head}${content}${foot}" - CURSOR=$pos - else - # Special handling if cursor at an empty line - if zvm_is_empty_line; then - head="${BUFFER:0:$((CURSOR-1))}" - foot="${BUFFER:$CURSOR}" - else - head="${BUFFER:0:$CURSOR}" - foot="${BUFFER:$((CURSOR+1))}" - fi - - BUFFER="${head}${BUFFER:$CURSOR:1}${content}${foot}" - CURSOR=$CURSOR+$#content - fi - - # Reresh display and highlight buffer - zvm_highlight clear - zvm_highlight custom $(($#head+$offset)) $(($#head+$#content+$offset)) -} - -# Put cutbuffer before the cursor -function zvm_vi_put_before() { - local head= foot= - local content=${CUTBUFFER} - - if [[ ${content: -1} == $'\n' ]]; then - local pos=$CURSOR - - # Find the beginning of current line - for ((; $pos>0; pos--)); do - if [[ "${BUFFER:$pos:1}" == $'\n' ]]; then - pos=$pos+1 - break - fi - done - - # Check if it is an empty line - if zvm_is_empty_line; then - head=${BUFFER:0:$((pos-1))} - foot=$'\n'${BUFFER:$pos} - pos=$((pos-1)) - else - head=${BUFFER:0:$pos} - foot=${BUFFER:$pos} - fi - - BUFFER="${head}${content}${foot}" - CURSOR=$pos - else - head="${BUFFER:0:$CURSOR}" - foot="${BUFFER:$((CURSOR+1))}" - BUFFER="${head}${content}${BUFFER:$CURSOR:1}${foot}" - CURSOR=$CURSOR+$#content - CURSOR=$((CURSOR-1)) - fi - - # Reresh display and highlight buffer - zvm_highlight clear - zvm_highlight custom $#head $(($#head+$#content)) -} - -# Delete characters of the visual selection -function zvm_vi_delete() { - local ret=($(zvm_calc_selection)) - local bpos=$ret[1] epos=$ret[2] cpos=$ret[3] - - CUTBUFFER=${BUFFER:$bpos:$((epos-bpos))} - - # Check if it is visual line mode - if [[ $ZVM_MODE == $ZVM_MODE_VISUAL_LINE ]]; then - if (( $epos < $#BUFFER )); then - epos=$epos+1 - elif (( $bpos > 0 )); then - bpos=$bpos-1 - fi - CUTBUFFER=${CUTBUFFER}$'\n' - fi - - BUFFER="${BUFFER:0:$bpos}${BUFFER:$epos}" - CURSOR=$cpos - - zvm_exit_visual_mode ${1:-true} -} - -# Yank characters of the visual selection -function zvm_vi_change() { - local ret=($(zvm_calc_selection)) - local bpos=$ret[1] epos=$ret[2] - - CUTBUFFER=${BUFFER:$bpos:$((epos-bpos))} - - # Check if it is visual line mode - if [[ $ZVM_MODE == $ZVM_MODE_VISUAL_LINE ]]; then - CUTBUFFER=${CUTBUFFER}$'\n' - fi - - BUFFER="${BUFFER:0:$bpos}${BUFFER:$epos}" - CURSOR=$bpos - - # Return when it's repeating mode - $ZVM_REPEAT_MODE && return - - # Reset the repeat commands - if [[ $ZVM_MODE != $ZVM_MODE_NORMAL ]]; then - local npos=0 ncount=0 ccount=0 - # Count the amount of newline character and the amount of - # characters after the last newline character. - while :; do - # Forward find the last newline character's position - npos=$(zvm_substr_pos $CUTBUFFER $'\n' $npos) - if [[ $npos == -1 ]]; then - if (($ncount == 0)); then - ccount=$#CUTBUFFER - fi - break - fi - npos=$((npos+1)) - ncount=$(($ncount + 1)) - ccount=$(($#CUTBUFFER - $npos)) - done - zvm_reset_repeat_commands $ZVM_MODE c $ncount $ccount - fi - - zvm_exit_visual_mode false - zvm_select_vi_mode $ZVM_MODE_INSERT -} - -# Change characters from cursor to the end of current line -function zvm_vi_change_eol() { - local bpos=$CURSOR epos=$CURSOR - - # Find the end of current line - for ((; $epos<$#BUFFER; epos++)); do - if [[ "${BUFFER:$epos:1}" == $'\n' ]]; then - break - fi - done - - CUTBUFFER=${BUFFER:$bpos:$((epos-bpos))} - BUFFER="${BUFFER:0:$bpos}${BUFFER:$epos}" - - zvm_reset_repeat_commands $ZVM_MODE c 0 $#CUTBUFFER - zvm_select_vi_mode $ZVM_MODE_INSERT -} - -# Default handler for unhandled key events -function zvm_default_handler() { - local keys=$(zvm_keys) - local extra_keys=$1 - - # Exit vi mode if keys is the escape keys - case $(zvm_escape_non_printed_characters "$keys") in - '^['|$ZVM_VI_INSERT_ESCAPE_BINDKEY) - zvm_exit_insert_mode - ZVM_KEYS=${extra_keys} - return - ;; - [vV]'^['|[vV]$ZVM_VI_VISUAL_ESCAPE_BINDKEY) - zvm_exit_visual_mode - ZVM_KEYS=${extra_keys} - return - ;; - esac - - case "$KEYMAP" in - vicmd) - case "$keys" in - [vV]c) zvm_vi_change;; - [vV]d) zvm_vi_delete;; - [vV]y) zvm_vi_yank;; - [cdyvV]*) zvm_range_handler "${keys}${extra_keys}";; - *) - for ((i=0;i<$#keys;i++)) do - zvm_navigation_handler ${keys:$i:1} - zvm_highlight - done - ;; - esac - ;; - viins|main) - if [[ "${keys:0:1}" =~ [a-zA-Z0-9\ ] ]]; then - zvm_self_insert "${keys:0:1}" - zle redisplay - ZVM_KEYS="${keys:1}${extra_keys}" - return - fi - ;; - visual) - ;; - esac - - ZVM_KEYS= -} - -# Read keys for retrieving and executing a widget -function zvm_readkeys_handler() { - local keymap=${1} - local keys=${2:-$KEYS} - local key= - local widget= - - # Get the keymap if keymap is empty - if [[ -z $keymap ]]; then - case "$ZVM_MODE" in - $ZVM_MODE_INSERT) keymap=viins;; - $ZVM_MODE_NORMAL) keymap=vicmd;; - $ZVM_MODE_VISUAL|$ZVM_MODE_VISUAL_LINE) keymap=visual;; - esac - fi - - # Read keys and retrieve the widget - zvm_readkeys $keymap $keys - keys=${retval[1]} - widget=${retval[2]} - key=${retval[3]} - - # Escape space in keys - keys=${keys//$ZVM_ESCAPE_SPACE/ } - key=${key//$ZVM_ESCAPE_SPACE/ } - - ZVM_KEYS="${keys}" - - # If the widget is current handler, we should call the default handler - if [[ "${widget}" == "${funcstack[1]}" ]]; then - widget= - fi - - # If the widget isn't matched, we should call the default handler - if [[ -z ${widget} ]]; then - zle zvm_default_handler "$key" - - # Push back to the key input stack - if [[ -n "$ZVM_KEYS" ]]; then - zle -U "$ZVM_KEYS" - fi - else - zle $widget - ZVM_KEYS= - fi -} - -# Find and move cursor to next character -function zvm_find_and_move_cursor() { - local char=$1 - local count=${2:-1} - local forward=${3:-true} - local skip=${4:-false} - local cursor=$CURSOR - - [[ -z $char ]] && return 1 - - # Find the specific character - while :; do - if $forward; then - cursor=$((cursor+1)) - ((cursor > $#BUFFER)) && break - else - cursor=$((cursor-1)) - ((cursor < 0)) && break - fi - if [[ ${BUFFER[$cursor+1]} == $char ]]; then - count=$((count-1)) - fi - ((count == 0)) && break - done - - [[ $count > 0 ]] && return 1 - - # Skip the character - if $skip; then - if $forward; then - cursor=$((cursor-1)) - else - cursor=$((cursor+1)) - fi - fi - - CURSOR=$cursor -} - -# Handle the navigation action -function zvm_navigation_handler() { - # Return if no keys provided - [[ -z $1 ]] && return 1 - - local keys=$1 - local count= - local cmd= - - # Retrieve the calling command - if [[ $keys =~ '^([1-9][0-9]*)?([fFtT].?)$' ]]; then - count=${match[1]:-1} - - # The length of keys must be 2 - if (( ${#match[2]} < 2)); then - zvm_enter_oppend_mode - - read -k 1 cmd - keys+=$cmd - - case "$(zvm_escape_non_printed_characters ${keys[-1]})" in - $ZVM_VI_OPPEND_ESCAPE_BINDKEY) return 1;; - esac - - zvm_exit_oppend_mode - fi - - local forward=true - local skip=false - - [[ ${keys[-2]} =~ '[FT]' ]] && forward=false - [[ ${keys[-2]} =~ '[tT]' ]] && skip=true - - cmd=(zvm_find_and_move_cursor ${keys[-1]} $count $forward $skip) - count=1 - else - count=${keys:0:-1} - case ${keys: -1} in - '^') cmd=(zle vi-first-non-blank);; - '$') cmd=(zle vi-end-of-line);; - ' ') cmd=(zle vi-forward-char);; - '0') cmd=(zle vi-digit-or-beginning-of-line);; - 'h') cmd=(zle vi-backward-char);; - 'j') cmd=(zle down-line-or-history);; - 'k') cmd=(zle up-line-or-history);; - 'l') cmd=(zle vi-forward-char);; - 'w') cmd=(zle vi-forward-word);; - 'W') cmd=(zle vi-forward-blank-word);; - 'e') cmd=(zle vi-forward-word-end);; - 'E') cmd=(zle vi-forward-blank-word-end);; - 'b') cmd=(zle vi-backward-word);; - 'B') cmd=(zle vi-backward-blank-word);; - esac - fi - - # Check widget if the widget is empty - if [[ -z $cmd ]]; then - return 0 - fi - - # Check if keys includes the count - if [[ ! $count =~ ^[0-9]+$ ]]; then - count=1 - fi - - # Call the widget, we can not use variable `i`, since - # some widgets will affect the variable `i`, and it - # will cause an infinite loop. - local init_cursor=$CURSOR - local last_cursor=$CURSOR - local exit_code=0 - for ((c=0; c `word1` - # c2[we] -> `word1 word2` - # ve -> `word1` - # v2e -> `word1 word2` - # vw -> `word1 w` - # v2w -> `word1 word2 w` - # [dy]e -> `word1` - # [dy]2e -> `word1 word2` - # [dy]w -> `word1 ` - # [dy]2w -> `word1 word2 ` - # [cdyv]iw -> `word1` - # [cdyv]aw -> `word1 ` - # [cdyv]2iw -> `word1 ` - # [cdyv]2aw -> `word1 word2 ` - # - # 2. SAMPLE: `a bb c dd`, CURSOR: at `a` - # - # cw -> `a` - # c2w -> `a bb` - # ce -> `a bb` - # c2e -> `a bb c` - # - # 3. SAMPLE: ` .foo. bar. baz.`, CURSOR: at `f` - # - # c[WE] -> `foo.` - # c2[WE] -> `foo. bar.` - # vE -> `foo.` - # v2E -> `foo. bar.` - # vW -> `foo. b` - # v2W -> `foo. bar. b` - # d2W -> `foo. bar. b` - # [dy]E -> `foo.` - # [dy]2E -> `foo. bar.` - # [dy]W -> `foo. ` - # [dy]2W -> `foo. bar. ` - # [cdyv]iW -> `.foo.` - # [cdyv]aW -> `.foo. ` - # [cdyv]2iW -> `.foo. ` - # [cdyv]2aW -> `.foo. bar. ` - # - # 4. SAMPLE: ` .foo.bar.baz.`, CURSOR: at `r` - # - # [cdy]b -> `ba` - # [cdy]B -> `.foo.ba` - # vb -> `bar` - # vB -> `.foo.bar` - # vFf -> `foo.bar` - # vTf -> `oo.bar` - # [cdyv]fz -> `r.baz` - # [cdy]Ff -> `foo.ba` - # [cdyv]tz -> `r.ba` - # [cdy]Tf -> `oo.ba` - # - - # Pre navigation handling - local navkey= - - if [[ $keys =~ '^c([1-9][0-9]*)?[ia][wW]$' ]]; then - count=${match[1]:-1} - navkey=${keys: -2} - elif [[ $keys =~ '^[cdy]([1-9][0-9]*)?[ia][eE]$' ]]; then - navkey= - elif [[ $keys =~ '^c([1-9][0-9]*)?w$' ]]; then - zle vi-backward-char - count=${match[1]:-1} - navkey='e' - elif [[ $keys =~ '^c([1-9][0-9]*)?W$' ]]; then - zle vi-backward-blank-char - count=${match[1]:-1} - navkey='E' - elif [[ $keys =~ '^c([1-9][0-9]*)?e$' ]]; then - count=${match[1]:-1} - navkey='e' - elif [[ $keys =~ '^c([1-9][0-9]*)?E$' ]]; then - count=${match[1]:-1} - navkey='E' - elif [[ $keys =~ '^[cdy]([1-9][0-9]*)?[bB]$' ]]; then - MARK=$((MARK-1)) - count=${match[1]:-1} - navkey=${keys: -1} - elif [[ $keys =~ '^[cdy]([1-9][0-9]*)?([FT].?)$' ]]; then - MARK=$((MARK-1)) - count=${match[1]:-1} - navkey=${match[2]} - elif [[ $keys =~ '^[cdy]([1-9][0-9]*)?j$' ]]; then - # Exit if there is no line below - count=${match[1]:-1} - for ((i=$((CURSOR+1)); i<=$#BUFFER; i++)); do - [[ ${BUFFER[$i]} == $'\n' ]] && navkey='j' - done - elif [[ $keys =~ '^[cdy]([1-9][0-9]*)?k$' ]]; then - # Exit if there is no line above - count=${match[1]:-1} - for ((i=$((CURSOR+1)); i>0; i--)); do - [[ ${BUFFER[$i]} == $'\n' ]] && navkey='k' - done - elif [[ $keys =~ '^[cdy]([1-9][0-9]*)?h$' ]]; then - MARK=$((MARK-1)) - count=${match[1]:-1} - navkey='h' - - # Exit if the cursor is at the beginning of a line - if ((MARK < 0)); then - navkey= - elif [[ ${BUFFER[$MARK+1]} == $'\n' ]]; then - navkey= - fi - elif [[ $keys =~ '^[cdy]([1-9][0-9]*)?l$' ]]; then - count=${match[1]:-1} - count=$((count-1)) - navkey=${count}l - elif [[ $keys =~ '^.([1-9][0-9]*)?([^0-9]+)$' ]]; then - count=${match[1]:-1} - navkey=${match[2]} - else - navkey= - fi - - # Handle navigation - case $navkey in - '') exit_code=1;; - *[ia][wW]) - local widget= - local mark= - - # At least 1 time - if [[ -z $count ]]; then - count=1 - fi - - # Retrieve the widget - case ${navkey: -2} in - iw) widget=select-in-word;; - aw) widget=select-a-word;; - iW) widget=select-in-blank-word;; - aW) widget=select-a-blank-word;; - esac - - # Execute the widget for `count` times, and - # save the `mark` position of the first time - for ((c=0; c= $#BUFFER)); then - break - fi - done - - MARK=$mark - CURSOR=$((CURSOR-1)) - ;; - *) - local retval= - - # Prevent some actions(e.g. w, e) from affecting the auto - # suggestion suffix - BUFFER+=$'\0' - - if zvm_navigation_handler "${count}${navkey}"; then - keys="${keys[1]}${retval}" - else - exit_code=1 - fi - - BUFFER[-1]='' - ;; - esac - - # Check if there is no range selected - if [[ $exit_code != 0 ]]; then - zvm_exit_visual_mode - return - fi - - # Post navigation handling - if [[ $keys =~ '^[cdy]([1-9][0-9]*)?[ia][wW]$' ]]; then - cursor=$MARK - elif [[ $keys =~ '[dy]([1-9][0-9]*)?[wW]' ]]; then - CURSOR=$((CURSOR-1)) - # If the CURSOR is at the newline character, we should - # move backward a character - if [[ "${BUFFER:$CURSOR:1}" == $'\n' ]]; then - CURSOR=$((CURSOR-1)) - fi - else - cursor=$CURSOR - fi - - # Handle operation - case "${keys}" in - c*) zvm_vi_change; cursor=;; - d*) zvm_vi_delete; cursor=;; - y*) zvm_vi_yank;; - [vV]*) cursor=;; - esac - - # Reset the repeat commands when it's changing or deleting - if $ZVM_REPEAT_MODE; then - zvm_exit_visual_mode false - elif [[ $keys =~ '^[cd].*' ]]; then - cmds+=($keys) - zvm_reset_repeat_commands $cmds - fi - - # Change the cursor position if the cursor is not null - if [[ ! -z $cursor ]]; then - CURSOR=$cursor - fi -} - -# Edit command line in EDITOR -function zvm_vi_edit_command_line() { - # Create a temporary file and save the BUFFER to it - local tmp_file=$(mktemp ${ZVM_TMPDIR}zvm.XXXXXX) - echo "$BUFFER" > "$tmp_file" - - # Edit the file with the specific editor, in case of - # the warning about input not from a terminal (e.g. - # vim), we should tell the editor input is from the - # terminal and not from standard input. - $ZVM_VI_EDITOR $tmp_file =0") - local step=$($forward && echo 'i++' || echo 'i--') - for (($init;$condition;$step)); do - if [[ ${1:$i:$slen} == "$2" ]]; then - pos=$i - break - fi - done - echo $pos -} - -# Parse surround from keys -function zvm_parse_surround_keys() { - local keys=${1:-${$(zvm_keys)//$ZVM_ESCAPE_SPACE/ }} - local action= - local surround= - case "${keys}" in - vS*) action=S; surround=${keys:2};; - vsa*) action=a; surround=${keys:3};; - vys*) action=y; surround=${keys:3};; - s[dr]*) action=${keys:1:1}; surround=${keys:2};; - [acd]s*) action=${keys:0:1}; surround=${keys:2};; - [cdvy][ia]*) action=${keys:0:2}; surround=${keys:2};; - esac - echo $action ${surround// /$ZVM_ESCAPE_SPACE} -} - -# Move around code structure (e.g. (..), {..}) -function zvm_move_around_surround() { - local slen= - local bpos=-1 - local epos=-1 - for ((i=$CURSOR;i>=0;i--)); do - # Check if it's one of the surrounds - for s in {\',\",\`,\(,\[,\{,\<}; do - slen=${#s} - if [[ ${BUFFER:$i:$slen} == "$s" ]]; then - bpos=$i - break - fi - done - if (($bpos == -1)); then - continue - fi - # Search the nearest surround - local ret=($(zvm_search_surround "$s")) - if [[ -z ${ret[@]} ]]; then - continue - fi - bpos=${ret[1]} - epos=${ret[2]} - # Move between the openning and close surrounds - if (( $CURSOR > $((bpos-1)) )) && (( $CURSOR < $((bpos+slen)) )); then - CURSOR=$epos - else - CURSOR=$bpos - fi - break - done -} - -# Match the surround pair from the part -function zvm_match_surround() { - local bchar=${1// /$ZVM_ESCAPE_SPACE} - local echar=$bchar - case $bchar in - '(') echar=')';; - '[') echar=']';; - '{') echar='}';; - '<') echar='>';; - ')') bchar='(';echar=')';; - ']') bchar='[';echar=']';; - '}') bchar='{';echar='}';; - '>') bchar='<';echar='>';; - esac - echo $bchar $echar -} - -# Search surround from the string -function zvm_search_surround() { - local ret=($(zvm_match_surround "$1")) - local bchar=${${ret[1]//$ZVM_ESCAPE_SPACE/ }:- } - local echar=${${ret[2]//$ZVM_ESCAPE_SPACE/ }:- } - local bpos=$(zvm_substr_pos $BUFFER $bchar $CURSOR false) - local epos=$(zvm_substr_pos $BUFFER $echar $CURSOR true) - if [[ $bpos == $epos ]]; then - epos=$(zvm_substr_pos $BUFFER $echar $((CURSOR+1)) true) - if [[ $epos == -1 ]]; then - epos=$(zvm_substr_pos $BUFFER $echar $((CURSOR-1)) false) - if [[ $epos != -1 ]]; then - local tmp=$epos; epos=$bpos; bpos=$tmp - fi - fi - fi - if [[ $bpos == -1 ]] || [[ $epos == -1 ]]; then - return - fi - echo $bpos $epos $bchar $echar -} - -# Select surround and highlight it in visual mode -function zvm_select_surround() { - local ret=($(zvm_parse_surround_keys)) - local action=${ret[1]} - local surround=${ret[2]//$ZVM_ESCAPE_SPACE/ } - ret=($(zvm_search_surround ${surround})) - if [[ ${#ret[@]} == 0 ]]; then - zvm_exit_visual_mode - return - fi - local bpos=${ret[1]} - local epos=${ret[2]} - if [[ ${action:1:1} == 'i' ]]; then - ((bpos++)) - else - ((epos++)) - fi - MARK=$bpos; CURSOR=$epos-1 - - # refresh current mode for prompt redraw - zle reset-prompt -} - -# Change surround in vicmd or visual mode -function zvm_change_surround() { - local ret=($(zvm_parse_surround_keys)) - local action=${1:-${ret[1]}} - local surround=${2:-${ret[2]//$ZVM_ESCAPE_SPACE/ }} - local bpos=${3} epos=${4} - local is_appending=false - case $action in - S|y|a) is_appending=true;; - esac - if $is_appending; then - if [[ -z $bpos && -z $epos ]]; then - ret=($(zvm_selection)) - bpos=${ret[1]} epos=${ret[2]} - fi - else - ret=($(zvm_search_surround "$surround")) - (( ${#ret[@]} )) || return - bpos=${ret[1]} epos=${ret[2]} - zvm_highlight custom $bpos $(($bpos+1)) - zvm_highlight custom $epos $(($epos+1)) - fi - local key= - case $action in - c|r) - zvm_enter_oppend_mode - read -k 1 key - zvm_exit_oppend_mode - ;; - S|y|a) key=$surround; [[ -z $@ ]] && zle visual-mode;; - esac - - # Check if it is ESCAPE key ( or ZVM_VI_ESCAPE_BINDKEY) - case "$key" in - ''|"${ZVM_VI_ESCAPE_BINDKEY//\^\[/}") - zvm_highlight clear - return - esac - - # Start changing surround - ret=($(zvm_match_surround "$key")) - local bchar=${${ret[1]//$ZVM_ESCAPE_SPACE/ }:-$key} - local echar=${${ret[2]//$ZVM_ESCAPE_SPACE/ }:-$key} - local value=$($is_appending && echo 0 || echo 1 ) - local head=${BUFFER:0:$bpos} - local body=${BUFFER:$((bpos+value)):$((epos-(bpos+value)))} - local foot=${BUFFER:$((epos+value))} - BUFFER="${head}${bchar}${body}${echar}${foot}" - - # Clear highliht - zvm_highlight clear - - case $action in - S|y|a) zvm_select_vi_mode $ZVM_MODE_NORMAL;; - esac -} - -# Change surround text object -function zvm_change_surround_text_object() { - local ret=($(zvm_parse_surround_keys)) - local action=${ret[1]} - local surround=${ret[2]//$ZVM_ESCAPE_SPACE/ } - ret=($(zvm_search_surround "${surround}")) - if [[ ${#ret[@]} == 0 ]]; then - zvm_select_vi_mode $ZVM_MODE_NORMAL - return - fi - local bpos=${ret[1]} - local epos=${ret[2]} - if [[ ${action:1:1} == 'i' ]]; then - ((bpos++)) - else - ((epos++)) - fi - CUTBUFFER=${BUFFER:$bpos:$(($epos-$bpos))} - case ${action:0:1} in - c) - BUFFER="${BUFFER:0:$bpos}${BUFFER:$epos}" - CURSOR=$bpos - zvm_select_vi_mode $ZVM_MODE_INSERT - ;; - d) - BUFFER="${BUFFER:0:$bpos}${BUFFER:$epos}" - CURSOR=$bpos - ;; - esac -} - -# Repeat last change -function zvm_repeat_change() { - ZVM_REPEAT_MODE=true - - local cmd=${ZVM_REPEAT_COMMANDS[2]} - - # Handle repeat command - case $cmd in - [aioAIO]) zvm_repeat_insert;; - c) zvm_repeat_vi_change;; - [cd]*) zvm_repeat_range_change;; - R) zvm_repeat_replace;; - r) zvm_repeat_replace_chars;; - *) zle vi-repeat-change;; - esac - - zle redisplay - - ZVM_REPEAT_MODE=false -} - -# Repeat inserting characters -function zvm_repeat_insert() { - local cmd=${ZVM_REPEAT_COMMANDS[2]} - local cmds=(${ZVM_REPEAT_COMMANDS[3,-1]}) - - # Pre-handle the command - case $cmd in - a) CURSOR+=1;; - o) - zle vi-backward-char - zle vi-end-of-line - LBUFFER+=$'\n' - ;; - A) - zle vi-end-of-line - CURSOR=$((CURSOR+1)) - ;; - I) zle vi-first-non-blank;; - O) - zle vi-digit-or-beginning-of-line - LBUFFER+=$'\n' - CURSOR=$((CURSOR-1)) - ;; - esac - - # Insert characters - for ((i=1; i<=${#cmds[@]}; i++)); do - cmd="${cmds[$i]}" - - # Hanlde the backspace command - if [[ $cmd == '' ]]; then - if (($#LBUFFER > 0)); then - LBUFFER=${LBUFFER:0:-1} - fi - continue - fi - - # The length of character should be 1 - if (($#cmd == 1)); then - LBUFFER+=$cmd - fi - done -} - -# Repeat changing visual characters -function zvm_repeat_vi_change() { - local mode=${ZVM_REPEAT_COMMANDS[1]} - local cmds=(${ZVM_REPEAT_COMMANDS[3,-1]}) - - # Backward move cursor to the beginning of line - if [[ $mode == $ZVM_MODE_VISUAL_LINE ]]; then - zle vi-digit-or-beginning-of-line - fi - - local ncount=${cmds[1]} - local ccount=${cmds[2]} - local pos=$CURSOR epos=$CURSOR - - # Forward expand the characters to the Nth newline character - for ((i=0; i<$ncount; i++)); do - pos=$(zvm_substr_pos $BUFFER $'\n' $pos) - if [[ $pos == -1 ]]; then - epos=$#BUFFER - break - fi - pos=$((pos+1)) - epos=$pos - done - - # Forward expand the remaining characters - for ((i=0; i<$ccount; i++)); do - local char=${BUFFER[$epos+i]} - if [[ $char == $'\n' || $char == '' ]]; then - ccount=$i - break - fi - done - - epos=$((epos+ccount)) - RBUFFER=${RBUFFER:$((epos-CURSOR))} -} - -# Repeat changing a range of characters -function zvm_repeat_range_change() { - local cmd=${ZVM_REPEAT_COMMANDS[2]} - - # Remove characters - zvm_range_handler $cmd - - # Insert characters - zvm_repeat_insert -} - -# Repeat replacing -function zvm_repeat_replace() { - local cmds=(${ZVM_REPEAT_COMMANDS[3,-1]}) - local cmd= - local cursor=$CURSOR - - for ((i=1; i<=${#cmds[@]}; i++)); do - cmd="${cmds[$i]}" - - # If the cmd or the character at cursor is a newline character, - # or the cursor is at the end of buffer, we should insert the - # cmd instead of replacing with the cmd. - if [[ $cmd == $'\n' || - $BUFFER[$cursor+1] == $'\n' || - $BUFFER[$cursor+1] == '' - ]]; then - LBUFFER+=$cmd - else - BUFFER[$cursor+1]=$cmd - fi - - cursor=$((cursor+1)) - CURSOR=$cursor - done - - # The cursor position should go back one character after - # exiting the replace mode - zle vi-backward-char -} - -# Repeat replacing characters -function zvm_repeat_replace_chars() { - local mode=${ZVM_REPEAT_COMMANDS[1]} - local cmds=(${ZVM_REPEAT_COMMANDS[3,-1]}) - local cmd= - - # Replacment of visual mode should move backward cursor to the - # begin of current line, and replacing to the end of last line. - if [[ $mode == $ZVM_MODE_VISUAL_LINE ]]; then - zle vi-digit-or-beginning-of-line - cmds+=($'\n') - fi - - local cursor=$((CURSOR+1)) - - for ((i=1; i<=${#cmds[@]}; i++)); do - cmd="${cmds[$i]}" - - # If we meet a newline character in the buffer, we should keep - # stop replacing, util we meet next newline character command. - if [[ ${BUFFER[$cursor]} == $'\n' ]]; then - if [[ $cmd == $'\n' ]]; then - cursor=$((cursor+1)) - fi - continue - fi - - # A newline character command should keep replacing with last - # character, until we meet a newline character in the buffer, - # then we use next command. - if [[ $cmd == $'\n' ]]; then - i=$((i-1)) - cmd="${cmds[$i]}" - fi - - # The length of character should be 1 - if (($#cmd == 1)); then - BUFFER[$cursor]="${cmd}" - fi - - cursor=$((cursor+1)) - - # Break when it reaches the end - if ((cursor > $#BUFFER)); then - break - fi - done -} - -# Select a word under the cursor -function zvm_select_in_word() { - local cursor=${1:-$CURSOR} - local buffer=${2:-$BUFFER} - local bpos=$cursor epos=$cursor - local pattern='[0-9a-zA-Z_]' - - if ! [[ "${buffer:$cursor:1}" =~ $pattern ]]; then - pattern="[^${pattern:1:-1} ]" - fi - - for ((; $bpos>=0; bpos--)); do - [[ "${buffer:$bpos:1}" =~ $pattern ]] || break - done - for ((; $epos<$#buffer; epos++)); do - [[ "${buffer:$epos:1}" =~ $pattern ]] || break - done - - bpos=$((bpos+1)) - - # The ending position must be greater than 0 - if (( epos > 0 )); then - epos=$((epos-1)) - fi - - echo $bpos $epos -} - -# Switch keyword -function zvm_switch_keyword() { - local bpos= epos= cpos=$CURSOR - - # Cursor position cases: - # - # 1. Cursor on symbol: - # 2+2 => + - # 2-2 => - - # 2 + 2 => + - # 2 +2 => +2 - # 2 -2 => -2 - # 2 -a => -a - # - # 2. Cursor on number or alpha: - # 2+2 => +2 - # 2-2 => -2 - # 2 + 2 => 2 - # 2 +2 => +2 - # 2 -2 => -2 - # 2 -a => -a - - # If cursor is on the `+` or `-`, we need to check if it is a - # number with a sign or an operator, only the number needs to - # forward the cursor. - if [[ ${BUFFER:$cpos:2} =~ [+-][0-9] ]]; then - if [[ $cpos == 0 || ${BUFFER:$((cpos-1)):1} =~ [^0-9] ]]; then - cpos=$((cpos+1)) - fi - - # If cursor is on the `+` or `-`, we need to check if it is a - # short option, only the short option needs to forward the cursor. - elif [[ ${BUFFER:$cpos:2} =~ [+-][a-zA-Z] ]]; then - if [[ $cpos == 0 || ${BUFFER:$((cpos-1)):1} == ' ' ]]; then - cpos=$((cpos+1)) - fi - fi - - local result=($(zvm_select_in_word $cpos)) - bpos=${result[1]} epos=$((${result[2]}+1)) - - # Move backward the cursor - if [[ $bpos != 0 && ${BUFFER:$((bpos-1)):1} == [+-] ]]; then - bpos=$((bpos-1)) - fi - - local word=${BUFFER:$bpos:$((epos-bpos))} - local keys=$(zvm_keys) - - if [[ $keys == '' ]]; then - local increase=true - else - local increase=false - fi - - # Execute extra commands - for handler in $zvm_switch_keyword_handlers; do - if ! zvm_exist_command ${handler}; then - continue - fi - - result=($($handler $word $increase)); - - if (( $#result == 0 )); then - continue - fi - - epos=$(( bpos + ${result[3]} )) - bpos=$(( bpos + ${result[2]} )) - - if (( cpos < bpos )) || (( cpos >= epos )); then - continue - fi - - BUFFER="${BUFFER:0:$bpos}${result[1]}${BUFFER:$epos}" - CURSOR=$((bpos + ${#result[1]} - 1)) - - zle reset-prompt - return - done -} - -# Switch number keyword -function zvm_switch_number { - local word=$1 - local increase=${2:-true} - local result= bpos= epos= - - # Hexadecimal - if [[ $word =~ [^0-9]?(0[xX][0-9a-fA-F]*) ]]; then - local number=${match[1]} - local prefix=${number:0:2} - bpos=$((mbegin-1)) epos=$mend - - # Hexadecimal cases: - # - # 1. Increment: - # 0xDe => 0xdf - # 0xdE => 0xDF - # 0xde0 => 0xddf - # 0xffffffffffffffff => 0x0000000000000000 - # 0X9 => 0XA - # 0Xdf => 0Xe0 - # - # 2. Decrement: - # 0xdE0 => 0xDDF - # 0xffFf0 => 0xfffef - # 0xfffF0 => 0xFFFEF - # 0x0 => 0xffffffffffffffff - # 0X0 => 0XFFFFFFFFFFFFFFFF - # 0Xf => 0Xe - - local lower=true - if [[ $number =~ [A-Z][0-9]*$ ]]; then - lower=false - fi - - # Fix the number truncated after 15 digits issue - if (( $#number > 17 )); then - local d=$(($#number - 15)) - local h=${number:0:$d} - number="0x${number:$d}" - fi - - local p=$(($#number - 2)) - - if $increase; then - if (( $number == 0x${(l:15::f:)} )); then - h=$(([##16]$h+1)) - h=${h: -1} - number=${(l:15::0:)} - else - h=${h:2} - number=$(([##16]$number + 1)) - fi - else - if (( $number == 0 )); then - if (( ${h:-0} == 0 )); then - h=f - else - h=$(([##16]$h-1)) - h=${h: -1} - fi - number=${(l:15::f:)} - else - h=${h:2} - number=$(([##16]$number - 1)) - fi - fi - - # Padding with zero - if (( $#number < $p )); then - number=${(l:$p::0:)number} - fi - - result="${h}${number}" - - # Transform the case - if $lower; then - result="${(L)result}" - fi - - result="${prefix}${result}" - - # Binary - elif [[ $word =~ [^0-9]?(0[bB][01]*) ]]; then - # Binary cases: - # - # 1. Increment: - # 0b1 => 0b10 - # 0x1111111111111111111111111111111111111111111111111111111111111111 => - # 0x0000000000000000000000000000000000000000000000000000000000000000 - # 0B0 => 0B1 - # - # 2. Decrement: - # 0b1 => 0b0 - # 0b100 => 0b011 - # 0B010 => 0B001 - # 0b0 => - # 0x1111111111111111111111111111111111111111111111111111111111111111 - - local number=${match[1]} - local prefix=${number:0:2} - bpos=$((mbegin-1)) epos=$mend - - # Fix the number truncated after 63 digits issue - if (( $#number > 65 )); then - local d=$(($#number - 63)) - local h=${number:0:$d} - number="0b${number:$d}" - fi - - local p=$(($#number - 2)) - - if $increase; then - if (( $number == 0b${(l:63::1:)} )); then - h=$(([##2]$h+1)) - h=${h: -1} - number=${(l:63::0:)} - else - h=${h:2} - number=$(([##2]$number + 1)) - fi - else - if (( $number == 0b0 )); then - if (( ${h:-0} == 0 )); then - h=1 - else - h=$(([##2]$h-1)) - h=${h: -1} - fi - number=${(l:63::1:)} - else - h=${h:2} - number=$(([##2]$number - 1)) - fi - fi - - # Padding with zero - if (( $#number < $p )); then - number=${(l:$p::0:)number} - fi - - result="${prefix}${number}" - - # Decimal - elif [[ $word =~ ([-+]?[0-9]+) ]]; then - # Decimal cases: - # - # 1. Increment: - # 0 => 1 - # 99 => 100 - # - # 2. Decrement: - # 0 => -1 - # 10 => 9 - # aa1230xa => aa1231xa - # aa1230bb => aa1231bb - # aa123a0bb => aa124a0bb - - local number=${match[1]} - bpos=$((mbegin-1)) epos=$mend - - if $increase; then - result=$(($number + 1)) - else - result=$(($number - 1)) - fi - - # Check if need the plus sign prefix - if [[ ${word:$bpos:1} == '+' ]]; then - result="+${result}" - fi - fi - - if [[ $result ]]; then - echo $result $bpos $epos - fi -} - -# Switch boolean keyword -function zvm_switch_boolean() { - local word=$1 - local increase=$2 - local result= - local bpos=0 epos=$#word - - # Remove option prefix - if [[ $word =~ (^[+-]{0,2}) ]]; then - local prefix=${match[1]} - bpos=$mend - word=${word:$bpos} - fi - - case ${(L)word} in - true) result=false;; - false) result=true;; - yes) result=no;; - no) result=yes;; - on) result=off;; - off) result=on;; - y) result=n;; - n) result=y;; - t) result=f;; - f) result=t;; - *) return;; - esac - - # Transform the case - if [[ $word =~ ^[A-Z]+$ ]]; then - result=${(U)result} - elif [[ $word =~ ^[A-Z] ]]; then - result=${(U)result:0:1}${result:1} - fi - - echo $result $bpos $epos -} - -# Switch weekday keyword -function zvm_switch_weekday() { - local word=$1 - local increase=$2 - local result=${(L)word} - local weekdays=( - sunday - monday - tuesday - wednesday - thursday - friday - saturday - ) - - local i=1 - - for ((; i<=${#weekdays[@]}; i++)); do - if [[ ${weekdays[i]:0:$#result} == ${result} ]]; then - result=${weekdays[i]} - break - fi - done - - # Return if no match - if (( i > ${#weekdays[@]} )); then - return - fi - - if $increase; then - if (( i == ${#weekdays[@]} )); then - i=1 - else - i=$((i+1)) - fi - else - if (( i == 1 )); then - i=${#weekdays[@]} - else - i=$((i-1)) - fi - fi - - # Abbreviation - if (( $#result == $#word )); then - result=${weekdays[i]} - else - result=${weekdays[i]:0:$#word} - fi - - # Transform the case - if [[ $word =~ ^[A-Z]+$ ]]; then - result=${(U)result} - elif [[ $word =~ ^[A-Z] ]]; then - result=${(U)result:0:1}${result:1} - fi - - echo $result 0 $#word -} - -# Switch operator keyword -function zvm_switch_operator() { - local word=$1 - local increase=$2 - local result= - - case ${(L)word} in - '&&') result='||';; - '||') result='&&';; - '++') result='--';; - '--') result='++';; - '==') result='!=';; - '!=') result='==';; - '===') result='!==';; - '!==') result='===';; - '+') result='-';; - '-') result='*';; - '*') result='/';; - '/') result='+';; - 'and') result='or';; - 'or') result='and';; - *) return;; - esac - - # Transform the case - if [[ $word =~ ^[A-Z]+$ ]]; then - result=${(U)result} - elif [[ $word =~ ^[A-Z] ]]; then - result=${(U)result:0:1}${result:1} - fi - - # Since the `echo` command can not print the character - # `-`, here we use `printf` command alternatively. - printf "%s 0 $#word" "${result}" -} - -# Switch month keyword -function zvm_switch_month() { - local word=$1 - local increase=$2 - local result=${(L)word} - local months=( - january - february - march - april - may - june - july - august - september - october - november - december - ) - - local i=1 - - for ((; i<=${#months[@]}; i++)); do - if [[ ${months[i]:0:$#result} == ${result} ]]; then - result=${months[i]} - break - fi - done - - # Return if no match - if (( i > ${#months[@]} )); then - return - fi - - if $increase; then - if (( i == ${#months[@]} )); then - i=1 - else - i=$((i+1)) - fi - else - if (( i == 1 )); then - i=${#months[@]} - else - i=$((i-1)) - fi - fi - - # Abbreviation - if (( $#result == $#word )); then - result=${months[i]} - else - result=${months[i]:0:$#word} - fi - - # Transform the case - if [[ $word =~ ^[A-Z]+$ ]]; then - result=${(U)result} - elif [[ $word =~ ^[A-Z] ]]; then - result=${(U)result:0:1}${result:1} - fi - - echo $result 0 $#word -} - -# Highlight content -function zvm_highlight() { - local opt=${1:-mode} - local region=() - local redraw=false - - # Hanlde region by the option - case "$opt" in - mode) - case "$ZVM_MODE" in - $ZVM_MODE_VISUAL|$ZVM_MODE_VISUAL_LINE) - local ret=($(zvm_calc_selection)) - local bpos=$ret[1] epos=$ret[2] - region=("$((bpos)) $((epos)) bg=$ZVM_VI_HIGHLIGHT_BACKGROUND") - ;; - esac - redraw=true - ;; - custom) - region=("${ZVM_REGION_HIGHLIGHT[@]}") - region+=("$2 $3 bg=${4:-$ZVM_VI_HIGHLIGHT_BACKGROUND}") - redraw=true - ;; - clear) - zle redisplay - redraw=true - ;; - redraw) redraw=true;; - esac - - # Update region highlight - if (( $#region > 0 )) || [[ "$opt" == 'clear' ]]; then - - # Remove old region highlight - local rawhighlight=() - for ((i=1; i<=${#region_highlight[@]}; i++)); do - local raw=true - for ((j=1; j<=${#ZVM_REGION_HIGHLIGHT[@]}; j++)); do - if [[ "${region_highlight[i]}" == "${ZVM_REGION_HIGHLIGHT[j]}" ]]; then - raw=false - break - fi - done - if $raw; then - rawhighlight+=("${region_highlight[i]}") - fi - done - - # Assign new region highlight - ZVM_REGION_HIGHLIGHT=("${region[@]}") - region_highlight=("${rawhighlight[@]}" "${ZVM_REGION_HIGHLIGHT[@]}") - fi - - # Check if we need to refresh the region highlight - if $redraw; then - zle -R - fi -} - -# Enter the visual mode -function zvm_enter_visual_mode() { - local mode= - local last_mode=$ZVM_MODE - local last_region= - - # Exit the visual mode - case $last_mode in - $ZVM_MODE_VISUAL|$ZVM_MODE_VISUAL_LINE) - last_region=($MARK $CURSOR) - zvm_exit_visual_mode - ;; - esac - - case "${1:-$(zvm_keys)}" in - v) mode=$ZVM_MODE_VISUAL;; - V) mode=$ZVM_MODE_VISUAL_LINE;; - esac - - # We should just exit the visual mdoe if current mode - # is the same with last visual mode - if [[ $last_mode == $mode ]]; then - return - fi - - zvm_select_vi_mode $mode - - # Recover the region when changing to another visual mode - if [[ -n $last_region ]]; then - MARK=$last_region[1] - CURSOR=$last_region[2] - zle redisplay - fi -} - -# Exit the visual mode -function zvm_exit_visual_mode() { - case "$ZVM_MODE" in - $ZVM_MODE_VISUAL) zle visual-mode;; - $ZVM_MODE_VISUAL_LINE) zle visual-line-mode;; - esac - zvm_highlight clear - zvm_select_vi_mode $ZVM_MODE_NORMAL ${1:-true} -} - -# Enter the vi insert mode -function zvm_enter_insert_mode() { - local keys=${1:-$(zvm_keys)} - - if [[ $keys == 'i' ]]; then - ZVM_INSERT_MODE='i' - elif [[ $keys == 'a' ]]; then - ZVM_INSERT_MODE='a' - if ! zvm_is_empty_line; then - CURSOR=$((CURSOR+1)) - fi - else - return - fi - - zvm_reset_repeat_commands $ZVM_MODE_NORMAL $ZVM_INSERT_MODE - zvm_select_vi_mode $ZVM_MODE_INSERT -} - -# Exit the vi insert mode -function zvm_exit_insert_mode() { - ZVM_INSERT_MODE= - zvm_select_vi_mode $ZVM_MODE_NORMAL -} - -# Enter the vi operator pending mode -function zvm_enter_oppend_mode() { - ZVM_OPPEND_MODE=true - ${1:-true} && zvm_update_cursor -} - -# Exit the vi operator pending mode -function zvm_exit_oppend_mode() { - ZVM_OPPEND_MODE=false - ${1:-true} && zvm_update_cursor -} - -# Insert at the beginning of the line -function zvm_insert_bol() { - ZVM_INSERT_MODE='I' - zle vi-first-non-blank - zvm_select_vi_mode $ZVM_MODE_INSERT - zvm_reset_repeat_commands $ZVM_MODE_NORMAL $ZVM_INSERT_MODE -} - -# Append at the end of the line -function zvm_append_eol() { - ZVM_INSERT_MODE='A' - zle vi-end-of-line - CURSOR=$((CURSOR+1)) - zvm_select_vi_mode $ZVM_MODE_INSERT - zvm_reset_repeat_commands $ZVM_MODE_NORMAL $ZVM_INSERT_MODE -} - -# Self insert content to cursor position -function zvm_self_insert() { - local keys=${1:-$KEYS} - RBUFFER="${keys}${RBUFFER}" - CURSOR=$((CURSOR+1)) -} - -# Reset the repeat commands -function zvm_reset_repeat_commands() { - ZVM_REPEAT_RESET=true - ZVM_REPEAT_COMMANDS=($@) -} - -# Select vi mode -function zvm_select_vi_mode() { - local mode=$1 - local reset_prompt=${2:-true} - - # Check if current mode is the same with the new mode - if [[ $mode == "$ZVM_MODE" ]]; then - zvm_update_cursor - mode= - fi - - zvm_exec_commands 'before_select_vi_mode' - - # Some plugins would reset the prompt when we select the - # keymap, so here we disable the reset-prompt temporarily. - ZVM_RESET_PROMPT_DISABLED=true - - # Exit operator pending mode - if $ZVM_OPPEND_MODE; then - zvm_exit_oppend_mode false - fi - - case $mode in - $ZVM_MODE_NORMAL) - ZVM_MODE=$ZVM_MODE_NORMAL - zvm_update_cursor - zle vi-cmd-mode - ;; - $ZVM_MODE_INSERT) - ZVM_MODE=$ZVM_MODE_INSERT - zvm_update_cursor - zle vi-insert - ;; - $ZVM_MODE_VISUAL) - ZVM_MODE=$ZVM_MODE_VISUAL - zvm_update_cursor - zle visual-mode - ;; - $ZVM_MODE_VISUAL_LINE) - ZVM_MODE=$ZVM_MODE_VISUAL_LINE - zvm_update_cursor - zle visual-line-mode - ;; - $ZVM_MODE_REPLACE) - ZVM_MODE=$ZVM_MODE_REPLACE - zvm_enter_oppend_mode - ;; - esac - - # This aspect provides you a moment to do something, such as - # update the cursor, prompt and so on. - zvm_exec_commands 'after_select_vi_mode' - - # Enable reset-prompt - ZVM_RESET_PROMPT_DISABLED=false - - $reset_prompt && zle reset-prompt - - # Start the lazy keybindings when the first time entering the - # normal mode, when the mode is the same as last mode, we get - # empty value for $mode. - if [[ $mode == $ZVM_MODE_NORMAL ]] && - (( $#ZVM_LAZY_KEYBINDINGS_LIST > 0 )); then - - zvm_exec_commands 'before_lazy_keybindings' - - # Here we should unset the list for normal keybindings - local list=("${ZVM_LAZY_KEYBINDINGS_LIST[@]}") - unset ZVM_LAZY_KEYBINDINGS_LIST - - for r in "${list[@]}"; do - eval "zvm_bindkey ${r}" - done - - zvm_exec_commands 'after_lazy_keybindings' - fi -} - -# Reset prompt -function zvm_reset_prompt() { - $ZVM_RESET_PROMPT_DISABLED && return - local -i retval - if [[ -z "$rawfunc" ]]; then - zle .reset-prompt -- "$@" - else - $rawfunc -- "$@" - fi - return retval -} - -# Undo action in vi insert mode -# -# CTRL-U Remove all characters between the cursor position and -# the beginning of the line. Previous versions of vim -# deleted all characters on the line. -function zvm_viins_undo() { - if [[ $ZVM_VI_INS_LEGACY_UNDO ]]; then - zvm_kill_line - else - zvm_backward_kill_line - fi -} - -# Change cursor to support for inside/outside tmux -function zvm_set_cursor() { - # Term of vim isn't supported - if [[ -n $VIMRUNTIME ]]; then - return - fi - - # Tmux sequence - if [[ -z $TMUX ]]; then - echo -ne "$1" - else - echo -ne "\ePtmux;\e\e$1\e\\" - fi -} - -# Get the escape sequence of cursor style -function zvm_cursor_style() { - local style=${(L)1} - local term=${2:-$ZVM_TERM} - - case $term in - # For xterm and rxvt and their derivatives use the same escape - # sequences as the VT520 terminal. And screen, konsole, alacritty - # and st implement a superset of VT100 and VT100, they support - # 256 colors the same way xterm does. - xterm*|rxvt*|screen*|tmux*|konsole*|alacritty*|st*) - case $style in - $ZVM_CURSOR_USER_DEFAULT) style='\e[0 q';; - $ZVM_CURSOR_BLOCK) style='\e[2 q';; - $ZVM_CURSOR_UNDERLINE) style='\e[4 q';; - $ZVM_CURSOR_BEAM) style='\e[6 q';; - $ZVM_CURSOR_BLINKING_BLOCK) style='\e[1 q';; - $ZVM_CURSOR_BLINKING_UNDERLINE) style='\e[3 q';; - $ZVM_CURSOR_BLINKING_BEAM) style='\e[5 q';; - esac - ;; - *) style='\e[0 q';; - esac - - echo $style -} - -# Update the cursor according current vi mode -function zvm_update_cursor() { - - # Check if we need to update the cursor style - $ZVM_CURSOR_STYLE_ENABLED || return - - local mode=$1 - local shape= - - # Check if it is operator pending mode - if $ZVM_OPPEND_MODE; then - mode=opp - shape=$(zvm_cursor_style $ZVM_OPPEND_MODE_CURSOR) - fi - - # Get cursor shape by the mode - case "${mode:-$ZVM_MODE}" in - $ZVM_MODE_NORMAL) - shape=$(zvm_cursor_style $ZVM_NORMAL_MODE_CURSOR) - ;; - $ZVM_MODE_INSERT) - shape=$(zvm_cursor_style $ZVM_INSERT_MODE_CURSOR) - ;; - $ZVM_MODE_VISUAL) - shape=$(zvm_cursor_style $ZVM_VISUAL_MODE_CURSOR) - ;; - $ZVM_MODE_VISUAL_LINE) - shape=$(zvm_cursor_style $ZVM_VISUAL_LINE_MODE_CURSOR) - ;; - esac - - if [[ $shape ]]; then - zvm_set_cursor $shape - fi -} - -# Updates highlight region -function zvm_update_highlight() { - case "$ZVM_MODE" in - $ZVM_MODE_VISUAL|$ZVM_MODE_VISUAL_LINE) - zvm_highlight - ;; - esac -} - -# Updates repeat commands -function zvm_update_repeat_commands() { - # We don't need to update the repeat commands if current - # mode is already the repeat mode. - $ZVM_REPEAT_MODE && return - - # We don't need to update the repeat commands if it is - # reseting the repeat commands. - if $ZVM_REPEAT_RESET; then - ZVM_REPEAT_RESET=false - return - fi - - # We update the repeat commands when it's the insert mode - [[ $ZVM_MODE == $ZVM_MODE_INSERT ]] || return - - local char=$KEYS - - # If current key is an arrow key, we should do something - if [[ "$KEYS" =~ '\[[ABCD]' ]]; then - # If last key is also an arrow key, we just replace it - if [[ ${ZVM_REPEAT_COMMANDS[-1]} =~ '\[[ABCD]' ]]; then - ZVM_REPEAT_COMMANDS=(${ZVM_REPEAT_COMMANDS[@]:0:-1}) - fi - else - # If last command is arrow key movement, we should reset - # the repeat commands with i(nsert) command - if [[ ${ZVM_REPEAT_COMMANDS[-1]} =~ '\[[ABCD]' ]]; then - zvm_reset_repeat_commands $ZVM_MODE_NORMAL i - fi - char=${BUFFER[$CURSOR]} - fi - - # If current key is backspace key, we should remove last - # one, until it has only the mode and inital command - if [[ "$KEYS" == '' ]]; then - if ((${#ZVM_REPEAT_COMMANDS[@]} > 2)) && - [[ ${ZVM_REPEAT_COMMANDS[-1]} != '' ]]; then - ZVM_REPEAT_COMMANDS=(${ZVM_REPEAT_COMMANDS[@]:0:-1}) - elif (($#LBUFFER > 0)); then - ZVM_REPEAT_COMMANDS+=($KEYS) - fi - else - ZVM_REPEAT_COMMANDS+=($char) - fi -} - -# Updates editor information when line pre redraw -function zvm_zle-line-pre-redraw() { - # Fix cursor style is not updated in tmux environment, when - # there are one more panel in the same window, the program - # in other panel could change the cursor shape, we need to - # update cursor style when line is redrawing. - zvm_update_cursor - zvm_update_highlight - zvm_update_repeat_commands -} - -# Start every prompt in the correct vi mode -function zvm_zle-line-init() { - # Save last mode - local mode=${ZVM_MODE:-$ZVM_MODE_INSERT} - - # It's neccessary to set to insert mode when line init - # and we don't need to reset prompt. - zvm_select_vi_mode $ZVM_MODE_INSERT false - - # Select line init mode and reset prompt - case ${ZVM_LINE_INIT_MODE:-$mode} in - $ZVM_MODE_INSERT) zvm_select_vi_mode $ZVM_MODE_INSERT;; - *) zvm_select_vi_mode $ZVM_MODE_NORMAL;; - esac -} - -# Restore the user default cursor style after prompt finish -function zvm_zle-line-finish() { - # When we start a program (e.g. vim, bash, etc.) from the - # command line, the cursor style is inherited by other - # programs, so that we need to reset the cursor style to - # default before executing a command and set the custom - # style again when the command exits. This way makes any - # other interactive CLI application would not be affected - # by it. - local shape=$(zvm_cursor_style $ZVM_CURSOR_USER_DEFAULT) - zvm_set_cursor $shape -} - -# Initialize vi-mode for widgets, keybindings, etc. -function zvm_init() { - zvm_exec_commands 'before_init' - - # Correct the readkey engine - case $ZVM_READKEY_ENGINE in - $ZVM_READKEY_ENGINE_NEX|$ZVM_READKEY_ENGINE_ZLE);; - *) - echo -n "Warning: Unsupported readkey engine! " - echo "ZVM_READKEY_ENGINE=$ZVM_READKEY_ENGINE" - ZVM_READKEY_ENGINE=$ZVM_READKEY_ENGINE_DEFAULT - ;; - esac - - # Reduce ESC delay (zle default is 0.4 seconds) - # Set to 0.01 second delay for taking over the key input processing - case $ZVM_READKEY_ENGINE in - $ZVM_READKEY_ENGINE_NEX) KEYTIMEOUT=1;; - $ZVM_READKEY_ENGINE_ZLE) KEYTIMEOUT=$(($ZVM_KEYTIMEOUT*100));; - esac - - # Create User-defined widgets - zvm_define_widget zvm_default_handler - zvm_define_widget zvm_readkeys_handler - zvm_define_widget zvm_backward_kill_region - zvm_define_widget zvm_backward_kill_line - zvm_define_widget zvm_forward_kill_line - zvm_define_widget zvm_kill_line - zvm_define_widget zvm_viins_undo - zvm_define_widget zvm_select_surround - zvm_define_widget zvm_change_surround - zvm_define_widget zvm_move_around_surround - zvm_define_widget zvm_change_surround_text_object - zvm_define_widget zvm_enter_insert_mode - zvm_define_widget zvm_exit_insert_mode - zvm_define_widget zvm_enter_visual_mode - zvm_define_widget zvm_exit_visual_mode - zvm_define_widget zvm_enter_oppend_mode - zvm_define_widget zvm_exit_oppend_mode - zvm_define_widget zvm_exchange_point_and_mark - zvm_define_widget zvm_open_line_below - zvm_define_widget zvm_open_line_above - zvm_define_widget zvm_insert_bol - zvm_define_widget zvm_append_eol - zvm_define_widget zvm_self_insert - zvm_define_widget zvm_vi_replace - zvm_define_widget zvm_vi_replace_chars - zvm_define_widget zvm_vi_substitute - zvm_define_widget zvm_vi_substitute_whole_line - zvm_define_widget zvm_vi_change - zvm_define_widget zvm_vi_change_eol - zvm_define_widget zvm_vi_delete - zvm_define_widget zvm_vi_yank - zvm_define_widget zvm_vi_put_after - zvm_define_widget zvm_vi_put_before - zvm_define_widget zvm_vi_up_case - zvm_define_widget zvm_vi_down_case - zvm_define_widget zvm_vi_opp_case - zvm_define_widget zvm_vi_edit_command_line - zvm_define_widget zvm_repeat_change - zvm_define_widget zvm_switch_keyword - - # Override standard widgets - zvm_define_widget zle-line-pre-redraw zvm_zle-line-pre-redraw - - # Ensure the correct cursor style when an interactive program - # (e.g. vim, bash, etc.) starts and exits - zvm_define_widget zle-line-init zvm_zle-line-init - zvm_define_widget zle-line-finish zvm_zle-line-finish - - # Override reset-prompt widget - zvm_define_widget reset-prompt zvm_reset_prompt - - # All Key bindings - # Emacs-like bindings - # Normal editing - zvm_bindkey viins '^A' beginning-of-line - zvm_bindkey viins '^E' end-of-line - zvm_bindkey viins '^B' backward-char - zvm_bindkey viins '^F' forward-char - zvm_bindkey viins '^K' zvm_forward_kill_line - zvm_bindkey viins '^W' backward-kill-word - zvm_bindkey viins '^U' zvm_viins_undo - zvm_bindkey viins '^Y' yank - zvm_bindkey viins '^_' undo - - # History search - zvm_bindkey viins '^R' history-incremental-search-backward - zvm_bindkey viins '^S' history-incremental-search-forward - zvm_bindkey viins '^P' up-line-or-history - zvm_bindkey viins '^N' down-line-or-history - - # Insert mode - zvm_bindkey vicmd 'i' zvm_enter_insert_mode - zvm_bindkey vicmd 'a' zvm_enter_insert_mode - zvm_bindkey vicmd 'I' zvm_insert_bol - zvm_bindkey vicmd 'A' zvm_append_eol - - # Other key bindings - zvm_bindkey vicmd 'v' zvm_enter_visual_mode - zvm_bindkey vicmd 'V' zvm_enter_visual_mode - zvm_bindkey visual 'o' zvm_exchange_point_and_mark - zvm_bindkey vicmd 'o' zvm_open_line_below - zvm_bindkey vicmd 'O' zvm_open_line_above - zvm_bindkey vicmd 'r' zvm_vi_replace_chars - zvm_bindkey vicmd 'R' zvm_vi_replace - zvm_bindkey vicmd 's' zvm_vi_substitute - zvm_bindkey vicmd 'S' zvm_vi_substitute_whole_line - zvm_bindkey vicmd 'C' zvm_vi_change_eol - zvm_bindkey visual 'c' zvm_vi_change - zvm_bindkey visual 'd' zvm_vi_delete - zvm_bindkey visual 'y' zvm_vi_yank - zvm_bindkey vicmd 'p' zvm_vi_put_after - zvm_bindkey vicmd 'P' zvm_vi_put_before - zvm_bindkey visual 'U' zvm_vi_up_case - zvm_bindkey visual 'u' zvm_vi_down_case - zvm_bindkey visual '~' zvm_vi_opp_case - zvm_bindkey visual 'v' zvm_vi_edit_command_line - zvm_bindkey vicmd '.' zvm_repeat_change - - zvm_bindkey vicmd '^A' zvm_switch_keyword - zvm_bindkey vicmd '^X' zvm_switch_keyword - - # Keybindings for escape key and some specials - local exit_oppend_mode_widget= - local exit_insert_mode_widget= - local exit_visual_mode_widget= - local default_handler_widget= - - case $ZVM_READKEY_ENGINE in - $ZVM_READKEY_ENGINE_NEX) - exit_oppend_mode_widget=zvm_readkeys_handler - exit_insert_mode_widget=zvm_readkeys_handler - exit_visual_mode_widget=zvm_readkeys_handler - ;; - $ZVM_READKEY_ENGINE_ZLE) - exit_insert_mode_widget=zvm_exit_insert_mode - exit_visual_mode_widget=zvm_exit_visual_mode - default_handler_widget=zvm_default_handler - ;; - esac - - # Bind custom escape key - zvm_bindkey vicmd "$ZVM_VI_OPPEND_ESCAPE_BINDKEY" $exit_oppend_mode_widget - zvm_bindkey viins "$ZVM_VI_INSERT_ESCAPE_BINDKEY" $exit_insert_mode_widget - zvm_bindkey visual "$ZVM_VI_VISUAL_ESCAPE_BINDKEY" $exit_visual_mode_widget - - # Bind the default escape key if the escape key is not the default - case "$ZVM_VI_OPPEND_ESCAPE_BINDKEY" in - '^['|'\e') ;; - *) zvm_bindkey vicmd '^[' $exit_oppend_mode_widget;; - esac - case "$ZVM_VI_INSERT_ESCAPE_BINDKEY" in - '^['|'\e') ;; - *) zvm_bindkey viins '^[' $exit_insert_mode_widget;; - esac - case "$ZVM_VI_VISUAL_ESCAPE_BINDKEY" in - '^['|'\e') ;; - *) zvm_bindkey visual '^[' $exit_visual_mode_widget;; - esac - - # Bind and overwrite original y/d/c of vicmd - for c in {y,d,c}; do - zvm_bindkey vicmd "$c" $default_handler_widget - done - - # Surround text-object - # Enable surround text-objects (quotes, brackets) - local surrounds=() - - # Append brackets - for s in ${(s..)^:-'()[]{}<>'}; do - surrounds+=($s) - done - - # Append quotes - for s in {\',\",\`,\ ,'^['}; do - surrounds+=($s) - done - - # Append for escaping visual mode - if $is_custom_escape_key; then - surrounds+=("$ZVM_VI_ESCAPE_BINDKEY") - fi - - # Surround key bindings - for s in $surrounds; do - for c in {a,i}${s}; do - zvm_bindkey visual "$c" zvm_select_surround - done - for c in {c,d,y}{a,i}${s}; do - zvm_bindkey vicmd "$c" zvm_change_surround_text_object - done - if [[ $ZVM_VI_SURROUND_BINDKEY == 's-prefix' ]]; then - for c in s{d,r}${s}; do - zvm_bindkey vicmd "$c" zvm_change_surround - done - for c in sa${s}; do - zvm_bindkey visual "$c" zvm_change_surround - done - else - for c in {d,c}s${s}; do - zvm_bindkey vicmd "$c" zvm_change_surround - done - for c in {S,ys}${s}; do - zvm_bindkey visual "$c" zvm_change_surround - done - fi - done - - # Moving around surrounds - zvm_bindkey vicmd '%' zvm_move_around_surround - - # Fix BACKSPACE was stuck in zsh - # Since normally '^?' (backspace) is bound to vi-backward-delete-char - zvm_bindkey viins '^?' backward-delete-char - - # Enable vi keymap - bindkey -v - - zvm_exec_commands 'after_init' -} - -# Precmd function -function zvm_precmd_function() { - # Init zsh vi mode when starting new command line at first time - if ! $ZVM_INIT_DONE; then - ZVM_INIT_DONE=true - zvm_init - fi -} - -# Check if a command is existed -function zvm_exist_command() { - command -v "$1" >/dev/null -} - -# Execute commands -function zvm_exec_commands() { - local commands="zvm_${1}_commands" - commands=(${(P)commands}) - - # Execute the default command - if zvm_exist_command "zvm_$1"; then - eval "zvm_$1" ${@:2} - fi - - # Execute extra commands - for cmd in $commands; do - if zvm_exist_command ${cmd}; then - cmd="$cmd ${@:2}" - fi - eval $cmd - done -} - -# Initialize the plugin when starting new command line -precmd_functions+=(zvm_precmd_function) - diff --git a/zsh/prompt.sh b/zsh/prompt.sh deleted file mode 100644 index 32791bc2a..000000000 --- a/zsh/prompt.sh +++ /dev/null @@ -1,63 +0,0 @@ -# Reference for colors: http://stackoverflow.com/questions/689765/how-can-i-change-the-color-of-my-prompt-in-zsh-different-from-normal-text - -autoload -U colors && colors - -setopt PROMPT_SUBST - -set_prompt() { - - # [ - PS1="[" - - # Path: http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/ - PS1+="%{$fg_bold[blue]%}${PWD/#$HOME/~}%{$reset_color%}" - - # Status Code - PS1+='%(?.., %{$fg[red]%}%?%{$reset_color%})' - - # Git - if git rev-parse --is-inside-work-tree 2> /dev/null | grep -q 'true' ; then - PS1+=', ' - PS1+="%{$fg[magenta]%}$(git rev-parse --abbrev-ref HEAD 2> /dev/null)%{$reset_color%}" - STATUS=$(git status --short | wc -l) - if [ $STATUS -gt 0 ]; then - PS1+="%{$fg[green]%}+$(echo $STATUS | awk '{$1=$1};1')%{$reset_color%}" - fi - fi - - - # Timer: http://stackoverflow.com/questions/2704635/is-there-a-way-to-find-the-running-time-of-the-last-executed-command-in-the-shel - if [[ $_elapsed[-1] -ne 0 ]]; then - PS1+=', ' - PS1+="%{$fg[yellow]%}$_elapsed[-1]s%{$reset_color%}" - fi - - # PID - if [[ $! -ne 0 ]]; then - PS1+=', ' - PS1+="%{$fg[yellow]%}PID:$!%{$reset_color%}" - fi - - # Sudo: https://superuser.com/questions/195781/sudo-is-there-a-command-to-check-if-i-have-sudo-and-or-how-much-time-is-left - CAN_I_RUN_SUDO=$(sudo -n uptime 2>&1|grep "load"|wc -l) - if [ ${CAN_I_RUN_SUDO} -gt 0 ] - then - PS1+=', ' - PS1+="%{$fg_bold[red]%}SUDO%{$reset_color%}" - fi - - # ] - PS1+="]: " -} - -precmd_functions+=set_prompt - -preexec () { - (( ${#_elapsed[@]} > 1000 )) && _elapsed=(${_elapsed[@]: -1000}) - _start=$SECONDS -} - -precmd () { - (( _start >= 0 )) && _elapsed+=($(( SECONDS-_start ))) - _start=-1 -} diff --git a/zsh/zshrc.sh b/zsh/zshrc.sh deleted file mode 100644 index 7e1cd15a6..000000000 --- a/zsh/zshrc.sh +++ /dev/null @@ -1,19 +0,0 @@ -# Vars - HISTFILE=~/.zsh_history - SAVEHIST=10000 - - -# Custom cd -source ~/dotfiles/zsh/plugins/fixls.zsh - -chpwd() ls - - -autoload -U compinit && compinit - -source ~/dotfiles/zsh/plugins/zsh-vi-mode.plugin.zsh -source ~/dotfiles/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh -source ~/dotfiles/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh -source ~/dotfiles/env-vars.env -source ~/dotfiles/zsh/lockbook.sh -source ~/dotfiles/zsh/prompt.sh diff --git a/zsh/zshrc_manager.sh b/zsh/zshrc_manager.sh deleted file mode 100644 index b313be3c9..000000000 --- a/zsh/zshrc_manager.sh +++ /dev/null @@ -1,16 +0,0 @@ -time_out () { perl -e 'alarm shift; exec @ARGV' "$@"; } - -echo "Checking for updates." -({cd ~/dotfiles && git fetch -q} &> /dev/null) - -if [ $({cd ~/dotfiles} &> /dev/null && git rev-list HEAD...origin/master | wc -l) = 0 ] -then - echo "Already up to date." -else - echo "Updates Detected:" - ({cd ~/dotfiles} &> /dev/null && git log ..@{u} --pretty=format:%Cred%aN:%Creset\ %s\ %Cgreen%cd) - echo "Setting up..." - ({cd ~/dotfiles} &> /dev/null && git pull -q && git submodule update --init --recursive) -fi - -source ~/dotfiles/zsh/zshrc.sh From 69b358e92ef1671d382ff6242d28575481e77355 Mon Sep 17 00:00:00 2001 From: parth Date: Tue, 19 Nov 2024 22:54:51 -0500 Subject: [PATCH 025/123] further nixOS investments --- nix/apply.sh | 3 +++ nix/configuration.nix | 14 ++++++++++++-- nix/deploy.sh | 5 ----- 3 files changed, 15 insertions(+), 7 deletions(-) create mode 100755 nix/apply.sh delete mode 100755 nix/deploy.sh diff --git a/nix/apply.sh b/nix/apply.sh new file mode 100755 index 000000000..8a3accc26 --- /dev/null +++ b/nix/apply.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +sudo rm -rf /etc/nixos/configuration.nix && sudo cp $HOME/dotfiles/nix/configuration.nix /etc/nixos/ && sudo nixos-rebuild switch diff --git a/nix/configuration.nix b/nix/configuration.nix index 5803b45bf..405f65c76 100644 --- a/nix/configuration.nix +++ b/nix/configuration.nix @@ -46,6 +46,14 @@ in LC_TIME = "en_US.UTF-8"; }; + programs.fish = { + enable = true; + # shellInit = '' + # fish_vi_key_bindings + # ''; + }; + users.defaultUserShell = pkgs.fish; + home-manager.users.parth = { /* The home.stateVersion option does not have a default and must be set */ home.stateVersion = "18.09"; @@ -55,6 +63,7 @@ in userName = "parth"; userEmail = "parth@mehrotra.me"; }; + }; # Enable the X11 windowing system. @@ -62,7 +71,7 @@ in # Enable the GNOME Desktop Environment. services.xserver.displayManager.gdm.enable = true; - services.xserver.desktopManager.kde.enable = true; + services.xserver.desktopManager.gnome.enable = true; # Configure keymap in X11 services.xserver.xkb = { @@ -112,6 +121,7 @@ in # Install firefox. programs.firefox.enable = true; + programs.git.enable = true; # Allow unfree packages nixpkgs.config.allowUnfree = true; @@ -119,8 +129,8 @@ in # List packages installed in system profile. To search, run: # $ nix search wget environment.systemPackages = with pkgs; [ - git neovim + fzf ]; diff --git a/nix/deploy.sh b/nix/deploy.sh deleted file mode 100755 index bbe6e5325..000000000 --- a/nix/deploy.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -# strangely i can copy / paste this command but not run this script - -sudo ln -s $HOME/dotfiles/nix/configuration.nix /etc/nixos/ From db983c10224ee376de92812e3ff17a4b3de2e659 Mon Sep 17 00:00:00 2001 From: parth Date: Sun, 24 Nov 2024 00:35:00 -0500 Subject: [PATCH 026/123] support for nvim in nix fashion --- nix/configuration.nix | 119 +++++++++++++++++------------------- nvim/deploy.sh | 2 +- nvim/lua/config.lua | 2 +- nvim/lua/keyboard.lua | 98 +++++++++++++++--------------- nvim/lua/packages.lua | 136 ++++++++++++++---------------------------- 5 files changed, 151 insertions(+), 206 deletions(-) diff --git a/nix/configuration.nix b/nix/configuration.nix index 405f65c76..05a5f0826 100644 --- a/nix/configuration.nix +++ b/nix/configuration.nix @@ -9,9 +9,10 @@ let in { imports = - [ # Include the results of the hardware scan. + [ + # Include the results of the hardware scan. ./hardware-configuration.nix - (import "${home-manager}/nixos") + (import "${home-manager}/nixos") ]; # Bootloader. @@ -21,11 +22,6 @@ in networking.hostName = "nixos"; # Define your hostname. # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant. - # Configure network proxy if necessary - # networking.proxy.default = "http://user:password@proxy:port/"; - # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain"; - - # Enable networking networking.networkmanager.enable = true; # Set your time zone. @@ -47,10 +43,10 @@ in }; programs.fish = { - enable = true; - # shellInit = '' - # fish_vi_key_bindings - # ''; + enable = true; + shellInit = '' + fish_vi_key_bindings + ''; }; users.defaultUserShell = pkgs.fish; @@ -60,29 +56,61 @@ in /* Here goes the rest of your home-manager config, e.g. home.packages = [ pkgs.foo ]; */ programs.git = { enable = true; - userName = "parth"; + userName = "parth"; userEmail = "parth@mehrotra.me"; }; + programs.neovim = { + enable = true; + plugins = with pkgs.vimPlugins; [ + nvim-web-devicons + telescope-nvim + nvim-cmp + cmp-nvim-lsp + vim-illuminate + lualine-nvim + lsp-status-nvim + nvim-tree-lua + nvim-lspconfig + luasnip + # todo replace "FabijanZulj/blame.nvim", + ]; + + extraPackages = with pkgs; [ + nixpkgs-fmt + lua-language-server + # i would like to configure this here but rustup does some wack shit + # rust-analyzer + ]; + + # extraLuaConfig = '' + # dofile("/home/parth/dotfiles/nvim/init.lua") + # ''; + }; + + + + xdg.configFile = { + "nvim" = { + source = /home/parth/dotfiles/nvim; + recursive = true; + }; + }; }; - # Enable the X11 windowing system. + services.xserver.enable = true; - # Enable the GNOME Desktop Environment. services.xserver.displayManager.gdm.enable = true; services.xserver.desktopManager.gnome.enable = true; - # Configure keymap in X11 services.xserver.xkb = { layout = "us"; variant = ""; }; - # Enable CUPS to print documents. services.printing.enable = true; - # Enable sound with pipewire. hardware.pulseaudio.enable = false; security.rtkit.enable = true; services.pipewire = { @@ -90,75 +118,38 @@ in alsa.enable = true; alsa.support32Bit = true; pulse.enable = true; - # If you want to use JACK applications, uncomment this - #jack.enable = true; - - # use the example session manager (no others are packaged yet so this is enabled by default, - # no need to redefine it in your config for now) - #media-session.enable = true; }; - # Enable touchpad support (enabled default in most desktopManager). - # services.xserver.libinput.enable = true; - - # Define a user account. Don't forget to set a password with ‘passwd’. users.users.parth = { isNormalUser = true; description = "parth"; extraGroups = [ "networkmanager" "wheel" ]; packages = with pkgs; [ - # thunderbird + fzf + ripgrep + clang + + rust-analyzer + rustup + + nixd ]; }; - # Enable automatic login for the user. services.xserver.displayManager.autoLogin.enable = true; services.xserver.displayManager.autoLogin.user = "parth"; - # Workaround for GNOME autologin: https://github.com/NixOS/nixpkgs/issues/103746#issuecomment-945091229 systemd.services."getty@tty1".enable = false; systemd.services."autovt@tty1".enable = false; - # Install firefox. programs.firefox.enable = true; programs.git.enable = true; - # Allow unfree packages nixpkgs.config.allowUnfree = true; - # List packages installed in system profile. To search, run: - # $ nix search wget environment.systemPackages = with pkgs; [ - neovim - fzf + xclip ]; - - - # Some programs need SUID wrappers, can be configured further or are - # started in user sessions. - # programs.mtr.enable = true; - # programs.gnupg.agent = { - # enable = true; - # enableSSHSupport = true; - # }; - - # List services that you want to enable: - - # Enable the OpenSSH daemon. - # services.openssh.enable = true; - - # Open ports in the firewall. - # networking.firewall.allowedTCPPorts = [ ... ]; - # networking.firewall.allowedUDPPorts = [ ... ]; - # Or disable the firewall altogether. - # networking.firewall.enable = false; - - # This value determines the NixOS release from which the default - # settings for stateful data, like file locations and database versions - # on your system were taken. It‘s perfectly fine and recommended to leave - # this value at the release version of the first install of this system. - # Before changing this value read the documentation for this option - # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). - system.stateVersion = "24.05"; # Did you read the comment? + system.stateVersion = "24.05"; } diff --git a/nvim/deploy.sh b/nvim/deploy.sh index 66422be1d..02f46d6ff 100755 --- a/nvim/deploy.sh +++ b/nvim/deploy.sh @@ -1,3 +1,3 @@ -#!/bin/bash +#!/bin/sh ln -s $HOME/dotfiles/nvim $HOME/.config/nvim diff --git a/nvim/lua/config.lua b/nvim/lua/config.lua index 207bc429f..340c97f97 100644 --- a/nvim/lua/config.lua +++ b/nvim/lua/config.lua @@ -15,4 +15,4 @@ vim.opt.hlsearch = true vim.opt.incsearch = true vim.opt.cursorline = true -vim.api.nvim_set_hl(0, 'CursorLine', {underline=true}) +vim.api.nvim_set_hl(0, 'CursorLine', { underline = true }) diff --git a/nvim/lua/keyboard.lua b/nvim/lua/keyboard.lua index c63eb3cd9..0831c2105 100644 --- a/nvim/lua/keyboard.lua +++ b/nvim/lua/keyboard.lua @@ -23,60 +23,62 @@ vim.keymap.set("n", "", vim.cmd.BlameToggle) -- LSP keybindings vim.api.nvim_create_autocmd('LspAttach', { - desc = 'LSP actions', - callback = function(event) - local opts = {buffer = event.buf} + desc = 'LSP actions', + callback = function(event) + local opts = { buffer = event.buf } - vim.keymap.set('n', 'K', 'lua vim.lsp.buf.hover()', opts) - vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', opts) - vim.keymap.set('n', 'fr', builtin.lsp_references, opts) - vim.keymap.set('n', 'ws', builtin.lsp_workspace_symbols, opts) - vim.keymap.set('n', 'ds', builtin.lsp_document_symbols, opts) - vim.keymap.set('n', 'rn', 'lua vim.lsp.buf.rename()', opts) - vim.keymap.set('n', 'fmt', 'lua vim.lsp.buf.format()', opts) - vim.keymap.set('i', '', 'lua vim.lsp.buf.signature_help()', opts) - vim.keymap.set('n', 'vd', 'lua vim.diagnostic.open_float()', opts) - vim.keymap.set('n', 'nd', 'lua vim.diagnostic.goto_next()', opts) - vim.keymap.set('n', 'pd', 'lua vim.diagnostic.goto_prev()', opts) - vim.keymap.set('n', ' ', 'lua vim.lsp.buf.code_action()', opts) - vim.keymap.set('n', 'nr', function() require('illuminate').goto_next_reference(wrap) end, opts) - vim.keymap.set('n', 'pr', function() require('illuminate').goto_prev_reference(wrap) end, opts) - end + vim.keymap.set('n', 'K', 'lua vim.lsp.buf.hover()', opts) + vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + vim.keymap.set('n', 'fr', builtin.lsp_references, opts) + vim.keymap.set('n', 'ws', builtin.lsp_workspace_symbols, opts) + vim.keymap.set('n', 'ds', builtin.lsp_document_symbols, opts) + vim.keymap.set('n', 'rn', 'lua vim.lsp.buf.rename()', opts) + vim.keymap.set('n', 'fmt', 'lua vim.lsp.buf.format()', opts) + vim.keymap.set('i', '', 'lua vim.lsp.buf.signature_help()', opts) + vim.keymap.set('n', 'vd', 'lua vim.diagnostic.open_float()', opts) + vim.keymap.set('n', 'nd', 'lua vim.diagnostic.goto_next()', opts) + vim.keymap.set('n', 'pd', 'lua vim.diagnostic.goto_prev()', opts) + vim.keymap.set('n', ' ', 'lua vim.lsp.buf.code_action()', opts) + vim.keymap.set('n', 'nr', function() require('illuminate').goto_next_reference(wrap) end, opts) + vim.keymap.set('n', 'pr', function() require('illuminate').goto_prev_reference(wrap) end, opts) + end }) + + -- Completion related keybindings local cmp = require('cmp') cmp.setup({ - sources = { - {name = 'nvim_lsp'}, - }, - mapping = { - [''] = cmp.mapping.confirm({select = false}), - [''] = cmp.mapping.abort(), - [''] = cmp.mapping.select_prev_item({behavior = 'select'}), - [''] = cmp.mapping.select_next_item({behavior = 'select'}), - [''] = cmp.mapping.complete(), - [''] = cmp.mapping(function() - if cmp.visible() then - cmp.select_prev_item({behavior = 'insert'}) - else - cmp.complete() - end - end), - [''] = cmp.mapping(function() - if cmp.visible() then - cmp.select_next_item({behavior = 'insert'}) - else - cmp.complete() - end - end), - }, - snippet = { - expand = function(args) - require('luasnip').lsp_expand(args.body) - end, - }, + sources = { + { name = 'nvim_lsp' }, + }, + mapping = { + [''] = cmp.mapping.confirm({ select = false }), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.select_prev_item({ behavior = 'select' }), + [''] = cmp.mapping.select_next_item({ behavior = 'select' }), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping(function() + if cmp.visible() then + cmp.select_prev_item({ behavior = 'insert' }) + else + cmp.complete() + end + end), + [''] = cmp.mapping(function() + if cmp.visible() then + cmp.select_next_item({ behavior = 'insert' }) + else + cmp.complete() + end + end), + }, + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, }) --- blame +-- blame diff --git a/nvim/lua/packages.lua b/nvim/lua/packages.lua index 950f07380..f9086827c 100644 --- a/nvim/lua/packages.lua +++ b/nvim/lua/packages.lua @@ -1,94 +1,3 @@ -local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" -if not (vim.uv or vim.loop).fs_stat(lazypath) then - vim.fn.system({ - "git", - "clone", - "--filter=blob:none", - "https://github.com/folke/lazy.nvim.git", - "--branch=stable", - lazypath, - }) -end -vim.opt.rtp:prepend(lazypath) - -require("lazy").setup( - { - -- treesitter: richer syntax highlighting - { - "nvim-treesitter/nvim-treesitter", - build = ":TSUpdate", - config = function() - local configs = require("nvim-treesitter.configs") - - configs.setup({ - ensure_installed = { "c", "lua", "vim", "rust", "go" }, - sync_install = false, - highlight = { enable = true }, - indent = { enable = true }, - }) - end - }, - - -- telescope - { - 'nvim-telescope/telescope.nvim', - tag = '0.1.6', - dependencies = { 'nvim-lua/plenary.nvim' } - }, - - -- lsp-zero - { 'VonHeikemen/lsp-zero.nvim', branch = 'v3.x' }, - { 'neovim/nvim-lspconfig' }, - { 'hrsh7th/cmp-nvim-lsp' }, - { 'hrsh7th/nvim-cmp' }, - { 'L3MON4D3/LuaSnip' }, - { 'williamboman/mason.nvim' }, - { 'williamboman/mason-lspconfig.nvim' }, - - -- for nvim config lsp support - { "folke/neodev.nvim", opts = {} }, - - -- highlight words - { 'RRethy/vim-illuminate' }, - - -- lua line - { - 'nvim-lualine/lualine.nvim', - dependencies = { 'nvim-tree/nvim-web-devicons' } - }, - - -- lsp-status populated in lua line - { 'nvim-lua/lsp-status.nvim' }, - - -- nvim-tree - { - 'nvim-tree/nvim-tree.lua', - dependencies = { 'nvim-tree/nvim-web-devicons' } - }, - - -- blame - { - "FabijanZulj/blame.nvim", - } - }, - { - install = { - colorscheme = { "default" } - } - } -) - -require('lsp-zero') -require('mason').setup({}) -require('mason-lspconfig').setup({ - ensure_installed = { "rust_analyzer", "lua_ls", "gopls" }, - handlers = { - function(server_name) - require('lspconfig')[server_name].setup({}) - end, - }, -}) - -- illuminate require("illuminate").configure {} vim.api.nvim_set_hl(0, "IlluminatedWordText", { link = "CursorLine" }) @@ -147,5 +56,48 @@ require("nvim-tree").setup({ } }) +local lspconfig = require("lspconfig") + +lspconfig.rust_analyzer.setup({ + settings = { + ["rust-analyzer"] = { + cargo = { + allFeatures = true, + }, + checkOnSave = { + command = "clippy", + }, + }, + }, +}) + +lspconfig.lua_ls.setup { + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using + -- (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { + 'vim', + 'require' + }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + }, + }, +} +lspconfig.nixd.setup {} + -- blame -require("blame").setup() +-- require("blame").setup() From 21a280dc4561de819e186d5a41e74ea50e8db806 Mon Sep 17 00:00:00 2001 From: parth Date: Mon, 25 Nov 2024 23:13:48 -0500 Subject: [PATCH 027/123] fonts are working in nix --- nix/configuration.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nix/configuration.nix b/nix/configuration.nix index 05a5f0826..e47ad9108 100644 --- a/nix/configuration.nix +++ b/nix/configuration.nix @@ -129,6 +129,8 @@ in ripgrep clang + + # move these to neovim specific area rust-analyzer rustup @@ -136,6 +138,10 @@ in ]; }; + fonts.packages = with pkgs; [ + nerdfonts + ]; + services.xserver.displayManager.autoLogin.enable = true; services.xserver.displayManager.autoLogin.user = "parth"; From d2b4e8d097a41490d240ad954eea2ff28930cdf0 Mon Sep 17 00:00:00 2001 From: parth Date: Fri, 29 Nov 2024 00:21:24 -0500 Subject: [PATCH 028/123] browser, discord, slack, 1password --- nix/configuration.nix | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/nix/configuration.nix b/nix/configuration.nix index e47ad9108..584645e98 100644 --- a/nix/configuration.nix +++ b/nix/configuration.nix @@ -6,6 +6,14 @@ let home-manager = builtins.fetchTarball "https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz"; + lock-false = { + Value = false; + Status = "locked"; + }; + lock-true = { + Value = true; + Status = "locked"; + }; in { imports = @@ -60,6 +68,7 @@ in userEmail = "parth@mehrotra.me"; }; + programs.neovim = { enable = true; plugins = with pkgs.vimPlugins; [ @@ -129,6 +138,11 @@ in ripgrep clang + _1password-gui + google-chrome + discord + spotify + slack # move these to neovim specific area rust-analyzer @@ -148,7 +162,14 @@ in systemd.services."getty@tty1".enable = false; systemd.services."autovt@tty1".enable = false; - programs.firefox.enable = true; + programs._1password-gui.enable = true; + programs.chromium = { + enable = true; + extraOpts = { + "PasswordManagerEnabled" = false; + }; + }; + programs.git.enable = true; nixpkgs.config.allowUnfree = true; From 6794908257c75818a6c4509774f5f83f7c75748f Mon Sep 17 00:00:00 2001 From: parth Date: Fri, 29 Nov 2024 21:58:34 -0500 Subject: [PATCH 029/123] machine specific config --- nix/apply.sh | 8 +++++++- nix/{ => common}/configuration.nix | 3 ++- nix/laptop.nix | 5 +++++ nix/workstation.nix | 5 +++++ nvim/deploy.sh | 0 utils/copy | 0 6 files changed, 19 insertions(+), 2 deletions(-) rename nix/{ => common}/configuration.nix (98%) create mode 100644 nix/laptop.nix create mode 100644 nix/workstation.nix mode change 100755 => 100644 nvim/deploy.sh mode change 100755 => 100644 utils/copy diff --git a/nix/apply.sh b/nix/apply.sh index 8a3accc26..f2ff38b8f 100755 --- a/nix/apply.sh +++ b/nix/apply.sh @@ -1,3 +1,9 @@ #!/bin/sh -sudo rm -rf /etc/nixos/configuration.nix && sudo cp $HOME/dotfiles/nix/configuration.nix /etc/nixos/ && sudo nixos-rebuild switch +if [ $# -eq 0 ] + then + echo "supply file as argument" + exit 1 +fi + +sudo rm -rf /etc/nixos/configuration.nix && sudo cp $HOME/dotfiles/nix/$1 /etc/nixos/configuration.nix && sudo nixos-rebuild switch diff --git a/nix/configuration.nix b/nix/common/configuration.nix similarity index 98% rename from nix/configuration.nix rename to nix/common/configuration.nix index 584645e98..8ad2e7fb0 100644 --- a/nix/configuration.nix +++ b/nix/common/configuration.nix @@ -19,7 +19,8 @@ in imports = [ # Include the results of the hardware scan. - ./hardware-configuration.nix + # ./hardware-configuration.nix + "/etc/nixos/hardware-configuration.nix" (import "${home-manager}/nixos") ]; diff --git a/nix/laptop.nix b/nix/laptop.nix new file mode 100644 index 000000000..6736ba468 --- /dev/null +++ b/nix/laptop.nix @@ -0,0 +1,5 @@ +{ + imports = [ + "/home/parth/dotfiles/nix/common/configuration.nix" + ]; +} diff --git a/nix/workstation.nix b/nix/workstation.nix new file mode 100644 index 000000000..6736ba468 --- /dev/null +++ b/nix/workstation.nix @@ -0,0 +1,5 @@ +{ + imports = [ + "/home/parth/dotfiles/nix/common/configuration.nix" + ]; +} diff --git a/nvim/deploy.sh b/nvim/deploy.sh old mode 100755 new mode 100644 diff --git a/utils/copy b/utils/copy old mode 100755 new mode 100644 From 209e5aeeecdc3cdb59acbb62f5dd1f5744a30a0b Mon Sep 17 00:00:00 2001 From: parth Date: Fri, 29 Nov 2024 22:57:48 -0500 Subject: [PATCH 030/123] graphics are working --- nix/workstation.nix | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/nix/workstation.nix b/nix/workstation.nix index 6736ba468..573c84ab4 100644 --- a/nix/workstation.nix +++ b/nix/workstation.nix @@ -1,5 +1,41 @@ +{ config, lib, pkgs, ... }: { - imports = [ - "/home/parth/dotfiles/nix/common/configuration.nix" - ]; + imports = [ + "/home/parth/dotfiles/nix/common/configuration.nix" + ]; + + # Load nvidia driver for Xorg and Wayland + services.xserver.videoDrivers = [ "nvidia" ]; + + hardware.nvidia = { + + # Modesetting is required. + modesetting.enable = true; + + # Nvidia power management. Experimental, and can cause sleep/suspend to fail. + # Enable this if you have graphical corruption issues or application crashes after waking + # up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead + # of just the bare essentials. + powerManagement.enable = false; + + # Fine-grained power management. Turns off GPU when not in use. + # Experimental and only works on modern Nvidia GPUs (Turing or newer). + powerManagement.finegrained = false; + + # Use the NVidia open source kernel module (not to be confused with the + # independent third-party "nouveau" open source driver). + # Support is limited to the Turing and later architectures. Full list of + # supported GPUs is at: + # https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus + # Only available from driver 515.43.04+ + # Currently alpha-quality/buggy, so false is currently the recommended setting. + open = false; + + # Enable the Nvidia settings menu, + # accessible via `nvidia-settings`. + nvidiaSettings = true; + + # Optionally, you may need to select the appropriate driver version for your specific GPU. + package = config.boot.kernelPackages.nvidiaPackages.stable; + }; } From aeb4c6c2f43bc89eff1208497569a4da70083eea Mon Sep 17 00:00:00 2001 From: parth Date: Fri, 29 Nov 2024 23:20:08 -0500 Subject: [PATCH 031/123] gpu things seem better --- nix/common/configuration.nix | 1 + nix/workstation.nix | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/nix/common/configuration.nix b/nix/common/configuration.nix index 8ad2e7fb0..6385837cd 100644 --- a/nix/common/configuration.nix +++ b/nix/common/configuration.nix @@ -24,6 +24,7 @@ in (import "${home-manager}/nixos") ]; + # Bootloader. boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; diff --git a/nix/workstation.nix b/nix/workstation.nix index 573c84ab4..fa161a3e2 100644 --- a/nix/workstation.nix +++ b/nix/workstation.nix @@ -7,6 +7,12 @@ # Load nvidia driver for Xorg and Wayland services.xserver.videoDrivers = [ "nvidia" ]; + hardware.opengl = { + enable = true; + driSupport = true; + driSupport32Bit = true; + }; + hardware.nvidia = { # Modesetting is required. From 4af73af533b2c4c3dc0590d753ccfcfb91e860d4 Mon Sep 17 00:00:00 2001 From: parth Date: Sat, 30 Nov 2024 00:15:06 -0500 Subject: [PATCH 032/123] gpu things seem better --- nix/common/configuration.nix | 4 ++-- nix/workstation.nix | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/nix/common/configuration.nix b/nix/common/configuration.nix index 6385837cd..97a1be4a1 100644 --- a/nix/common/configuration.nix +++ b/nix/common/configuration.nix @@ -24,7 +24,7 @@ in (import "${home-manager}/nixos") ]; - + # Bootloader. boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; @@ -111,7 +111,7 @@ in services.xserver.enable = true; - + services.xserver.displayManager.gdm.wayland = false; services.xserver.displayManager.gdm.enable = true; services.xserver.desktopManager.gnome.enable = true; diff --git a/nix/workstation.nix b/nix/workstation.nix index fa161a3e2..86afe969e 100644 --- a/nix/workstation.nix +++ b/nix/workstation.nix @@ -1,12 +1,9 @@ { config, lib, pkgs, ... }: { - imports = [ - "/home/parth/dotfiles/nix/common/configuration.nix" - ]; - # Load nvidia driver for Xorg and Wayland services.xserver.videoDrivers = [ "nvidia" ]; + # Load nvidia driver for Xorg and Wayland hardware.opengl = { enable = true; driSupport = true; @@ -15,6 +12,7 @@ hardware.nvidia = { + forceFullCompositionPipeline = true; # Modesetting is required. modesetting.enable = true; @@ -44,4 +42,16 @@ # Optionally, you may need to select the appropriate driver version for your specific GPU. package = config.boot.kernelPackages.nvidiaPackages.stable; }; + + # this config seemed to initially make wayland the default until I forced it to be x11 at the gdm level + # the behavior was really strange lots of weird frame stuttering going on until x11 was the default, than + # many problems went away. + # I don't have screen tearing at this point, and that's generally my litmus test, but I do seem to have + # vsync issues (which I've probably never tested for before). But I do have 2 monitors with different + # refresh rates, so maybe that's just my problem. + # maybe some combination of a new driver from nvidia and wayland will solve this at some pognt + + imports = [ + "/home/parth/dotfiles/nix/common/configuration.nix" + ]; } From ec7aa18ac36ffe059deff4fc25c3c7e12a049278 Mon Sep 17 00:00:00 2001 From: parth Date: Tue, 3 Dec 2024 22:48:21 -0500 Subject: [PATCH 033/123] split out gui config --- nix/common/gui.nix | 46 ++++++++++++ .../{configuration.nix => headless.nix} | 75 +------------------ nix/laptop.nix | 13 +++- nix/workstation.nix | 10 ++- 4 files changed, 67 insertions(+), 77 deletions(-) create mode 100644 nix/common/gui.nix rename nix/common/{configuration.nix => headless.nix} (60%) diff --git a/nix/common/gui.nix b/nix/common/gui.nix new file mode 100644 index 000000000..1a6614dac --- /dev/null +++ b/nix/common/gui.nix @@ -0,0 +1,46 @@ +{ pkgs, ... }: { + + services.xserver.enable = true; + services.xserver.displayManager.gdm.wayland = false; + services.xserver.displayManager.gdm.enable = true; + services.xserver.desktopManager.gnome.enable = true; + services.xserver.displayManager.autoLogin.enable = true; + services.xserver.displayManager.autoLogin.user = "parth"; + + services.xserver.xkb = { + layout = "us"; + variant = ""; + }; + + services.printing.enable = true; + + hardware.pulseaudio.enable = false; + security.rtkit.enable = true; + services.pipewire = { + enable = true; + alsa.enable = true; + alsa.support32Bit = true; + pulse.enable = true; + }; + + fonts.packages = with pkgs; [ + nerdfonts + ]; + + users.users.parth.packages = with pkgs; [ + _1password-gui + google-chrome + discord + spotify + slack + ]; + + programs._1password-gui.enable = true; + programs.chromium = { + enable = true; + extraOpts = { + "PasswordManagerEnabled" = false; + }; + }; + +} diff --git a/nix/common/configuration.nix b/nix/common/headless.nix similarity index 60% rename from nix/common/configuration.nix rename to nix/common/headless.nix index 97a1be4a1..2e1d8c55b 100644 --- a/nix/common/configuration.nix +++ b/nix/common/headless.nix @@ -1,19 +1,7 @@ -# Edit this configuration file to define what should be installed on -# your system. Help is available in the configuration.nix(5) man page -# and in the NixOS manual (accessible by running ‘nixos-help’). - -{ config, pkgs, ... }: +{ pkgs, ... }: let home-manager = builtins.fetchTarball "https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz"; - lock-false = { - Value = false; - Status = "locked"; - }; - lock-true = { - Value = true; - Status = "locked"; - }; in { imports = @@ -24,22 +12,10 @@ in (import "${home-manager}/nixos") ]; - - # Bootloader. - boot.loader.systemd-boot.enable = true; - boot.loader.efi.canTouchEfiVariables = true; - - networking.hostName = "nixos"; # Define your hostname. - # networking.wireless.enable = true; # Enables wireless support via wpa_supplicant. - networking.networkmanager.enable = true; - # Set your time zone. time.timeZone = "America/New_York"; - - # Select internationalisation properties. i18n.defaultLocale = "en_US.UTF-8"; - i18n.extraLocaleSettings = { LC_ADDRESS = "en_US.UTF-8"; LC_IDENTIFICATION = "en_US.UTF-8"; @@ -109,43 +85,16 @@ in }; }; - - services.xserver.enable = true; - services.xserver.displayManager.gdm.wayland = false; - services.xserver.displayManager.gdm.enable = true; - services.xserver.desktopManager.gnome.enable = true; - - services.xserver.xkb = { - layout = "us"; - variant = ""; - }; - - services.printing.enable = true; - - hardware.pulseaudio.enable = false; - security.rtkit.enable = true; - services.pipewire = { - enable = true; - alsa.enable = true; - alsa.support32Bit = true; - pulse.enable = true; - }; - users.users.parth = { isNormalUser = true; description = "parth"; extraGroups = [ "networkmanager" "wheel" ]; packages = with pkgs; [ - fzf + xclip + ripgrep clang - _1password-gui - google-chrome - discord - spotify - slack - # move these to neovim specific area rust-analyzer rustup @@ -154,31 +103,13 @@ in ]; }; - fonts.packages = with pkgs; [ - nerdfonts - ]; - - services.xserver.displayManager.autoLogin.enable = true; - services.xserver.displayManager.autoLogin.user = "parth"; systemd.services."getty@tty1".enable = false; systemd.services."autovt@tty1".enable = false; - programs._1password-gui.enable = true; - programs.chromium = { - enable = true; - extraOpts = { - "PasswordManagerEnabled" = false; - }; - }; - programs.git.enable = true; nixpkgs.config.allowUnfree = true; - environment.systemPackages = with pkgs; [ - xclip - ]; - system.stateVersion = "24.05"; } diff --git a/nix/laptop.nix b/nix/laptop.nix index 6736ba468..28c72d0d7 100644 --- a/nix/laptop.nix +++ b/nix/laptop.nix @@ -1,5 +1,12 @@ { - imports = [ - "/home/parth/dotfiles/nix/common/configuration.nix" - ]; + imports = [ + "/home/parth/dotfiles/nix/common/headless.nix" + "/home/parth/dotfiles/nix/common/gui.nix" + ]; + + networking.hostName = "parth-laptop-nix"; + + # Bootloader. + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; } diff --git a/nix/workstation.nix b/nix/workstation.nix index 86afe969e..a13548d8b 100644 --- a/nix/workstation.nix +++ b/nix/workstation.nix @@ -1,5 +1,6 @@ -{ config, lib, pkgs, ... }: +{ config, ... }: { + networking.hostName = "parth-workstation-nix"; services.xserver.videoDrivers = [ "nvidia" ]; @@ -52,6 +53,11 @@ # maybe some combination of a new driver from nvidia and wayland will solve this at some pognt imports = [ - "/home/parth/dotfiles/nix/common/configuration.nix" + "/home/parth/dotfiles/nix/common/headless.nix" + "/home/parth/dotfiles/nix/common/gui.nix" ]; + + # Bootloader. + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; } From 41a74d1a885bd1890feffbf26debe12b5d713740 Mon Sep 17 00:00:00 2001 From: parth Date: Tue, 3 Dec 2024 23:45:39 -0500 Subject: [PATCH 034/123] intial server config --- nix/common/gui.nix | 1 - nix/server.nix | 23 +++++++++++++++++++++++ nix/workstation.nix | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 nix/server.nix diff --git a/nix/common/gui.nix b/nix/common/gui.nix index 1a6614dac..31ef446d3 100644 --- a/nix/common/gui.nix +++ b/nix/common/gui.nix @@ -1,7 +1,6 @@ { pkgs, ... }: { services.xserver.enable = true; - services.xserver.displayManager.gdm.wayland = false; services.xserver.displayManager.gdm.enable = true; services.xserver.desktopManager.gnome.enable = true; services.xserver.displayManager.autoLogin.enable = true; diff --git a/nix/server.nix b/nix/server.nix new file mode 100644 index 000000000..abda1a33c --- /dev/null +++ b/nix/server.nix @@ -0,0 +1,23 @@ +{ + imports = [ + "/home/parth/dotfiles/nix/common/headless.nix" + ]; + + networking.hostName = "parth-server-nix"; + + # Bootloader. + boot.loader.grub = { + enable = true; + device = "/dev/nvme1n1"; + useOSProber = true; + }; + + services.openssh = { + enable = true; + settings = { + PermitRootLogin = "yes"; + PasswordAuthentication = true; + }; + }; + +} diff --git a/nix/workstation.nix b/nix/workstation.nix index a13548d8b..cc7585733 100644 --- a/nix/workstation.nix +++ b/nix/workstation.nix @@ -11,6 +11,8 @@ driSupport32Bit = true; }; + services.xserver.displayManager.gdm.wayland = false; + hardware.nvidia = { forceFullCompositionPipeline = true; From 791c8c40a69f14f7ad752ec02467761041fdef3f Mon Sep 17 00:00:00 2001 From: parth Date: Wed, 4 Dec 2024 00:08:36 -0500 Subject: [PATCH 035/123] tweak server config --- nix/common/gui.nix | 2 ++ nix/common/headless.nix | 2 -- nix/server.nix | 11 ++++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/nix/common/gui.nix b/nix/common/gui.nix index 31ef446d3..463d51991 100644 --- a/nix/common/gui.nix +++ b/nix/common/gui.nix @@ -42,4 +42,6 @@ }; }; + systemd.services."getty@tty1".enable = false; + systemd.services."autovt@tty1".enable = false; } diff --git a/nix/common/headless.nix b/nix/common/headless.nix index 2e1d8c55b..6a2c2d5fc 100644 --- a/nix/common/headless.nix +++ b/nix/common/headless.nix @@ -104,8 +104,6 @@ in }; - systemd.services."getty@tty1".enable = false; - systemd.services."autovt@tty1".enable = false; programs.git.enable = true; diff --git a/nix/server.nix b/nix/server.nix index abda1a33c..c7eb9428a 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -13,11 +13,12 @@ }; services.openssh = { - enable = true; - settings = { - PermitRootLogin = "yes"; - PasswordAuthentication = true; - }; + enable = true; + settings = { + PermitRootLogin = "yes"; + PasswordAuthentication = true; + }; }; + systemd.services."getty@tty1".enable = false; } From 35c8d1326b5c3317aa30ac6915bcaf5d295f1197 Mon Sep 17 00:00:00 2001 From: parth Date: Wed, 4 Dec 2024 00:16:34 -0500 Subject: [PATCH 036/123] tty needed for server --- nix/laptop.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nix/laptop.nix b/nix/laptop.nix index 28c72d0d7..c0e685362 100644 --- a/nix/laptop.nix +++ b/nix/laptop.nix @@ -6,7 +6,8 @@ networking.hostName = "parth-laptop-nix"; - # Bootloader. boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; + + services.tlp.enable = true; } From 679d757a376bb677a53ec72625d703a3e8e99f9c Mon Sep 17 00:00:00 2001 From: parth Date: Wed, 4 Dec 2024 20:05:46 -0500 Subject: [PATCH 037/123] restore CI? --- nix/server.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nix/server.nix b/nix/server.nix index c7eb9428a..22df3bdae 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -21,4 +21,11 @@ }; systemd.services."getty@tty1".enable = false; + + services.github-runners.lockbook = { + enable = true; + name = "parth-server-nix"; + tokenFile = "/home/parth/token"; + url = "https://github.com/lockbook/lockbook"; + }; } From ccb2aa62c408619e72e802f267bae04b2cd8cb5d Mon Sep 17 00:00:00 2001 From: parth Date: Wed, 4 Dec 2024 20:11:08 -0500 Subject: [PATCH 038/123] restore CI? --- nix/server.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/server.nix b/nix/server.nix index 22df3bdae..683ea4204 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -24,7 +24,7 @@ services.github-runners.lockbook = { enable = true; - name = "parth-server-nix"; + name = "ci"; tokenFile = "/home/parth/token"; url = "https://github.com/lockbook/lockbook"; }; From 2f776c020bd37820ba6aeb29cb39b5af5db88f36 Mon Sep 17 00:00:00 2001 From: parth Date: Wed, 4 Dec 2024 20:14:23 -0500 Subject: [PATCH 039/123] restore CI? --- nix/server.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nix/server.nix b/nix/server.nix index 683ea4204..bacff2deb 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -25,6 +25,7 @@ services.github-runners.lockbook = { enable = true; name = "ci"; + extraLabels = [ "ci" ]; tokenFile = "/home/parth/token"; url = "https://github.com/lockbook/lockbook"; }; From e35ba2923815f1641e42c0f14ec73b7d11f7e57c Mon Sep 17 00:00:00 2001 From: parth Date: Wed, 4 Dec 2024 20:15:25 -0500 Subject: [PATCH 040/123] restore CI? --- nix/server.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/server.nix b/nix/server.nix index bacff2deb..71121fe7a 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -24,7 +24,7 @@ services.github-runners.lockbook = { enable = true; - name = "ci"; + name = "lockbook ci"; extraLabels = [ "ci" ]; tokenFile = "/home/parth/token"; url = "https://github.com/lockbook/lockbook"; From 7a71d5a270e6c0f7fb9c4a64b3996900cf8244d0 Mon Sep 17 00:00:00 2001 From: parth Date: Wed, 4 Dec 2024 20:17:04 -0500 Subject: [PATCH 041/123] restore CI? --- nix/server.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nix/server.nix b/nix/server.nix index 71121fe7a..ae3160829 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -1,4 +1,4 @@ -{ +{pkgs, ...}: { imports = [ "/home/parth/dotfiles/nix/common/headless.nix" ]; @@ -28,5 +28,8 @@ extraLabels = [ "ci" ]; tokenFile = "/home/parth/token"; url = "https://github.com/lockbook/lockbook"; + extraPackages = with pkgs; [ + rustup + ]; }; } From 241a32e7fad67b224a87a81eba3fb6ea5eef9c83 Mon Sep 17 00:00:00 2001 From: parth Date: Wed, 4 Dec 2024 22:44:33 -0500 Subject: [PATCH 042/123] restore CI? --- nix/common/headless.nix | 1 + nix/laptop.nix | 2 -- nix/server.nix | 19 ++++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/nix/common/headless.nix b/nix/common/headless.nix index 6a2c2d5fc..82f68a0be 100644 --- a/nix/common/headless.nix +++ b/nix/common/headless.nix @@ -90,6 +90,7 @@ in description = "parth"; extraGroups = [ "networkmanager" "wheel" ]; packages = with pkgs; [ + fzf xclip ripgrep diff --git a/nix/laptop.nix b/nix/laptop.nix index c0e685362..3a1ec9bf9 100644 --- a/nix/laptop.nix +++ b/nix/laptop.nix @@ -8,6 +8,4 @@ boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; - - services.tlp.enable = true; } diff --git a/nix/server.nix b/nix/server.nix index ae3160829..7e8441a67 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -1,4 +1,4 @@ -{pkgs, ...}: { +{ pkgs, ... }: { imports = [ "/home/parth/dotfiles/nix/common/headless.nix" ]; @@ -23,13 +23,14 @@ systemd.services."getty@tty1".enable = false; services.github-runners.lockbook = { - enable = true; - name = "lockbook ci"; - extraLabels = [ "ci" ]; - tokenFile = "/home/parth/token"; - url = "https://github.com/lockbook/lockbook"; - extraPackages = with pkgs; [ - rustup - ]; + enable = true; + name = "lockbook ci"; + user = "parth"; + extraLabels = [ "ci" ]; + tokenFile = "/home/parth/token"; + url = "https://github.com/lockbook/lockbook"; + extraPackages = with pkgs; [ + rustup + ]; }; } From 2c7d701aeba79858dc39c7db0830ef579196ba82 Mon Sep 17 00:00:00 2001 From: parth Date: Wed, 4 Dec 2024 23:01:43 -0500 Subject: [PATCH 043/123] restore CI? --- nix/server.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nix/server.nix b/nix/server.nix index 7e8441a67..5a7cc562e 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -31,6 +31,7 @@ url = "https://github.com/lockbook/lockbook"; extraPackages = with pkgs; [ rustup + gcc ]; }; } From 3f2cd69fa81656cacef925212c887e8eed43826d Mon Sep 17 00:00:00 2001 From: parth Date: Wed, 4 Dec 2024 23:07:44 -0500 Subject: [PATCH 044/123] restore CI? --- nix/server.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nix/server.nix b/nix/server.nix index 5a7cc562e..bd90e3515 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -32,6 +32,7 @@ extraPackages = with pkgs; [ rustup gcc + gtk3 ]; }; } From bbbcba2808e69e90192bcf05d53a0c2a8e79e25c Mon Sep 17 00:00:00 2001 From: parth Date: Wed, 4 Dec 2024 23:14:50 -0500 Subject: [PATCH 045/123] restore CI? --- nix/server.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nix/server.nix b/nix/server.nix index bd90e3515..88bd90404 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -33,6 +33,7 @@ rustup gcc gtk3 + pkgconfig ]; }; } From 7c927374e7d1730730b9199446691566ee2dc712 Mon Sep 17 00:00:00 2001 From: parth Date: Wed, 4 Dec 2024 23:15:57 -0500 Subject: [PATCH 046/123] restore CI? --- nix/server.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/server.nix b/nix/server.nix index 88bd90404..efe7e4059 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -33,7 +33,7 @@ rustup gcc gtk3 - pkgconfig + pkg-config ]; }; } From 35ec0bf458c2587e2c2fc22a924a2e75637a2888 Mon Sep 17 00:00:00 2001 From: parth Date: Wed, 4 Dec 2024 23:21:10 -0500 Subject: [PATCH 047/123] restore CI? --- nix/server.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nix/server.nix b/nix/server.nix index efe7e4059..5f94cac1a 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -34,6 +34,9 @@ gcc gtk3 pkg-config + glib + gobject-introspection + gdk-pixbuf ]; }; } From 41d0ec8dfa3affadff3800dfd34c23b5877ac2bf Mon Sep 17 00:00:00 2001 From: parth Date: Wed, 4 Dec 2024 23:28:45 -0500 Subject: [PATCH 048/123] restore CI? --- nix/server.nix | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/nix/server.nix b/nix/server.nix index 5f94cac1a..ccb55478c 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -32,11 +32,15 @@ extraPackages = with pkgs; [ rustup gcc - gtk3 - pkg-config - glib - gobject-introspection - gdk-pixbuf ]; }; + + environment.systemPackages = with pkgs; [ + gtk3 + pkg-config + glib + gobject-introspection + gdk-pixbuf + ]; + } From 1095a0e3f7e1b0ad2cf42cc8ff3a3ce695c306aa Mon Sep 17 00:00:00 2001 From: parth Date: Wed, 4 Dec 2024 23:53:54 -0500 Subject: [PATCH 049/123] restore CI? --- nix/server.nix | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/nix/server.nix b/nix/server.nix index ccb55478c..29c8c98f3 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -32,15 +32,16 @@ extraPackages = with pkgs; [ rustup gcc - ]; - }; - environment.systemPackages = with pkgs; [ - gtk3 - pkg-config - glib - gobject-introspection - gdk-pixbuf - ]; + pkg-config + gtk3 + glib + gobject-introspection + gdk-pixbuf + ]; + extraEnvironment = { + PKG_CONFIG_PATH = "${pkgs.gtk3.dev}/lib/pkgconfig:${pkgs.glib.dev}/lib/pkgconfig"; + }; + }; } From 01b3bc4c8f77f51777270dc8dcae87fe164ee130 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 11:04:49 -0500 Subject: [PATCH 050/123] restore CI? --- nix/server.nix | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/nix/server.nix b/nix/server.nix index 29c8c98f3..9dcbcd8c0 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -32,16 +32,15 @@ extraPackages = with pkgs; [ rustup gcc - - pkg-config - gtk3 - glib - gobject-introspection - gdk-pixbuf ]; - - extraEnvironment = { - PKG_CONFIG_PATH = "${pkgs.gtk3.dev}/lib/pkgconfig:${pkgs.glib.dev}/lib/pkgconfig"; - }; }; + + environment.systemPackages = with pkgs; [ + pkg-config + gtk3 + glib + gobject-introspection + gdk-pixbuf + ]; + } From ccb3c386b13919e13aa6bc5df6f5408018022be3 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 11:21:59 -0500 Subject: [PATCH 051/123] restore CI? --- nix/server.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nix/server.nix b/nix/server.nix index 9dcbcd8c0..6ebc54dc0 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -33,6 +33,9 @@ rustup gcc ]; + extraEnvironment = { + PKG_CONFIG_PATH = "${pkgs.gtk3.dev}/lib/pkgconfig:${pkgs.glib.dev}/lib/pkgconfig"; + }; }; environment.systemPackages = with pkgs; [ From 2aa33981ebb2652322a5abb2b00cf561c0e4ee80 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 11:29:43 -0500 Subject: [PATCH 052/123] restore CI? --- nix/server.nix | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/nix/server.nix b/nix/server.nix index 6ebc54dc0..bcec43346 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -32,18 +32,20 @@ extraPackages = with pkgs; [ rustup gcc + pkg-config + gtk3 + glib + gobject-introspection + gdk-pixbuf ]; extraEnvironment = { + PATH = "${pkgs.pkg-config}/bin:$PATH"; PKG_CONFIG_PATH = "${pkgs.gtk3.dev}/lib/pkgconfig:${pkgs.glib.dev}/lib/pkgconfig"; }; }; - environment.systemPackages = with pkgs; [ - pkg-config - gtk3 - glib - gobject-introspection - gdk-pixbuf - ]; + # environment.systemPackages = with pkgs; [ + + # ]; } From a3e02b3583551ef3d0adfb6a65826138dfc54686 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 13:51:45 -0500 Subject: [PATCH 053/123] restore CI? --- nix/server.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nix/server.nix b/nix/server.nix index bcec43346..aa810e429 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -38,8 +38,13 @@ gobject-introspection gdk-pixbuf ]; + serviceOverrides = { + ProtectSystem = "no"; + ProtectHome = "no"; + PrivateTmp = false; + PrivateDevices = false; + }; extraEnvironment = { - PATH = "${pkgs.pkg-config}/bin:$PATH"; PKG_CONFIG_PATH = "${pkgs.gtk3.dev}/lib/pkgconfig:${pkgs.glib.dev}/lib/pkgconfig"; }; }; From 850355e0caa8ed3ccddb136a57d344ac79337d6a Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 13:58:23 -0500 Subject: [PATCH 054/123] restore CI? --- nix/server.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nix/server.nix b/nix/server.nix index aa810e429..13b2f6fce 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -45,7 +45,13 @@ PrivateDevices = false; }; extraEnvironment = { - PKG_CONFIG_PATH = "${pkgs.gtk3.dev}/lib/pkgconfig:${pkgs.glib.dev}/lib/pkgconfig"; + PKG_CONFIG_PATH = concatStringsSep ":" [ + "${pkgs.gtk3.dev}/lib/pkgconfig" + "${pkgs.glib.dev}/lib/pkgconfig" + "${pkgs.gobject-introspection.dev}/lib/pkgconfig" + "${pkgs.gdk-pixbuf.dev}/lib/pkgconfig" + "${pkgs.atk.dev}/lib/pkgconfig" + ]; }; }; From e171a010b8d2a235a9fbae15a5f302d6d6350900 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 13:59:09 -0500 Subject: [PATCH 055/123] restore CI? --- nix/server.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/server.nix b/nix/server.nix index 13b2f6fce..08eb8c457 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: { +{ pkgs, concatStringsSep, ... }: { imports = [ "/home/parth/dotfiles/nix/common/headless.nix" ]; From f770a2343f65f2ad242596ab04511bec9aa358e4 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 14:00:54 -0500 Subject: [PATCH 056/123] restore CI? --- nix/server.nix | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/nix/server.nix b/nix/server.nix index 08eb8c457..894c001e2 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -1,4 +1,4 @@ -{ pkgs, concatStringsSep, ... }: { +{ pkgs, ... }: { imports = [ "/home/parth/dotfiles/nix/common/headless.nix" ]; @@ -45,13 +45,7 @@ PrivateDevices = false; }; extraEnvironment = { - PKG_CONFIG_PATH = concatStringsSep ":" [ - "${pkgs.gtk3.dev}/lib/pkgconfig" - "${pkgs.glib.dev}/lib/pkgconfig" - "${pkgs.gobject-introspection.dev}/lib/pkgconfig" - "${pkgs.gdk-pixbuf.dev}/lib/pkgconfig" - "${pkgs.atk.dev}/lib/pkgconfig" - ]; + PKG_CONFIG_PATH = "${pkgs.gtk3.dev}/lib/pkgconfig:${pkgs.glib.dev}/lib/pkgconfig:${pkgs.gobject-introspection.dev}/lib/pkgconfig:${pkgs.gdk-pixbuf.dev}/lib/pkgconfig:${pkgs.atk.dev}/lib/pkgconfig"; }; }; From 15129e8e14e60341e535c8f1bbbe21bdb378b902 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 15:44:55 -0500 Subject: [PATCH 057/123] restore CI? --- nix/server.nix | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/nix/server.nix b/nix/server.nix index 894c001e2..42ccc2907 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -32,11 +32,12 @@ extraPackages = with pkgs; [ rustup gcc - pkg-config - gtk3 - glib - gobject-introspection - gdk-pixbuf + ci-env + # pkg-config + # gtk3 + # glib + # gobject-introspection + # gdk-pixbuf ]; serviceOverrides = { ProtectSystem = "no"; @@ -44,13 +45,22 @@ PrivateTmp = false; PrivateDevices = false; }; - extraEnvironment = { - PKG_CONFIG_PATH = "${pkgs.gtk3.dev}/lib/pkgconfig:${pkgs.glib.dev}/lib/pkgconfig:${pkgs.gobject-introspection.dev}/lib/pkgconfig:${pkgs.gdk-pixbuf.dev}/lib/pkgconfig:${pkgs.atk.dev}/lib/pkgconfig"; - }; + # extraEnvironment = { + # PKG_CONFIG_PATH = "${pkgs.gtk3.dev}/lib/pkgconfig:${pkgs.glib.dev}/lib/pkgconfig:${pkgs.gobject-introspection.dev}/lib/pkgconfig:${pkgs.gdk-pixbuf.dev}/lib/pkgconfig:${pkgs.atk.dev}/lib/pkgconfig"; + # }; }; - # environment.systemPackages = with pkgs; [ - - # ]; - + environment.systemPackages = with pkgs; [ + (buildEnv { + name = "ci-env"; + paths = [ + pkg-config + gtk3 + glib + gobject-introspection + gdk-pixbuf + atk + ]; + }) + ]; } From 033d95ad0bcd2b7afba604cc61149cc891f38f39 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 15:46:58 -0500 Subject: [PATCH 058/123] restore CI? --- nix/server.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/nix/server.nix b/nix/server.nix index 42ccc2907..815f3f962 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -32,7 +32,6 @@ extraPackages = with pkgs; [ rustup gcc - ci-env # pkg-config # gtk3 # glib From 2e4767655b4b84b4110017e51a756bf9c0b4880a Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 16:51:10 -0500 Subject: [PATCH 059/123] restore CI? --- nix/server.nix | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/nix/server.nix b/nix/server.nix index 815f3f962..6c8002e26 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -32,11 +32,12 @@ extraPackages = with pkgs; [ rustup gcc - # pkg-config - # gtk3 - # glib - # gobject-introspection - # gdk-pixbuf + + pkg-config + gtk3 + glib + gobject-introspection + gdk-pixbuf ]; serviceOverrides = { ProtectSystem = "no"; @@ -44,22 +45,22 @@ PrivateTmp = false; PrivateDevices = false; }; - # extraEnvironment = { - # PKG_CONFIG_PATH = "${pkgs.gtk3.dev}/lib/pkgconfig:${pkgs.glib.dev}/lib/pkgconfig:${pkgs.gobject-introspection.dev}/lib/pkgconfig:${pkgs.gdk-pixbuf.dev}/lib/pkgconfig:${pkgs.atk.dev}/lib/pkgconfig"; - # }; + extraEnvironment = { + PKG_CONFIG_PATH = "${pkgs.gtk3.dev}/lib/pkgconfig:${pkgs.glib.dev}/lib/pkgconfig:${pkgs.gobject-introspection.dev}/lib/pkgconfig:${pkgs.gdk-pixbuf.dev}/lib/pkgconfig:${pkgs.atk.dev}/lib/pkgconfig"; + }; }; - environment.systemPackages = with pkgs; [ - (buildEnv { - name = "ci-env"; - paths = [ - pkg-config - gtk3 - glib - gobject-introspection - gdk-pixbuf - atk - ]; - }) - ]; + # environment.systemPackages = with pkgs; [ + # (buildEnv { + # name = "ci-env"; + # paths = [ + # pkg-config + # gtk3 + # glib + # gobject-introspection + # gdk-pixbuf + # atk + # ]; + # }) + # ]; } From 77424688f3f90646b64d38249b7986d8f06cdf40 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 16:55:25 -0500 Subject: [PATCH 060/123] restore CI? --- nix/server.nix | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/nix/server.nix b/nix/server.nix index 6c8002e26..431adf14b 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: { +{ pkgs, lib, ... }: { imports = [ "/home/parth/dotfiles/nix/common/headless.nix" ]; @@ -46,7 +46,58 @@ PrivateDevices = false; }; extraEnvironment = { - PKG_CONFIG_PATH = "${pkgs.gtk3.dev}/lib/pkgconfig:${pkgs.glib.dev}/lib/pkgconfig:${pkgs.gobject-introspection.dev}/lib/pkgconfig:${pkgs.gdk-pixbuf.dev}/lib/pkgconfig:${pkgs.atk.dev}/lib/pkgconfig"; + PKG_CONFIG_PATH = lib.makeSearchPath "pkgconfig" [ + pkgs.gtk3.dev + pkgs.at-spi2-core.dev + pkgs.dbus.dev + pkgs.expat.dev + pkgs.glib.dev + pkgs.zlib.dev + pkgs.libffi.dev + pkgs.cairo.dev + pkgs.fontconfig.dev + pkgs.freetype.dev + pkgs.bzip2.dev + pkgs.brotli.dev + pkgs.libpng-apng.dev + pkgs.pixman + pkgs.libXext.dev + pkgs.xorgproto + pkgs.libXau.dev + pkgs.libXrender.dev + pkgs.libX11.dev + pkgs.libxcb.dev + pkgs.fribidi.dev + pkgs.gdk-pixbuf.dev + pkgs.libtiff.dev + pkgs.libdeflate + pkgs.libjpeg-turbo.dev + pkgs.xz.dev + pkgs.gsettings-desktop-schemas + pkgs.libICE.dev + pkgs.libSM.dev + pkgs.libXcomposite.dev + pkgs.libXfixes.dev + pkgs.libXcursor.dev + pkgs.libXdamage.dev + pkgs.libXi.dev + pkgs.libXrandr.dev + pkgs.pango.dev + pkgs.harfbuzz.dev + pkgs.graphite2.dev + pkgs.libXft.dev + pkgs.libGL.dev + pkgs.libglvnd.dev + pkgs.wayland.dev + pkgs.wayland.bin + pkgs.wayland-protocols + pkgs.libXinerama.dev + pkgs.cups.dev + pkgs.gmp.dev + pkgs.gobject-introspection-wrapped.dev + pkgs.gobject-introspection.dev + ]; + # PKG_CONFIG_PATH = "${pkgs.gtk3.dev}/lib/pkgconfig:${pkgs.glib.dev}/lib/pkgconfig:${pkgs.gobject-introspection.dev}/lib/pkgconfig:${pkgs.gdk-pixbuf.dev}/lib/pkgconfig:${pkgs.atk.dev}/lib/pkgconfig"; }; }; From 42b7ef9d37548d9e930aa40c23f9a70488b212bf Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 16:57:17 -0500 Subject: [PATCH 061/123] restore CI? --- nix/server.nix | 45 +-------------------------------------------- 1 file changed, 1 insertion(+), 44 deletions(-) diff --git a/nix/server.nix b/nix/server.nix index 431adf14b..9aa8fea44 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -48,53 +48,10 @@ extraEnvironment = { PKG_CONFIG_PATH = lib.makeSearchPath "pkgconfig" [ pkgs.gtk3.dev - pkgs.at-spi2-core.dev - pkgs.dbus.dev - pkgs.expat.dev pkgs.glib.dev - pkgs.zlib.dev - pkgs.libffi.dev - pkgs.cairo.dev - pkgs.fontconfig.dev - pkgs.freetype.dev - pkgs.bzip2.dev - pkgs.brotli.dev - pkgs.libpng-apng.dev - pkgs.pixman - pkgs.libXext.dev - pkgs.xorgproto - pkgs.libXau.dev - pkgs.libXrender.dev - pkgs.libX11.dev - pkgs.libxcb.dev - pkgs.fribidi.dev pkgs.gdk-pixbuf.dev - pkgs.libtiff.dev - pkgs.libdeflate - pkgs.libjpeg-turbo.dev - pkgs.xz.dev - pkgs.gsettings-desktop-schemas - pkgs.libICE.dev - pkgs.libSM.dev - pkgs.libXcomposite.dev - pkgs.libXfixes.dev - pkgs.libXcursor.dev - pkgs.libXdamage.dev - pkgs.libXi.dev - pkgs.libXrandr.dev pkgs.pango.dev - pkgs.harfbuzz.dev - pkgs.graphite2.dev - pkgs.libXft.dev - pkgs.libGL.dev - pkgs.libglvnd.dev - pkgs.wayland.dev - pkgs.wayland.bin - pkgs.wayland-protocols - pkgs.libXinerama.dev - pkgs.cups.dev - pkgs.gmp.dev - pkgs.gobject-introspection-wrapped.dev + # pkgs.gobject-introspection-wrapped.dev pkgs.gobject-introspection.dev ]; # PKG_CONFIG_PATH = "${pkgs.gtk3.dev}/lib/pkgconfig:${pkgs.glib.dev}/lib/pkgconfig:${pkgs.gobject-introspection.dev}/lib/pkgconfig:${pkgs.gdk-pixbuf.dev}/lib/pkgconfig:${pkgs.atk.dev}/lib/pkgconfig"; From 93b3c446c6cbed216b688d2f4e676eb5d8e60bb3 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 17:02:22 -0500 Subject: [PATCH 062/123] restore CI? --- nix/server.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nix/server.nix b/nix/server.nix index 9aa8fea44..3edf78fd7 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -51,7 +51,8 @@ pkgs.glib.dev pkgs.gdk-pixbuf.dev pkgs.pango.dev - # pkgs.gobject-introspection-wrapped.dev + pkgs.cairo.dev + pkgs.gobject-introspection-wrapped.dev pkgs.gobject-introspection.dev ]; # PKG_CONFIG_PATH = "${pkgs.gtk3.dev}/lib/pkgconfig:${pkgs.glib.dev}/lib/pkgconfig:${pkgs.gobject-introspection.dev}/lib/pkgconfig:${pkgs.gdk-pixbuf.dev}/lib/pkgconfig:${pkgs.atk.dev}/lib/pkgconfig"; From e35875497440d65df2f046e8f39e27317c8a9983 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 17:02:52 -0500 Subject: [PATCH 063/123] restore CI? --- nix/server.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/nix/server.nix b/nix/server.nix index 3edf78fd7..808e179c9 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -52,7 +52,6 @@ pkgs.gdk-pixbuf.dev pkgs.pango.dev pkgs.cairo.dev - pkgs.gobject-introspection-wrapped.dev pkgs.gobject-introspection.dev ]; # PKG_CONFIG_PATH = "${pkgs.gtk3.dev}/lib/pkgconfig:${pkgs.glib.dev}/lib/pkgconfig:${pkgs.gobject-introspection.dev}/lib/pkgconfig:${pkgs.gdk-pixbuf.dev}/lib/pkgconfig:${pkgs.atk.dev}/lib/pkgconfig"; From 7ed2be82845687c2790dac39d76cc250369f1e4f Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 17:06:32 -0500 Subject: [PATCH 064/123] restore CI? --- nix/server.nix | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/nix/server.nix b/nix/server.nix index 808e179c9..1e11a5ebd 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -46,15 +46,23 @@ PrivateDevices = false; }; extraEnvironment = { - PKG_CONFIG_PATH = lib.makeSearchPath "pkgconfig" [ - pkgs.gtk3.dev - pkgs.glib.dev - pkgs.gdk-pixbuf.dev - pkgs.pango.dev - pkgs.cairo.dev - pkgs.gobject-introspection.dev - ]; - # PKG_CONFIG_PATH = "${pkgs.gtk3.dev}/lib/pkgconfig:${pkgs.glib.dev}/lib/pkgconfig:${pkgs.gobject-introspection.dev}/lib/pkgconfig:${pkgs.gdk-pixbuf.dev}/lib/pkgconfig:${pkgs.atk.dev}/lib/pkgconfig"; + # PKG_CONFIG_PATH = lib.makeSearchPath "pkgconfig" [ + # pkgs.gtk3.dev + # pkgs.glib.dev + # pkgs.gdk-pixbuf.dev + # pkgs.pango.dev + # pkgs.cairo.dev + # pkgs.gobject-introspection.dev + # ]; + PKG_CONFIG_PATH = '' + ${pkgs.gtk3.dev}/lib/pkgconfig: + ${pkgs.glib.dev}/lib/pkgconfig: + ${pkgs.gobject-introspection.dev}/lib/pkgconfig: + ${pkgs.gdk-pixbuf.dev}/lib/pkgconfig: + ${pkgs.atk.dev}/lib/pkgconfig + ${pkgs.cairo.dev}/lib/pkgconfig + ${pkgs.pango.dev}/lib/pkgconfig + ''; }; }; From 79d7674ce1a6e215205735b7b2888dae1e4b0784 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 17:18:45 -0500 Subject: [PATCH 065/123] restore CI? --- nix/server.nix | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/nix/server.nix b/nix/server.nix index 1e11a5ebd..56e266d70 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -55,13 +55,13 @@ # pkgs.gobject-introspection.dev # ]; PKG_CONFIG_PATH = '' - ${pkgs.gtk3.dev}/lib/pkgconfig: - ${pkgs.glib.dev}/lib/pkgconfig: - ${pkgs.gobject-introspection.dev}/lib/pkgconfig: - ${pkgs.gdk-pixbuf.dev}/lib/pkgconfig: - ${pkgs.atk.dev}/lib/pkgconfig - ${pkgs.cairo.dev}/lib/pkgconfig - ${pkgs.pango.dev}/lib/pkgconfig + ${pkgs.gtk3.dev}/lib/pkgconfig:\ + ${pkgs.glib.dev}/lib/pkgconfig:\ + ${pkgs.gobject-introspection.dev}/lib/pkgconfig:\ + ${pkgs.gdk-pixbuf.dev}/lib/pkgconfig:\ + ${pkgs.atk.dev}/lib/pkgconfig:\ + ${pkgs.cairo.dev}/lib/pkgconfig:\ + ${pkgs.pango.dev}/lib/pkgconfig:\ ''; }; }; From 8b8fb9b6705abc2781952ea87aa9eb703a396654 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 17:22:19 -0500 Subject: [PATCH 066/123] restore CI? --- nix/server.nix | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/nix/server.nix b/nix/server.nix index 56e266d70..0ba44ab67 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -55,13 +55,7 @@ # pkgs.gobject-introspection.dev # ]; PKG_CONFIG_PATH = '' - ${pkgs.gtk3.dev}/lib/pkgconfig:\ - ${pkgs.glib.dev}/lib/pkgconfig:\ - ${pkgs.gobject-introspection.dev}/lib/pkgconfig:\ - ${pkgs.gdk-pixbuf.dev}/lib/pkgconfig:\ - ${pkgs.atk.dev}/lib/pkgconfig:\ - ${pkgs.cairo.dev}/lib/pkgconfig:\ - ${pkgs.pango.dev}/lib/pkgconfig:\ + ${pkgs.gtk3.dev}/lib/pkgconfig:${pkgs.glib.dev}/lib/pkgconfig:${pkgs.gobject-introspection.dev}/lib/pkgconfig:${pkgs.gdk-pixbuf.dev}/lib/pkgconfig:${pkgs.atk.dev}/lib/pkgconfig:${pkgs.cairo.dev}/lib/pkgconfig:${pkgs.pango.dev}/lib/pkgconfig ''; }; }; From 9db4d6934e4ccba4d4d6a179cf0f5484b1ca752e Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 17:28:03 -0500 Subject: [PATCH 067/123] restore CI? --- nix/server.nix | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/nix/server.nix b/nix/server.nix index 0ba44ab67..0acd4ac81 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -38,6 +38,7 @@ glib gobject-introspection gdk-pixbuf + pango ]; serviceOverrides = { ProtectSystem = "no"; @@ -46,17 +47,16 @@ PrivateDevices = false; }; extraEnvironment = { - # PKG_CONFIG_PATH = lib.makeSearchPath "pkgconfig" [ - # pkgs.gtk3.dev - # pkgs.glib.dev - # pkgs.gdk-pixbuf.dev - # pkgs.pango.dev - # pkgs.cairo.dev - # pkgs.gobject-introspection.dev - # ]; - PKG_CONFIG_PATH = '' - ${pkgs.gtk3.dev}/lib/pkgconfig:${pkgs.glib.dev}/lib/pkgconfig:${pkgs.gobject-introspection.dev}/lib/pkgconfig:${pkgs.gdk-pixbuf.dev}/lib/pkgconfig:${pkgs.atk.dev}/lib/pkgconfig:${pkgs.cairo.dev}/lib/pkgconfig:${pkgs.pango.dev}/lib/pkgconfig - ''; + PKG_CONFIG_PATH = lib.makeSearchPath "pkgconfig" [ + pkgs.gtk3.dev + pkgs.gdk3.dev + pkgs.glib.dev + pkgs.gdk-pixbuf.dev + pkgs.atk.dev + pkgs.pango.dev + pkgs.cairo.dev + pkgs.gobject-introspection.dev + ]; }; }; From 49abe492dee3d564f9fe3e14f3c6cd76db3f1396 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 17:28:45 -0500 Subject: [PATCH 068/123] restore CI? --- nix/server.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/nix/server.nix b/nix/server.nix index 0acd4ac81..b0f0b6d74 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -49,7 +49,6 @@ extraEnvironment = { PKG_CONFIG_PATH = lib.makeSearchPath "pkgconfig" [ pkgs.gtk3.dev - pkgs.gdk3.dev pkgs.glib.dev pkgs.gdk-pixbuf.dev pkgs.atk.dev From e1310479ce899199980afdce4e7ba681debbe4ef Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 17:32:00 -0500 Subject: [PATCH 069/123] restore CI? --- nix/server.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nix/server.nix b/nix/server.nix index b0f0b6d74..cf2c3a323 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -39,6 +39,7 @@ gobject-introspection gdk-pixbuf pango + cairo ]; serviceOverrides = { ProtectSystem = "no"; From f5abedcb9164f54d0eddfc990f40c1f73e3a4dbd Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 17:36:27 -0500 Subject: [PATCH 070/123] restore CI? --- nix/server.nix | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/nix/server.nix b/nix/server.nix index cf2c3a323..c7d7e37eb 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -33,13 +33,13 @@ rustup gcc - pkg-config - gtk3 - glib - gobject-introspection - gdk-pixbuf - pango - cairo + # pkg-config + # gtk3 + # glib + # gobject-introspection + # gdk-pixbuf + # pango + # cairo ]; serviceOverrides = { ProtectSystem = "no"; @@ -48,15 +48,16 @@ PrivateDevices = false; }; extraEnvironment = { - PKG_CONFIG_PATH = lib.makeSearchPath "pkgconfig" [ - pkgs.gtk3.dev - pkgs.glib.dev - pkgs.gdk-pixbuf.dev - pkgs.atk.dev - pkgs.pango.dev - pkgs.cairo.dev - pkgs.gobject-introspection.dev - ]; + NIX_PATH = "/nix/var/nix/profiles/per-user/root/channels/nixos"; + # PKG_CONFIG_PATH = lib.makeSearchPath "pkgconfig" [ + # pkgs.gtk3.dev + # pkgs.glib.dev + # pkgs.gdk-pixbuf.dev + # pkgs.atk.dev + # pkgs.pango.dev + # pkgs.cairo.dev + # pkgs.gobject-introspection.dev + # ]; }; }; From 88e009923d2fbe11f6d3fee1187e3b189a326338 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 17:47:03 -0500 Subject: [PATCH 071/123] restore CI? --- nix/server.nix | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/nix/server.nix b/nix/server.nix index c7d7e37eb..9f68b0d74 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -32,14 +32,7 @@ extraPackages = with pkgs; [ rustup gcc - - # pkg-config - # gtk3 - # glib - # gobject-introspection - # gdk-pixbuf - # pango - # cairo + libxkbcommon ]; serviceOverrides = { ProtectSystem = "no"; @@ -49,29 +42,6 @@ }; extraEnvironment = { NIX_PATH = "/nix/var/nix/profiles/per-user/root/channels/nixos"; - # PKG_CONFIG_PATH = lib.makeSearchPath "pkgconfig" [ - # pkgs.gtk3.dev - # pkgs.glib.dev - # pkgs.gdk-pixbuf.dev - # pkgs.atk.dev - # pkgs.pango.dev - # pkgs.cairo.dev - # pkgs.gobject-introspection.dev - # ]; }; }; - - # environment.systemPackages = with pkgs; [ - # (buildEnv { - # name = "ci-env"; - # paths = [ - # pkg-config - # gtk3 - # glib - # gobject-introspection - # gdk-pixbuf - # atk - # ]; - # }) - # ]; } From 96f02c693bc739cdeebc950a4676c3b7bc8f3fb8 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 17:55:03 -0500 Subject: [PATCH 072/123] restore CI? --- nix/server.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nix/server.nix b/nix/server.nix index 9f68b0d74..a783728d4 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -32,7 +32,7 @@ extraPackages = with pkgs; [ rustup gcc - libxkbcommon + xkbcommon ]; serviceOverrides = { ProtectSystem = "no"; @@ -42,6 +42,7 @@ }; extraEnvironment = { NIX_PATH = "/nix/var/nix/profiles/per-user/root/channels/nixos"; + # LIBRARY_PATH = "${pkgs.xkbcommon}/lib"; }; }; } From 9c349f9bddbe907dc879082f15fae74d40fd8ab4 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 17:55:35 -0500 Subject: [PATCH 073/123] restore CI? --- nix/server.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nix/server.nix b/nix/server.nix index a783728d4..4350599a4 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -32,7 +32,7 @@ extraPackages = with pkgs; [ rustup gcc - xkbcommon + libxkbcommon ]; serviceOverrides = { ProtectSystem = "no"; @@ -42,7 +42,7 @@ }; extraEnvironment = { NIX_PATH = "/nix/var/nix/profiles/per-user/root/channels/nixos"; - # LIBRARY_PATH = "${pkgs.xkbcommon}/lib"; + LIBRARY_PATH = "${pkgs.libxkbcommon}/lib"; }; }; } From d19c916ffe6ce023ae54c4930c36a7466610bd9d Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 18:02:50 -0500 Subject: [PATCH 074/123] restore CI? --- nix/server.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nix/server.nix b/nix/server.nix index 4350599a4..31e0ef982 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -32,6 +32,7 @@ extraPackages = with pkgs; [ rustup gcc + psmisc libxkbcommon ]; serviceOverrides = { From b991c41128ec32f6668a33f9ef6827c485bc05e9 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 5 Dec 2024 18:20:48 -0500 Subject: [PATCH 075/123] restore CI! --- nix/server.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/server.nix b/nix/server.nix index 31e0ef982..3c706f869 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -1,4 +1,4 @@ -{ pkgs, lib, ... }: { +{ pkgs, ... }: { imports = [ "/home/parth/dotfiles/nix/common/headless.nix" ]; From c9350589f49e50a22dcdbddb530cfb9815286472 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 12 Dec 2024 21:46:39 -0500 Subject: [PATCH 076/123] ensure certain repos are always present on my systems --- nix/common/headless.nix | 28 +++++++++++++++++++++++++++- utils/fix-ssh.sh | 5 +++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100755 utils/fix-ssh.sh diff --git a/nix/common/headless.nix b/nix/common/headless.nix index 82f68a0be..36054fe1e 100644 --- a/nix/common/headless.nix +++ b/nix/common/headless.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: +{ pkgs, lib, ... }: let home-manager = builtins.fetchTarball "https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz"; @@ -83,6 +83,30 @@ in recursive = true; }; }; + + home.activation.cloneLockbook = lib.mkAfter '' + #!/usr/bin/env bash + + if [ ! -d $HOME/Documents/lockbook/lockbook ]; then + mkdir -p $HOME/Documents/lockbook/; + cd $HOME/Documents/lockbook && git clone git@github.com:lockbook/lockbook.git + fi + + if [ ! -d $HOME/Documents/lockbook/nixpkgs ]; then + mkdir -p $HOME/Documents/lockbook/; + cd $HOME/Documents/lockbook && git clone git@github.com:lockbook/nixpkgs.git + fi + + if [ ! -d $HOME/Documents/lockbook/db-rs ]; then + mkdir -p $HOME/Documents/lockbook/; + cd $HOME/Documents/lockbook && git clone git@github.com:lockbook/db-rs.git + fi + + if [ ! -d $HOME/Documents/lockbook/cli-rs ]; then + mkdir -p $HOME/Documents/lockbook/; + cd $HOME/Documents/lockbook && git clone git@github.com:lockbook/cli-rs.git + fi + ''; }; users.users.parth = { @@ -96,6 +120,8 @@ in ripgrep clang + samba + # move these to neovim specific area rust-analyzer rustup diff --git a/utils/fix-ssh.sh b/utils/fix-ssh.sh new file mode 100755 index 000000000..9da230246 --- /dev/null +++ b/utils/fix-ssh.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +chmod 700 $HOME/.ssh +chmod 644 $HOME/.ssh/id_rsa.pub +chmod 600 $HOME/.ssh/id_rsa From 74d90d14a32cd9a2490d02c235e1c8fa67383a27 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 12 Dec 2024 21:50:34 -0500 Subject: [PATCH 077/123] repos + tracing-gcp --- nix/common/headless.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nix/common/headless.nix b/nix/common/headless.nix index 36054fe1e..fabf476c2 100644 --- a/nix/common/headless.nix +++ b/nix/common/headless.nix @@ -106,6 +106,11 @@ in mkdir -p $HOME/Documents/lockbook/; cd $HOME/Documents/lockbook && git clone git@github.com:lockbook/cli-rs.git fi + + if [ ! -d $HOME/Documents/lockbook/tracing-gcp ]; then + mkdir -p $HOME/Documents/lockbook/; + cd $HOME/Documents/lockbook && git clone git@github.com:lockbook/tracing-gcp.git + fi ''; }; From 96e76bd66296830972432b6552424a09325877c9 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 12 Dec 2024 22:28:50 -0500 Subject: [PATCH 078/123] caps lock? --- nix/common/gui.nix | 3 +++ nix/common/headless.nix | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/nix/common/gui.nix b/nix/common/gui.nix index 463d51991..dc58eaae5 100644 --- a/nix/common/gui.nix +++ b/nix/common/gui.nix @@ -5,6 +5,9 @@ services.xserver.desktopManager.gnome.enable = true; services.xserver.displayManager.autoLogin.enable = true; services.xserver.displayManager.autoLogin.user = "parth"; + services.xserver = { + xkb.options = "caps:escape"; + }; services.xserver.xkb = { layout = "us"; diff --git a/nix/common/headless.nix b/nix/common/headless.nix index fabf476c2..40361e55c 100644 --- a/nix/common/headless.nix +++ b/nix/common/headless.nix @@ -112,6 +112,10 @@ in cd $HOME/Documents/lockbook && git clone git@github.com:lockbook/tracing-gcp.git fi ''; + + home.sessionPath = [ + "$HOME/.cargo/bin" + ]; }; users.users.parth = { From 8f8514c1a5dd198f33d354aceef27c1bf5647062 Mon Sep 17 00:00:00 2001 From: parth Date: Wed, 9 Apr 2025 22:21:46 -0400 Subject: [PATCH 079/123] start of macbook config --- nix/apply-macbook.sh | 3 ++ nix/macbook.nix | 85 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100755 nix/apply-macbook.sh create mode 100644 nix/macbook.nix diff --git a/nix/apply-macbook.sh b/nix/apply-macbook.sh new file mode 100755 index 000000000..8f7caf332 --- /dev/null +++ b/nix/apply-macbook.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +rm -rf /etc/nix-darwin/flake.nix && cp $HOME/dotfiles/nix/macbook.nix /etc/nix-darwin/flake.nix && sudo nix run nix-darwin/master#darwin-rebuild -- switch diff --git a/nix/macbook.nix b/nix/macbook.nix new file mode 100644 index 000000000..e8f370384 --- /dev/null +++ b/nix/macbook.nix @@ -0,0 +1,85 @@ + +{ + description = "Example nix-darwin system flake"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + nix-darwin.url = "github:nix-darwin/nix-darwin/master"; + nix-darwin.inputs.nixpkgs.follows = "nixpkgs"; + home-manager.url = "github:nix-community/home-manager"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = + inputs@{ + self, + nix-darwin, + nixpkgs, + home-manager, + }: + let + configuration = + { pkgs, ... }: + { + # List packages installed in system profile. To search by name, run: + # $ nix-env -qaP | grep wget + environment.systemPackages = [ + pkgs.vim + ]; + + # Necessary for using flakes on this system. + nix.settings.experimental-features = "nix-command flakes"; + + # Enable alternative shell support in nix-darwin. + # programs.fish.enable = true; + + # Set Git commit hash for darwin-version. + system.configurationRevision = self.rev or self.dirtyRev or null; + + # Used for backwards compatibility, please read the changelog before changing. + # $ darwin-rebuild changelog + system.stateVersion = 6; + + # The platform the configuration will be used on. + nixpkgs.hostPlatform = "aarch64-darwin"; + + programs.fish = { + enable = true; + shellInit = '' + fish_vi_key_bindings + ''; + }; + + users.users.parth = { + home = "/Users/parth"; + shell = pkgs.fish; + }; + }; + in + { + # Build darwin flake using: + # $ darwin-rebuild build --flake .#simple + darwinConfigurations."parth-macbook" = nix-darwin.lib.darwinSystem { + modules = [ + configuration + + home-manager.darwinModules.home-manager + { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.users.parth = { pkgs, ...}: { + home.stateVersion = "24.05"; + +programs.git = { + enable = true; + userName = "parth"; + userEmail = "parth@mehrotra.me"; + }; + + # + }; + } + ]; + }; + }; +} From 9b0d4f44d307bff674df6117cb977f88198c072a Mon Sep 17 00:00:00 2001 From: parth Date: Wed, 9 Apr 2025 23:00:58 -0400 Subject: [PATCH 080/123] some bare bones macos setup is done --- nix/apply-macbook.sh | 2 +- nix/macbook.nix | 93 +++++++++++++++++++++++++++++++++---------- nvim/lua/packages.lua | 6 ++- 3 files changed, 77 insertions(+), 24 deletions(-) diff --git a/nix/apply-macbook.sh b/nix/apply-macbook.sh index 8f7caf332..2265af9b7 100755 --- a/nix/apply-macbook.sh +++ b/nix/apply-macbook.sh @@ -1,3 +1,3 @@ #!/bin/sh -rm -rf /etc/nix-darwin/flake.nix && cp $HOME/dotfiles/nix/macbook.nix /etc/nix-darwin/flake.nix && sudo nix run nix-darwin/master#darwin-rebuild -- switch +rm -rf /etc/nix-darwin/flake.nix && cp $HOME/dotfiles/nix/macbook.nix /etc/nix-darwin/flake.nix && nix run nix-darwin/master#darwin-rebuild -- switch --impure diff --git a/nix/macbook.nix b/nix/macbook.nix index e8f370384..d61578b84 100644 --- a/nix/macbook.nix +++ b/nix/macbook.nix @@ -1,4 +1,3 @@ - { description = "Example nix-darwin system flake"; @@ -11,11 +10,11 @@ }; outputs = - inputs@{ - self, - nix-darwin, - nixpkgs, - home-manager, + inputs@{ self + , nix-darwin + , nixpkgs + , home-manager + , }: let configuration = @@ -23,15 +22,27 @@ { # List packages installed in system profile. To search by name, run: # $ nix-env -qaP | grep wget - environment.systemPackages = [ - pkgs.vim + environment.systemPackages = with pkgs; [ + fzf + xclip + + ripgrep + clang + + samba + + # move these to neovim specific area + rust-analyzer + rustup + + nixd + + nixpkgs-fmt ]; # Necessary for using flakes on this system. nix.settings.experimental-features = "nix-command flakes"; - # Enable alternative shell support in nix-darwin. - # programs.fish.enable = true; # Set Git commit hash for darwin-version. system.configurationRevision = self.rev or self.dirtyRev or null; @@ -50,10 +61,13 @@ ''; }; + users.knownUsers = [ "parth" ]; + users.users.parth.uid = 501; + users.users.parth = { - home = "/Users/parth"; - shell = pkgs.fish; - }; + home = "/Users/parth"; + shell = pkgs.fish; + }; }; in { @@ -67,17 +81,52 @@ { home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; - home-manager.users.parth = { pkgs, ...}: { - home.stateVersion = "24.05"; + home-manager.users.parth = { pkgs, ... }: { + home.stateVersion = "24.05"; -programs.git = { - enable = true; - userName = "parth"; - userEmail = "parth@mehrotra.me"; - }; + programs.git = { + enable = true; + userName = "parth"; + userEmail = "parth@mehrotra.me"; + }; + + programs.neovim = { + enable = true; + plugins = with pkgs.vimPlugins; [ + nvim-web-devicons + telescope-nvim + nvim-cmp + cmp-nvim-lsp + vim-illuminate + lualine-nvim + lsp-status-nvim + nvim-tree-lua + nvim-lspconfig + luasnip + # todo replace "FabijanZulj/blame.nvim", + ]; + + extraPackages = with pkgs; [ + lua-language-server + # i would like to configure this here but rustup does some wack shit + # rust-analyzer + ]; + + # extraLuaConfig = '' + # dofile("/home/parth/dotfiles/nvim/init.lua") + # ''; + }; - # - }; + + + xdg.configFile = { + "nvim" = { + source = /Users/parth/dotfiles/nvim; + recursive = true; + }; + }; + + }; } ]; }; diff --git a/nvim/lua/packages.lua b/nvim/lua/packages.lua index f9086827c..a61bfedf7 100644 --- a/nvim/lua/packages.lua +++ b/nvim/lua/packages.lua @@ -97,7 +97,11 @@ lspconfig.lua_ls.setup { }, }, } -lspconfig.nixd.setup {} +lspconfig.nixd.setup { + formatters_by_ft = { + nix = { "nixpkgs_fmt" }, + }, +} -- blame -- require("blame").setup() From e07150ae48ed419d8b645a2fc26c364e6a3c5480 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 10 Apr 2025 11:41:15 -0400 Subject: [PATCH 081/123] fonts --- nix/macbook.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nix/macbook.nix b/nix/macbook.nix index d61578b84..b83a768df 100644 --- a/nix/macbook.nix +++ b/nix/macbook.nix @@ -40,6 +40,10 @@ nixpkgs-fmt ]; + fonts.packages = with pkgs; [ + nerd-fonts.jetbrains-mono + + ]; # Necessary for using flakes on this system. nix.settings.experimental-features = "nix-command flakes"; From 32835f8356164a6827d762a3f02eaf249519caec Mon Sep 17 00:00:00 2001 From: parth Date: Sat, 26 Apr 2025 19:57:17 -0400 Subject: [PATCH 082/123] +aerospace +helix --- nix/common/headless.nix | 4 --- nix/macbook.nix | 58 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/nix/common/headless.nix b/nix/common/headless.nix index 40361e55c..46b8e7771 100644 --- a/nix/common/headless.nix +++ b/nix/common/headless.nix @@ -139,11 +139,7 @@ in ]; }; - - programs.git.enable = true; - nixpkgs.config.allowUnfree = true; - system.stateVersion = "24.05"; } diff --git a/nix/macbook.nix b/nix/macbook.nix index b83a768df..6d850b3d5 100644 --- a/nix/macbook.nix +++ b/nix/macbook.nix @@ -7,6 +7,7 @@ nix-darwin.inputs.nixpkgs.follows = "nixpkgs"; home-manager.url = "github:nix-community/home-manager"; home-manager.inputs.nixpkgs.follows = "nixpkgs"; + nix-homebrew.url = "github:zhaofengli-wip/nix-homebrew"; }; outputs = @@ -14,6 +15,7 @@ , nix-darwin , nixpkgs , home-manager + , nix-homebrew , }: let @@ -22,12 +24,15 @@ { # List packages installed in system profile. To search by name, run: # $ nix-env -qaP | grep wget + + nixpkgs.config.allowUnfree = true; + homebrew.enable = true; + environment.systemPackages = with pkgs; [ fzf xclip ripgrep - clang samba @@ -35,9 +40,14 @@ rust-analyzer rustup + # listing clang here makes the macOS clang act strange + nixd nixpkgs-fmt + + helix + ]; fonts.packages = with pkgs; [ @@ -65,6 +75,7 @@ ''; }; + users.knownUsers = [ "parth" ]; users.users.parth.uid = 501; @@ -72,6 +83,12 @@ home = "/Users/parth"; shell = pkgs.fish; }; + + system.keyboard = { + enableKeyMapping = true; + remapCapsLockToEscape = true; + }; + }; in { @@ -81,11 +98,39 @@ modules = [ configuration + nix-homebrew.darwinModules.nix-homebrew + { + nix-homebrew = { + enable = true; + user = "parth"; + }; + + homebrew = { + enable = true; + + masApps = { + "XCode" = 497799835; + # "Final Cut Pro" = 424389933; + "Lockbook" = 1526775001; + # 1password + }; + + casks = [ + "alacritty" + "google-chrome" + "nikitabobko/tap/aerospace" + # discord + # ableton-live-standard + # spotify + ]; + }; + } + home-manager.darwinModules.home-manager { home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; - home-manager.users.parth = { pkgs, ... }: { + home-manager.users.parth = { pkgs, lib, ... }: { home.stateVersion = "24.05"; programs.git = { @@ -94,6 +139,7 @@ userEmail = "parth@mehrotra.me"; }; + programs.neovim = { enable = true; plugins = with pkgs.vimPlugins; [ @@ -104,6 +150,7 @@ vim-illuminate lualine-nvim lsp-status-nvim + nvim-tree-lua nvim-lspconfig luasnip @@ -124,12 +171,19 @@ xdg.configFile = { + "nvim" = { source = /Users/parth/dotfiles/nvim; recursive = true; }; }; + home.activation.removeAlacrittyQuarantine = lib.mkAfter '' + if [ -d /Applications/Alacritty.app ]; then + echo "Removing quarantine from Alacritty.app..." + /usr/bin/xattr -d -r com.apple.quarantine /Applications/Alacritty.app || true + fi + ''; }; } ]; From c63c2bb7635bcfa76fc51356475a12de3c83f20a Mon Sep 17 00:00:00 2001 From: parth Date: Sat, 26 Apr 2025 20:10:09 -0400 Subject: [PATCH 083/123] aerospace managed by nix --- nix/macbook.nix | 216 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 216 insertions(+) diff --git a/nix/macbook.nix b/nix/macbook.nix index 6d850b3d5..ef8da9b58 100644 --- a/nix/macbook.nix +++ b/nix/macbook.nix @@ -129,6 +129,7 @@ home-manager.darwinModules.home-manager { home-manager.useGlobalPkgs = true; + home-manager.backupFileExtension = "backup"; home-manager.useUserPackages = true; home-manager.users.parth = { pkgs, lib, ... }: { home.stateVersion = "24.05"; @@ -184,6 +185,221 @@ /usr/bin/xattr -d -r com.apple.quarantine /Applications/Alacritty.app || true fi ''; + + home.file.".aerospace.toml".text = '' + # Place a copy of this config to ~/.aerospace.toml + # After that, you can edit ~/.aerospace.toml to your liking + + # You can use it to add commands that run after login to macOS user session. + # 'start-at-login' needs to be 'true' for 'after-login-command' to work + # Available commands: https://nikitabobko.github.io/AeroSpace/commands + after-login-command = [] + + # You can use it to add commands that run after AeroSpace startup. + # 'after-startup-command' is run after 'after-login-command' + # Available commands : https://nikitabobko.github.io/AeroSpace/commands + after-startup-command = [] + + # Start AeroSpace at login + start-at-login = false + + # Normalizations. See: https://nikitabobko.github.io/AeroSpace/guide#normalization + enable-normalization-flatten-containers = true + enable-normalization-opposite-orientation-for-nested-containers = true + + # See: https://nikitabobko.github.io/AeroSpace/guide#layouts + # The 'accordion-padding' specifies the size of accordion padding + # You can set 0 to disable the padding feature + accordion-padding = 30 + + # Possible values: tiles|accordion + default-root-container-layout = 'tiles' + + # Possible values: horizontal|vertical|auto + # 'auto' means: wide monitor (anything wider than high) gets horizontal orientation, + # tall monitor (anything higher than wide) gets vertical orientation + default-root-container-orientation = 'auto' + + # Mouse follows focus when focused monitor changes + # Drop it from your config, if you don't like this behavior + # See https://nikitabobko.github.io/AeroSpace/guide#on-focus-changed-callbacks + # See https://nikitabobko.github.io/AeroSpace/commands#move-mouse + # Fallback value (if you omit the key): on-focused-monitor-changed = [] + on-focused-monitor-changed = ['move-mouse monitor-lazy-center'] + + # You can effectively turn off macOS "Hide application" (cmd-h) feature by toggling this flag + # Useful if you don't use this macOS feature, but accidentally hit cmd-h or cmd-alt-h key + # Also see: https://nikitabobko.github.io/AeroSpace/goodies#disable-hide-app + automatically-unhide-macos-hidden-apps = false + + # Possible values: (qwerty|dvorak|colemak) + # See https://nikitabobko.github.io/AeroSpace/guide#key-mapping + [key-mapping] + preset = 'qwerty' + + # Gaps between windows (inner-*) and between monitor edges (outer-*). + # Possible values: + # - Constant: gaps.outer.top = 8 + # - Per monitor: gaps.outer.top = [{ monitor.main = 16 }, { monitor."some-pattern" = 32 }, 24] + # In this example, 24 is a default value when there is no match. + # Monitor pattern is the same as for 'workspace-to-monitor-force-assignment'. + # See: + # https://nikitabobko.github.io/AeroSpace/guide#assign-workspaces-to-monitors + [gaps] + inner.horizontal = 0 + inner.vertical = 0 + outer.left = 0 + outer.bottom = 0 + outer.top = 0 + outer.right = 0 + + # 'main' binding mode declaration + # See: https://nikitabobko.github.io/AeroSpace/guide#binding-modes + # 'main' binding mode must be always presented + # Fallback value (if you omit the key): mode.main.binding = {} + [mode.main.binding] + + # All possible keys: + # - Letters. a, b, c, ..., z + # - Numbers. 0, 1, 2, ..., 9 + # - Keypad numbers. keypad0, keypad1, keypad2, ..., keypad9 + # - F-keys. f1, f2, ..., f20 + # - Special keys. minus, equal, period, comma, slash, backslash, quote, semicolon, + # backtick, leftSquareBracket, rightSquareBracket, space, enter, esc, + # backspace, tab, pageUp, pageDown, home, end, forwardDelete, + # sectionSign (ISO keyboards only, european keyboards only) + # - Keypad special. keypadClear, keypadDecimalMark, keypadDivide, keypadEnter, keypadEqual, + # keypadMinus, keypadMultiply, keypadPlus + # - Arrows. left, down, up, right + + # All possible modifiers: cmd, alt, ctrl, shift + + # All possible commands: https://nikitabobko.github.io/AeroSpace/commands + + # See: https://nikitabobko.github.io/AeroSpace/commands#exec-and-forget + # You can uncomment the following lines to open up terminal with alt + enter shortcut + # (like in i3) + # alt-enter = '''exec-and-forget osascript -e ' + # tell application "Terminal" + # do script + # activate + # end tell' + # ''' + + # See: https://nikitabobko.github.io/AeroSpace/commands#layout + alt-slash = 'layout tiles horizontal vertical' + alt-comma = 'layout accordion horizontal vertical' + + # See: https://nikitabobko.github.io/AeroSpace/commands#focus + alt-h = 'focus left' + alt-j = 'focus down' + alt-k = 'focus up' + alt-l = 'focus right' + + # See: https://nikitabobko.github.io/AeroSpace/commands#move + alt-shift-h = 'move left' + alt-shift-j = 'move down' + alt-shift-k = 'move up' + alt-shift-l = 'move right' + + # See: https://nikitabobko.github.io/AeroSpace/commands#resize + alt-minus = 'resize smart -50' + alt-equal = 'resize smart +50' + + # See: https://nikitabobko.github.io/AeroSpace/commands#workspace + alt-1 = 'workspace 1' + alt-2 = 'workspace 2' + alt-3 = 'workspace 3' + alt-4 = 'workspace 4' + alt-5 = 'workspace 5' + alt-6 = 'workspace 6' + alt-7 = 'workspace 7' + alt-8 = 'workspace 8' + alt-9 = 'workspace 9' + alt-a = 'workspace A' # In your config, you can drop workspace bindings that you don't need + alt-b = 'workspace B' + alt-c = 'workspace C' + alt-d = 'workspace D' + alt-e = 'workspace E' + alt-f = 'workspace F' + alt-g = 'workspace G' + alt-i = 'workspace I' + alt-m = 'workspace M' + alt-n = 'workspace N' + alt-o = 'workspace O' + alt-p = 'workspace P' + alt-q = 'workspace Q' + alt-r = 'workspace R' + alt-s = 'workspace S' + alt-t = 'workspace T' + alt-u = 'workspace U' + alt-v = 'workspace V' + alt-w = 'workspace W' + alt-x = 'workspace X' + alt-y = 'workspace Y' + alt-z = 'workspace Z' + + # See: https://nikitabobko.github.io/AeroSpace/commands#move-node-to-workspace + alt-shift-1 = 'move-node-to-workspace 1' + alt-shift-2 = 'move-node-to-workspace 2' + alt-shift-3 = 'move-node-to-workspace 3' + alt-shift-4 = 'move-node-to-workspace 4' + alt-shift-5 = 'move-node-to-workspace 5' + alt-shift-6 = 'move-node-to-workspace 6' + alt-shift-7 = 'move-node-to-workspace 7' + alt-shift-8 = 'move-node-to-workspace 8' + alt-shift-9 = 'move-node-to-workspace 9' + alt-shift-a = 'move-node-to-workspace A' + alt-shift-b = 'move-node-to-workspace B' + alt-shift-c = 'move-node-to-workspace C' + alt-shift-d = 'move-node-to-workspace D' + alt-shift-e = 'move-node-to-workspace E' + alt-shift-f = 'move-node-to-workspace F' + alt-shift-g = 'move-node-to-workspace G' + alt-shift-i = 'move-node-to-workspace I' + alt-shift-m = 'move-node-to-workspace M' + alt-shift-n = 'move-node-to-workspace N' + alt-shift-o = 'move-node-to-workspace O' + alt-shift-p = 'move-node-to-workspace P' + alt-shift-q = 'move-node-to-workspace Q' + alt-shift-r = 'move-node-to-workspace R' + alt-shift-s = 'move-node-to-workspace S' + alt-shift-t = 'move-node-to-workspace T' + alt-shift-u = 'move-node-to-workspace U' + alt-shift-v = 'move-node-to-workspace V' + alt-shift-w = 'move-node-to-workspace W' + alt-shift-x = 'move-node-to-workspace X' + alt-shift-y = 'move-node-to-workspace Y' + alt-shift-z = 'move-node-to-workspace Z' + + # See: https://nikitabobko.github.io/AeroSpace/commands#workspace-back-and-forth + alt-tab = 'workspace-back-and-forth' + # See: https://nikitabobko.github.io/AeroSpace/commands#move-workspace-to-monitor + alt-shift-tab = 'move-workspace-to-monitor --wrap-around next' + + # See: https://nikitabobko.github.io/AeroSpace/commands#mode + alt-shift-semicolon = 'mode service' + + # 'service' binding mode declaration. + # See: https://nikitabobko.github.io/AeroSpace/guide#binding-modes + [mode.service.binding] + esc = ['reload-config', 'mode main'] + r = ['flatten-workspace-tree', 'mode main'] # reset layout + f = ['layout floating tiling', 'mode main'] # Toggle between floating and tiling layout + backspace = ['close-all-windows-but-current', 'mode main'] + + # sticky is not yet supported https://github.com/nikitabobko/AeroSpace/issues/2 + #s = ['layout sticky tiling', 'mode main'] + + alt-shift-h = ['join-with left', 'mode main'] + alt-shift-j = ['join-with down', 'mode main'] + alt-shift-k = ['join-with up', 'mode main'] + alt-shift-l = ['join-with right', 'mode main'] + + down = 'volume down' + up = 'volume up' + shift-down = ['volume set 0', 'mode main'] + ''; }; } ]; From 6182950b63c26ae095be7b738be182677a47734f Mon Sep 17 00:00:00 2001 From: parth Date: Mon, 28 Apr 2025 14:23:21 -0400 Subject: [PATCH 084/123] minor accomplishments --- helix/config.toml | 4 ++++ helix/languages.toml | 4 ++++ nix/macbook.nix | 53 +++++++++++++++++--------------------------- 3 files changed, 28 insertions(+), 33 deletions(-) create mode 100644 helix/config.toml create mode 100644 helix/languages.toml diff --git a/helix/config.toml b/helix/config.toml new file mode 100644 index 000000000..faecdcc4f --- /dev/null +++ b/helix/config.toml @@ -0,0 +1,4 @@ +theme = "onedark" + +[editor.cursor-shape] +insert = "bar" diff --git a/helix/languages.toml b/helix/languages.toml new file mode 100644 index 000000000..780ec6c50 --- /dev/null +++ b/helix/languages.toml @@ -0,0 +1,4 @@ +[[language]] +name = "nix" +auto-format = true +formatter = { command = "nixpkgs-fmt" } diff --git a/nix/macbook.nix b/nix/macbook.nix index ef8da9b58..5abcf8a19 100644 --- a/nix/macbook.nix +++ b/nix/macbook.nix @@ -22,44 +22,29 @@ configuration = { pkgs, ... }: { - # List packages installed in system profile. To search by name, run: - # $ nix-env -qaP | grep wget - nixpkgs.config.allowUnfree = true; + nix.settings.experimental-features = "nix-command flakes"; homebrew.enable = true; - environment.systemPackages = with pkgs; [ - fzf - xclip + # Set Git commit hash for darwin-version. + system.configurationRevision = self.rev or self.dirtyRev or null; - ripgrep + environment.systemPackages = with pkgs; [ + helix - samba + fzf - # move these to neovim specific area + nixpkgs-fmt + nixd rust-analyzer rustup - # listing clang here makes the macOS clang act strange - - nixd - - nixpkgs-fmt - - helix - ]; fonts.packages = with pkgs; [ nerd-fonts.jetbrains-mono - ]; - # Necessary for using flakes on this system. - nix.settings.experimental-features = "nix-command flakes"; - - # Set Git commit hash for darwin-version. - system.configurationRevision = self.rev or self.dirtyRev or null; # Used for backwards compatibility, please read the changelog before changing. # $ darwin-rebuild changelog @@ -75,7 +60,6 @@ ''; }; - users.knownUsers = [ "parth" ]; users.users.parth.uid = 501; @@ -88,7 +72,6 @@ enableKeyMapping = true; remapCapsLockToEscape = true; }; - }; in { @@ -140,7 +123,6 @@ userEmail = "parth@mehrotra.me"; }; - programs.neovim = { enable = true; plugins = with pkgs.vimPlugins; [ @@ -172,11 +154,15 @@ xdg.configFile = { - "nvim" = { source = /Users/parth/dotfiles/nvim; recursive = true; }; + + "helix" = { + source = /Users/parth/dotfiles/helix; + recursive = true; + }; }; home.activation.removeAlacrittyQuarantine = lib.mkAfter '' @@ -246,12 +232,12 @@ # See: # https://nikitabobko.github.io/AeroSpace/guide#assign-workspaces-to-monitors [gaps] - inner.horizontal = 0 - inner.vertical = 0 - outer.left = 0 - outer.bottom = 0 - outer.top = 0 - outer.right = 0 + inner.horizontal = 6 + inner.vertical = 6 + outer.left = 6 + outer.bottom = 6 + outer.top = 6 + outer.right = 6 # 'main' binding mode declaration # See: https://nikitabobko.github.io/AeroSpace/guide#binding-modes @@ -403,6 +389,7 @@ }; } ]; + }; }; } From 5ad66b7130d208f034e65c27f64fe3650d187dc8 Mon Sep 17 00:00:00 2001 From: parth Date: Tue, 29 Apr 2025 16:32:27 -0400 Subject: [PATCH 085/123] welcome wezterm --- aerospace/aerospace.toml | 212 +++++++++++++++++++++++++++++++++++++++ helix/config.toml | 8 +- nix/macbook.nix | 20 ++-- wezterm/wezterm.lua | 73 ++++++++++++++ 4 files changed, 302 insertions(+), 11 deletions(-) create mode 100644 aerospace/aerospace.toml create mode 100644 wezterm/wezterm.lua diff --git a/aerospace/aerospace.toml b/aerospace/aerospace.toml new file mode 100644 index 000000000..0dbcedf7a --- /dev/null +++ b/aerospace/aerospace.toml @@ -0,0 +1,212 @@ +# Place a copy of this config to ~/.aerospace.toml +# After that, you can edit ~/.aerospace.toml to your liking + +# You can use it to add commands that run after login to macOS user session. +# 'start-at-login' needs to be 'true' for 'after-login-command' to work +# Available commands: https://nikitabobko.github.io/AeroSpace/commands +after-login-command = [] + +# You can use it to add commands that run after AeroSpace startup. +# 'after-startup-command' is run after 'after-login-command' +# Available commands : https://nikitabobko.github.io/AeroSpace/commands +after-startup-command = [] + +# Start AeroSpace at login +start-at-login = false + +# Normalizations. See: https://nikitabobko.github.io/AeroSpace/guide#normalization +enable-normalization-flatten-containers = true +enable-normalization-opposite-orientation-for-nested-containers = true + +# See: https://nikitabobko.github.io/AeroSpace/guide#layouts +# The 'accordion-padding' specifies the size of accordion padding +# You can set 0 to disable the padding feature +accordion-padding = 30 + +# Possible values: tiles|accordion +default-root-container-layout = 'tiles' + +# Possible values: horizontal|vertical|auto +# 'auto' means: wide monitor (anything wider than high) gets horizontal orientation, +# tall monitor (anything higher than wide) gets vertical orientation +default-root-container-orientation = 'auto' + +# Mouse follows focus when focused monitor changes +# Drop it from your config, if you don't like this behavior +# See https://nikitabobko.github.io/AeroSpace/guide#on-focus-changed-callbacks +# See https://nikitabobko.github.io/AeroSpace/commands#move-mouse +# Fallback value (if you omit the key): on-focused-monitor-changed = [] +on-focused-monitor-changed = ['move-mouse monitor-lazy-center'] + +# You can effectively turn off macOS "Hide application" (cmd-h) feature by toggling this flag +# Useful if you don't use this macOS feature, but accidentally hit cmd-h or cmd-alt-h key +# Also see: https://nikitabobko.github.io/AeroSpace/goodies#disable-hide-app +automatically-unhide-macos-hidden-apps = false + +# Possible values: (qwerty|dvorak|colemak) +# See https://nikitabobko.github.io/AeroSpace/guide#key-mapping +[key-mapping] + preset = 'qwerty' + +# Gaps between windows (inner-*) and between monitor edges (outer-*). +# Possible values: +# - Constant: gaps.outer.top = 8 +# - Per monitor: gaps.outer.top = [{ monitor.main = 16 }, { monitor."some-pattern" = 32 }, 24] +# In this example, 24 is a default value when there is no match. +# Monitor pattern is the same as for 'workspace-to-monitor-force-assignment'. +# See: +# https://nikitabobko.github.io/AeroSpace/guide#assign-workspaces-to-monitors +[gaps] + inner.horizontal = 0 + inner.vertical = 0 + outer.left = 0 + outer.bottom = 0 + outer.top = 0 + outer.right = 0 + +# 'main' binding mode declaration +# See: https://nikitabobko.github.io/AeroSpace/guide#binding-modes +# 'main' binding mode must be always presented +# Fallback value (if you omit the key): mode.main.binding = {} +[mode.main.binding] + + # All possible keys: + # - Letters. a, b, c, ..., z + # - Numbers. 0, 1, 2, ..., 9 + # - Keypad numbers. keypad0, keypad1, keypad2, ..., keypad9 + # - F-keys. f1, f2, ..., f20 + # - Special keys. minus, equal, period, comma, slash, backslash, quote, semicolon, + # backtick, leftSquareBracket, rightSquareBracket, space, enter, esc, + # backspace, tab, pageUp, pageDown, home, end, forwardDelete, + # sectionSign (ISO keyboards only, european keyboards only) + # - Keypad special. keypadClear, keypadDecimalMark, keypadDivide, keypadEnter, keypadEqual, + # keypadMinus, keypadMultiply, keypadPlus + # - Arrows. left, down, up, right + + # All possible modifiers: cmd, alt, ctrl, shift + + # All possible commands: https://nikitabobko.github.io/AeroSpace/commands + + # See: https://nikitabobko.github.io/AeroSpace/commands#exec-and-forget + # You can uncomment the following lines to open up terminal with alt + enter shortcut + # (like in i3) + # alt-enter = '''exec-and-forget osascript -e ' + # tell application "Terminal" + # do script + # activate + # end tell' + # ''' + + # See: https://nikitabobko.github.io/AeroSpace/commands#layout + alt-slash = 'layout tiles horizontal vertical' + alt-comma = 'layout accordion horizontal vertical' + + # See: https://nikitabobko.github.io/AeroSpace/commands#focus + alt-h = 'focus left' + alt-j = 'focus down' + alt-k = 'focus up' + alt-l = 'focus right' + + # See: https://nikitabobko.github.io/AeroSpace/commands#move + alt-shift-h = 'move left' + alt-shift-j = 'move down' + alt-shift-k = 'move up' + alt-shift-l = 'move right' + + # See: https://nikitabobko.github.io/AeroSpace/commands#resize + alt-minus = 'resize smart -50' + alt-equal = 'resize smart +50' + + # See: https://nikitabobko.github.io/AeroSpace/commands#workspace + alt-1 = 'workspace 1' + alt-2 = 'workspace 2' + alt-3 = 'workspace 3' + alt-4 = 'workspace 4' + alt-5 = 'workspace 5' + alt-6 = 'workspace 6' + alt-7 = 'workspace 7' + alt-8 = 'workspace 8' + alt-9 = 'workspace 9' + alt-a = 'workspace A' # In your config, you can drop workspace bindings that you don't need + alt-b = 'workspace B' + alt-c = 'workspace C' + alt-d = 'workspace D' + alt-e = 'workspace E' + alt-f = 'workspace F' + alt-g = 'workspace G' + alt-i = 'workspace I' + alt-m = 'workspace M' + alt-n = 'workspace N' + alt-o = 'workspace O' + alt-p = 'workspace P' + alt-q = 'workspace Q' + alt-r = 'workspace R' + alt-s = 'workspace S' + alt-t = 'workspace T' + alt-u = 'workspace U' + alt-v = 'workspace V' + alt-w = 'workspace W' + alt-x = 'workspace X' + alt-y = 'workspace Y' + alt-z = 'workspace Z' + + # See: https://nikitabobko.github.io/AeroSpace/commands#move-node-to-workspace + alt-shift-1 = 'move-node-to-workspace 1' + alt-shift-2 = 'move-node-to-workspace 2' + alt-shift-3 = 'move-node-to-workspace 3' + alt-shift-4 = 'move-node-to-workspace 4' + alt-shift-5 = 'move-node-to-workspace 5' + alt-shift-6 = 'move-node-to-workspace 6' + alt-shift-7 = 'move-node-to-workspace 7' + alt-shift-8 = 'move-node-to-workspace 8' + alt-shift-9 = 'move-node-to-workspace 9' + alt-shift-a = 'move-node-to-workspace A' + alt-shift-b = 'move-node-to-workspace B' + alt-shift-c = 'move-node-to-workspace C' + alt-shift-d = 'move-node-to-workspace D' + alt-shift-e = 'move-node-to-workspace E' + alt-shift-f = 'move-node-to-workspace F' + alt-shift-g = 'move-node-to-workspace G' + alt-shift-i = 'move-node-to-workspace I' + alt-shift-m = 'move-node-to-workspace M' + alt-shift-n = 'move-node-to-workspace N' + alt-shift-o = 'move-node-to-workspace O' + alt-shift-p = 'move-node-to-workspace P' + alt-shift-q = 'move-node-to-workspace Q' + alt-shift-r = 'move-node-to-workspace R' + alt-shift-s = 'move-node-to-workspace S' + alt-shift-t = 'move-node-to-workspace T' + alt-shift-u = 'move-node-to-workspace U' + alt-shift-v = 'move-node-to-workspace V' + alt-shift-w = 'move-node-to-workspace W' + alt-shift-x = 'move-node-to-workspace X' + alt-shift-y = 'move-node-to-workspace Y' + alt-shift-z = 'move-node-to-workspace Z' + + # See: https://nikitabobko.github.io/AeroSpace/commands#workspace-back-and-forth + alt-tab = 'workspace-back-and-forth' + # See: https://nikitabobko.github.io/AeroSpace/commands#move-workspace-to-monitor + alt-shift-tab = 'move-workspace-to-monitor --wrap-around next' + + # See: https://nikitabobko.github.io/AeroSpace/commands#mode + alt-shift-semicolon = 'mode service' + +# 'service' binding mode declaration. +# See: https://nikitabobko.github.io/AeroSpace/guide#binding-modes +[mode.service.binding] + esc = ['reload-config', 'mode main'] + r = ['flatten-workspace-tree', 'mode main'] # reset layout + f = ['layout floating tiling', 'mode main'] # Toggle between floating and tiling layout + backspace = ['close-all-windows-but-current', 'mode main'] + + # sticky is not yet supported https://github.com/nikitabobko/AeroSpace/issues/2 + #s = ['layout sticky tiling', 'mode main'] + + alt-shift-h = ['join-with left', 'mode main'] + alt-shift-j = ['join-with down', 'mode main'] + alt-shift-k = ['join-with up', 'mode main'] + alt-shift-l = ['join-with right', 'mode main'] + + down = 'volume down' + up = 'volume up' + shift-down = ['volume set 0', 'mode main'] diff --git a/helix/config.toml b/helix/config.toml index faecdcc4f..ab789026f 100644 --- a/helix/config.toml +++ b/helix/config.toml @@ -1,4 +1,6 @@ -theme = "onedark" +theme = "tokyonight" -[editor.cursor-shape] -insert = "bar" +[editor] +cursor-shape = { insert = "bar" } +cursorline = true +cursorcolumn = true diff --git a/nix/macbook.nix b/nix/macbook.nix index 5abcf8a19..bd88d1e2d 100644 --- a/nix/macbook.nix +++ b/nix/macbook.nix @@ -34,6 +34,7 @@ fzf + lua-language-server nixpkgs-fmt nixd rust-analyzer @@ -99,7 +100,7 @@ }; casks = [ - "alacritty" + "wezterm" "google-chrome" "nikitabobko/tap/aerospace" # discord @@ -163,14 +164,17 @@ source = /Users/parth/dotfiles/helix; recursive = true; }; - }; - home.activation.removeAlacrittyQuarantine = lib.mkAfter '' - if [ -d /Applications/Alacritty.app ]; then - echo "Removing quarantine from Alacritty.app..." - /usr/bin/xattr -d -r com.apple.quarantine /Applications/Alacritty.app || true - fi - ''; + "aerospace" = { + source = /Users/parth/dotfiles/aerospace; + recursive = true; + }; + + "wezterm" = { + source = /Users/parth/dotfiles/wezterm; + recursive = true; + }; + }; home.file.".aerospace.toml".text = '' # Place a copy of this config to ~/.aerospace.toml diff --git a/wezterm/wezterm.lua b/wezterm/wezterm.lua new file mode 100644 index 000000000..6587b1c6e --- /dev/null +++ b/wezterm/wezterm.lua @@ -0,0 +1,73 @@ +local wezterm = require 'wezterm' + +local config = wezterm.config_builder() + +config.enable_tab_bar = false + +config.window_padding = { + left = 0, + right = 0, + top = 0, + bottom = 0, +} +config.macos_window_background_blur = 100 +config.win32_system_backdrop = 'Acrylic' + +if wezterm.gui.get_appearance():find 'Dark' then + config.window_background_opacity = 0.5 + config.colors = { + ansi = { + '#505050', -- black + '#FF6680', -- red + '#67E4B6', -- green + '#FFDB70', -- yellow + '#66B2FF', -- blue + '#AC8CD9', -- magenta + '#6EECF7', -- cyan + '#D0D0D0', -- white + }, + brights = { + '#D0D0D0', -- brblack + '#FF99AA', -- brred + '#93ECCB', -- brgreen + '#FFE699', -- bryellow + '#80BFFF', -- brblue + '#BA9FDF', -- brmagenta + '#9EF2FA', -- brcyan + '#FFFFFF', -- brwhite + }, + + foreground = '#FFFFFF', + background = '#1A1A1A', + + } +else + config.colors = { + ansi = { + '#1A1A1A', -- black + '#DF2040', -- red + '#00B371', -- green + '#CC9900', -- yellow + '#207FDF', -- blue + '#7855AA', -- magenta + '#0FAEBD', -- cyan + '#D0D0D0', -- white + }, + brights = { + '#808080', -- brblack + '#FF6680', -- brred + '#2DD296', -- brgreen + '#FFBF00', -- bryellow + '#66B2FF', -- brblue + '#AC8CD9', -- brmagenta + '#13DAEC', -- brcyan + '#1A1A1A', -- brwhite + }, + + foreground = '#1A1A1A', + background = '#FFFFFF', + } +end + +return config + From 2cc06b73e57f7cb67f5d0d974507f470bc85fbbf Mon Sep 17 00:00:00 2001 From: parth Date: Wed, 30 Apr 2025 18:56:44 -0400 Subject: [PATCH 086/123] time for sway? --- helix/config.toml | 2 +- nix/common/gui.nix | 27 +++++++++++----------- nix/common/headless.nix | 48 ++++++++++++++------------------------- nix/workstation.nix | 50 +++-------------------------------------- wezterm/wezterm.lua | 9 ++++---- 5 files changed, 39 insertions(+), 97 deletions(-) diff --git a/helix/config.toml b/helix/config.toml index ab789026f..ed7e744de 100644 --- a/helix/config.toml +++ b/helix/config.toml @@ -1,4 +1,4 @@ -theme = "tokyonight" +theme = "base16_default" [editor] cursor-shape = { insert = "bar" } diff --git a/nix/common/gui.nix b/nix/common/gui.nix index dc58eaae5..ee7f10cdb 100644 --- a/nix/common/gui.nix +++ b/nix/common/gui.nix @@ -1,21 +1,21 @@ { pkgs, ... }: { - services.xserver.enable = true; - services.xserver.displayManager.gdm.enable = true; - services.xserver.desktopManager.gnome.enable = true; - services.xserver.displayManager.autoLogin.enable = true; - services.xserver.displayManager.autoLogin.user = "parth"; - services.xserver = { - xkb.options = "caps:escape"; - }; - services.xserver.xkb = { - layout = "us"; - variant = ""; + # from: https://wiki.nixos.org/wiki/Sway + environment.systemPackages = with pkgs; [ + grim + slurp + wl-clipboard + mako + ]; + services.gnome.gnome-keyring.enable = true; + programs.sway = { + enable = true; + wrapperFeatures.gtk = true; }; + # end sway services.printing.enable = true; - hardware.pulseaudio.enable = false; security.rtkit.enable = true; services.pipewire = { @@ -34,7 +34,8 @@ google-chrome discord spotify - slack + wezterm + lockbook-desktop ]; programs._1password-gui.enable = true; diff --git a/nix/common/headless.nix b/nix/common/headless.nix index 46b8e7771..da5402b6d 100644 --- a/nix/common/headless.nix +++ b/nix/common/headless.nix @@ -64,7 +64,6 @@ in ]; extraPackages = with pkgs; [ - nixpkgs-fmt lua-language-server # i would like to configure this here but rustup does some wack shit # rust-analyzer @@ -82,37 +81,22 @@ in source = /home/parth/dotfiles/nvim; recursive = true; }; - }; - - home.activation.cloneLockbook = lib.mkAfter '' - #!/usr/bin/env bash - - if [ ! -d $HOME/Documents/lockbook/lockbook ]; then - mkdir -p $HOME/Documents/lockbook/; - cd $HOME/Documents/lockbook && git clone git@github.com:lockbook/lockbook.git - fi - - if [ ! -d $HOME/Documents/lockbook/nixpkgs ]; then - mkdir -p $HOME/Documents/lockbook/; - cd $HOME/Documents/lockbook && git clone git@github.com:lockbook/nixpkgs.git - fi - if [ ! -d $HOME/Documents/lockbook/db-rs ]; then - mkdir -p $HOME/Documents/lockbook/; - cd $HOME/Documents/lockbook && git clone git@github.com:lockbook/db-rs.git - fi - - if [ ! -d $HOME/Documents/lockbook/cli-rs ]; then - mkdir -p $HOME/Documents/lockbook/; - cd $HOME/Documents/lockbook && git clone git@github.com:lockbook/cli-rs.git - fi + "helix" = { + source = /home/parth/dotfiles/helix; + recursive = true; + }; - if [ ! -d $HOME/Documents/lockbook/tracing-gcp ]; then - mkdir -p $HOME/Documents/lockbook/; - cd $HOME/Documents/lockbook && git clone git@github.com:lockbook/tracing-gcp.git - fi - ''; + "aerospace" = { + source = /home/parth/dotfiles/aerospace; + recursive = true; + }; + "wezterm" = { + source = /home/parth/dotfiles/wezterm; + recursive = true; + }; + }; home.sessionPath = [ "$HOME/.cargo/bin" ]; @@ -123,6 +107,8 @@ in description = "parth"; extraGroups = [ "networkmanager" "wheel" ]; packages = with pkgs; [ + helix + fzf xclip @@ -131,11 +117,11 @@ in samba - # move these to neovim specific area rust-analyzer rustup - nixd + lua-language-server + nixpkgs-fmt ]; }; diff --git a/nix/workstation.nix b/nix/workstation.nix index cc7585733..a3c32668e 100644 --- a/nix/workstation.nix +++ b/nix/workstation.nix @@ -2,58 +2,14 @@ { networking.hostName = "parth-workstation-nix"; - services.xserver.videoDrivers = [ "nvidia" ]; + services.xserver.videoDrivers = [ "amdgpu" ]; # Load nvidia driver for Xorg and Wayland - hardware.opengl = { + hardware.graphics = { enable = true; - driSupport = true; - driSupport32Bit = true; + enable32Bit = true; }; - services.xserver.displayManager.gdm.wayland = false; - - hardware.nvidia = { - - forceFullCompositionPipeline = true; - # Modesetting is required. - modesetting.enable = true; - - # Nvidia power management. Experimental, and can cause sleep/suspend to fail. - # Enable this if you have graphical corruption issues or application crashes after waking - # up from sleep. This fixes it by saving the entire VRAM memory to /tmp/ instead - # of just the bare essentials. - powerManagement.enable = false; - - # Fine-grained power management. Turns off GPU when not in use. - # Experimental and only works on modern Nvidia GPUs (Turing or newer). - powerManagement.finegrained = false; - - # Use the NVidia open source kernel module (not to be confused with the - # independent third-party "nouveau" open source driver). - # Support is limited to the Turing and later architectures. Full list of - # supported GPUs is at: - # https://github.com/NVIDIA/open-gpu-kernel-modules#compatible-gpus - # Only available from driver 515.43.04+ - # Currently alpha-quality/buggy, so false is currently the recommended setting. - open = false; - - # Enable the Nvidia settings menu, - # accessible via `nvidia-settings`. - nvidiaSettings = true; - - # Optionally, you may need to select the appropriate driver version for your specific GPU. - package = config.boot.kernelPackages.nvidiaPackages.stable; - }; - - # this config seemed to initially make wayland the default until I forced it to be x11 at the gdm level - # the behavior was really strange lots of weird frame stuttering going on until x11 was the default, than - # many problems went away. - # I don't have screen tearing at this point, and that's generally my litmus test, but I do seem to have - # vsync issues (which I've probably never tested for before). But I do have 2 monitors with different - # refresh rates, so maybe that's just my problem. - # maybe some combination of a new driver from nvidia and wayland will solve this at some pognt - imports = [ "/home/parth/dotfiles/nix/common/headless.nix" "/home/parth/dotfiles/nix/common/gui.nix" diff --git a/wezterm/wezterm.lua b/wezterm/wezterm.lua index 6587b1c6e..cdcee4cc2 100644 --- a/wezterm/wezterm.lua +++ b/wezterm/wezterm.lua @@ -14,7 +14,7 @@ config.macos_window_background_blur = 100 config.win32_system_backdrop = 'Acrylic' if wezterm.gui.get_appearance():find 'Dark' then - config.window_background_opacity = 0.5 + config.window_background_opacity = 1.0 config.colors = { ansi = { '#505050', -- black @@ -38,9 +38,8 @@ if wezterm.gui.get_appearance():find 'Dark' then }, foreground = '#FFFFFF', - background = '#1A1A1A', - - } + background = '#000000', + } else config.colors = { ansi = { @@ -64,7 +63,7 @@ else '#1A1A1A', -- brwhite }, - foreground = '#1A1A1A', + foreground = '#000000', background = '#FFFFFF', } end From 9e112d51722681da899eb4948be7fa1c215a20c5 Mon Sep 17 00:00:00 2001 From: parth Date: Wed, 30 Apr 2025 23:55:32 -0400 Subject: [PATCH 087/123] sway is in --- nix/common/gui.nix | 1 + nix/common/headless.nix | 4 + sway/config | 223 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 228 insertions(+) create mode 100644 sway/config diff --git a/nix/common/gui.nix b/nix/common/gui.nix index ee7f10cdb..ab3ccc2e0 100644 --- a/nix/common/gui.nix +++ b/nix/common/gui.nix @@ -7,6 +7,7 @@ slurp wl-clipboard mako + wdisplays ]; services.gnome.gnome-keyring.enable = true; programs.sway = { diff --git a/nix/common/headless.nix b/nix/common/headless.nix index da5402b6d..5c06f8f4b 100644 --- a/nix/common/headless.nix +++ b/nix/common/headless.nix @@ -96,6 +96,10 @@ in source = /home/parth/dotfiles/wezterm; recursive = true; }; + "sway" = { + source = /home/parth/dotfiles/sway; + recursive = true; + }; }; home.sessionPath = [ "$HOME/.cargo/bin" diff --git a/sway/config b/sway/config new file mode 100644 index 000000000..60f376544 --- /dev/null +++ b/sway/config @@ -0,0 +1,223 @@ +# todo: Use Mod1 for Alt. +set $mod Mod4 + +set $left h +set $down j +set $up k +set $right l + +set $term foot +# Your preferred application launcher +set $menu wmenu-run + +output 'LG Electronics LG ULTRAGEAR 301NTZNBU797' mode 3840x2160 position 3335,1420 +output 'California Institute of Technology HDMI demoset-1' mode 1920x1200 position 4038,3580 +output 'LG Electronics LG HDR 4K 111NTMX7X891' mode 3840x2160 position 1175,407 transform 90 + +### Output configuration +# +# Default wallpaper (more resolutions are available in /run/current-system/sw/share/backgrounds/sway/) +# +# Example configuration: +# +# output HDMI-A-1 resolution 1920x1080 position 1920,0 +# +# You can get the names of your outputs by running: swaymsg -t get_outputs + +### Idle configuration +# +# Example configuration: +# +# exec swayidle -w \ +# timeout 300 'swaylock -f -c 000000' \ +# timeout 600 'swaymsg "output * power off"' resume 'swaymsg "output * power on"' \ +# before-sleep 'swaylock -f -c 000000' +# +# This will lock your screen after 300 seconds of inactivity, then turn off +# your displays after another 300 seconds, and turn your screens back on when +# resumed. It will also lock your screen before your computer goes to sleep. + +### Input configuration +# +# Example configuration: +# +# input "2:14:SynPS/2_Synaptics_TouchPad" { +# dwt enabled +# tap enabled +# natural_scroll enabled +# middle_emulation enabled +# } +# +# You can get the names of your inputs by running: swaymsg -t get_inputs +# Read `man 5 sway-input` for more information about this section. + +### Key bindings +# +# Basics: +# + # Start a terminal + bindsym $mod+Return exec $term + + # Kill focused window + bindsym $mod+Shift+q kill + + # Start your launcher + bindsym $mod+d exec $menu + + # Drag floating windows by holding down $mod and left mouse button. + # Resize them with right mouse button + $mod. + # Despite the name, also works for non-floating windows. + # Change normal to inverse to use left mouse button for resizing and right + # mouse button for dragging. + floating_modifier $mod normal + + # Reload the configuration file + bindsym $mod+Shift+c reload + + # Exit sway (logs you out of your Wayland session) + bindsym $mod+Shift+e exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -B 'Yes, exit sway' 'swaymsg exit' +# +# Moving around: +# + # Move your focus around + bindsym $mod+$left focus left + bindsym $mod+$down focus down + bindsym $mod+$up focus up + bindsym $mod+$right focus right + # Or use $mod+[up|down|left|right] + bindsym $mod+Left focus left + bindsym $mod+Down focus down + bindsym $mod+Up focus up + bindsym $mod+Right focus right + + # Move the focused window with the same, but add Shift + bindsym $mod+Shift+$left move left + bindsym $mod+Shift+$down move down + bindsym $mod+Shift+$up move up + bindsym $mod+Shift+$right move right + # Ditto, with arrow keys + bindsym $mod+Shift+Left move left + bindsym $mod+Shift+Down move down + bindsym $mod+Shift+Up move up + bindsym $mod+Shift+Right move right +# +# Workspaces: +# + # Switch to workspace + bindsym $mod+1 workspace number 1 + bindsym $mod+2 workspace number 2 + bindsym $mod+3 workspace number 3 + bindsym $mod+4 workspace number 4 + bindsym $mod+5 workspace number 5 + bindsym $mod+6 workspace number 6 + bindsym $mod+7 workspace number 7 + bindsym $mod+8 workspace number 8 + bindsym $mod+9 workspace number 9 + bindsym $mod+0 workspace number 10 + # Move focused container to workspace + bindsym $mod+Shift+1 move container to workspace number 1 + bindsym $mod+Shift+2 move container to workspace number 2 + bindsym $mod+Shift+3 move container to workspace number 3 + bindsym $mod+Shift+4 move container to workspace number 4 + bindsym $mod+Shift+5 move container to workspace number 5 + bindsym $mod+Shift+6 move container to workspace number 6 + bindsym $mod+Shift+7 move container to workspace number 7 + bindsym $mod+Shift+8 move container to workspace number 8 + bindsym $mod+Shift+9 move container to workspace number 9 + bindsym $mod+Shift+0 move container to workspace number 10 + # Note: workspaces can have any name you want, not just numbers. + # We just use 1-10 as the default. +# +# Layout stuff: +# + # You can "split" the current object of your focus with + # $mod+b or $mod+v, for horizontal and vertical splits + # respectively. + bindsym $mod+b splith + bindsym $mod+v splitv + + # Switch the current container between different layout styles + bindsym $mod+s layout stacking + bindsym $mod+w layout tabbed + bindsym $mod+e layout toggle split + + # Make the current focus fullscreen + bindsym $mod+f fullscreen + + # Toggle the current focus between tiling and floating mode + bindsym $mod+Shift+space floating toggle + + # Swap focus between the tiling area and the floating area + bindsym $mod+space focus mode_toggle + + # Move focus to the parent container + bindsym $mod+a focus parent +# +# Scratchpad: +# + # Sway has a "scratchpad", which is a bag of holding for windows. + # You can send windows there and get them back later. + + # Move the currently focused window to the scratchpad + bindsym $mod+Shift+minus move scratchpad + + # Show the next scratchpad window or hide the focused scratchpad window. + # If there are multiple scratchpad windows, this command cycles through them. + bindsym $mod+minus scratchpad show +# +# Resizing containers: +# +mode "resize" { + # left will shrink the containers width + # right will grow the containers width + # up will shrink the containers height + # down will grow the containers height + bindsym $left resize shrink width 10px + bindsym $down resize grow height 10px + bindsym $up resize shrink height 10px + bindsym $right resize grow width 10px + + # Ditto, with arrow keys + bindsym Left resize shrink width 10px + bindsym Down resize grow height 10px + bindsym Up resize shrink height 10px + bindsym Right resize grow width 10px + + # Return to default mode + bindsym Return mode "default" + bindsym Escape mode "default" +} +bindsym $mod+r mode "resize" +# +# Utilities: +# + # Special keys to adjust volume via PulseAudio + bindsym --locked XF86AudioMute exec pactl set-sink-mute \@DEFAULT_SINK@ toggle + bindsym --locked XF86AudioLowerVolume exec pactl set-sink-volume \@DEFAULT_SINK@ -5% + bindsym --locked XF86AudioRaiseVolume exec pactl set-sink-volume \@DEFAULT_SINK@ +5% + bindsym --locked XF86AudioMicMute exec pactl set-source-mute \@DEFAULT_SOURCE@ toggle + # Special keys to adjust brightness via brightnessctl + bindsym --locked XF86MonBrightnessDown exec brightnessctl set 5%- + bindsym --locked XF86MonBrightnessUp exec brightnessctl set 5%+ + # Special key to take a screenshot with grim + bindsym Print exec grim + +# +# Status Bar: +# +# Read `man 5 sway-bar` for more information about this section. +bar { + position top + + # When the status_command prints a new line to stdout, swaybar updates. + # The default just shows the current date and time. + status_command while date +'%Y-%m-%d %X'; do sleep 1; done + + colors { + statusline #ffffff + background #323232 + inactive_workspace #32323200 #32323200 #5c5c5c + } +} + +include /etc/sway/config.d/* From 0fa9ed7491d621c6fb4b990203c2a52d31ae54a4 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 1 May 2025 17:07:44 -0400 Subject: [PATCH 088/123] sway is in a lil more --- nix/common/gui.nix | 5 +++++ sway/config | 12 +----------- wezterm/wezterm.lua | 3 ++- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/nix/common/gui.nix b/nix/common/gui.nix index ab3ccc2e0..0aaea55f8 100644 --- a/nix/common/gui.nix +++ b/nix/common/gui.nix @@ -14,6 +14,11 @@ enable = true; wrapperFeatures.gtk = true; }; + xdg.portal = { + enable = true; + wlr.enable = true; + extraPortals = [ pkgs.xdg-desktop-portal-gtk ]; + }; # end sway services.printing.enable = true; diff --git a/sway/config b/sway/config index 60f376544..4c9220aad 100644 --- a/sway/config +++ b/sway/config @@ -6,7 +6,7 @@ set $down j set $up k set $right l -set $term foot +set $term wezterm # Your preferred application launcher set $menu wmenu-run @@ -14,16 +14,6 @@ output 'LG Electronics LG ULTRAGEAR 301NTZNBU797' mode 3840x2160 position 3335,1 output 'California Institute of Technology HDMI demoset-1' mode 1920x1200 position 4038,3580 output 'LG Electronics LG HDR 4K 111NTMX7X891' mode 3840x2160 position 1175,407 transform 90 -### Output configuration -# -# Default wallpaper (more resolutions are available in /run/current-system/sw/share/backgrounds/sway/) -# -# Example configuration: -# -# output HDMI-A-1 resolution 1920x1080 position 1920,0 -# -# You can get the names of your outputs by running: swaymsg -t get_outputs - ### Idle configuration # # Example configuration: diff --git a/wezterm/wezterm.lua b/wezterm/wezterm.lua index cdcee4cc2..c767d7353 100644 --- a/wezterm/wezterm.lua +++ b/wezterm/wezterm.lua @@ -13,8 +13,9 @@ config.window_padding = { config.macos_window_background_blur = 100 config.win32_system_backdrop = 'Acrylic' +-- presently broken on linux as my system has no real way to set dark / light mode + if wezterm.gui.get_appearance():find 'Dark' then - config.window_background_opacity = 1.0 config.colors = { ansi = { '#505050', -- black From a3eb471f19cf0c6948beeb13c58d1c1a2aa424a0 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 1 May 2025 21:43:14 -0400 Subject: [PATCH 089/123] restore virt-manager and add gaps --- nix/common/gui.nix | 6 ++++++ sway/config | 2 ++ wezterm/wezterm.lua | 1 + 3 files changed, 9 insertions(+) diff --git a/nix/common/gui.nix b/nix/common/gui.nix index 0aaea55f8..fc068fdd8 100644 --- a/nix/common/gui.nix +++ b/nix/common/gui.nix @@ -54,4 +54,10 @@ systemd.services."getty@tty1".enable = false; systemd.services."autovt@tty1".enable = false; + + programs.virt-manager.enable = true; + users.groups.libvirtd.members = [ "parth" ]; + virtualisation.libvirtd.enable = true; + virtualisation.spiceUSBRedirection.enable = true; + } diff --git a/sway/config b/sway/config index 4c9220aad..83bb5dcae 100644 --- a/sway/config +++ b/sway/config @@ -1,6 +1,8 @@ # todo: Use Mod1 for Alt. set $mod Mod4 +gaps inner 10 + set $left h set $down j set $up k diff --git a/wezterm/wezterm.lua b/wezterm/wezterm.lua index c767d7353..21737c1a4 100644 --- a/wezterm/wezterm.lua +++ b/wezterm/wezterm.lua @@ -14,6 +14,7 @@ config.macos_window_background_blur = 100 config.win32_system_backdrop = 'Acrylic' -- presently broken on linux as my system has no real way to set dark / light mode +print(wezterm.gui.get_appearance()) if wezterm.gui.get_appearance():find 'Dark' then config.colors = { From 722927f6fbda1d9c0f1e869bbc191d24159b3012 Mon Sep 17 00:00:00 2001 From: parth Date: Fri, 2 May 2025 21:44:12 -0400 Subject: [PATCH 090/123] some more tweaking --- helix/config.toml | 5 +++++ sway/config | 15 +++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/helix/config.toml b/helix/config.toml index ed7e744de..def217109 100644 --- a/helix/config.toml +++ b/helix/config.toml @@ -4,3 +4,8 @@ theme = "base16_default" cursor-shape = { insert = "bar" } cursorline = true cursorcolumn = true +indent-guides = { render = true, skip-levels = 1 } + +# status line desires +# git info +# lsp info diff --git a/sway/config b/sway/config index 83bb5dcae..4171429f8 100644 --- a/sway/config +++ b/sway/config @@ -1,3 +1,5 @@ +input "type:keyboard" xkb_options caps:escape + # todo: Use Mod1 for Alt. set $mod Mod4 @@ -8,9 +10,10 @@ set $down j set $up k set $right l -set $term wezterm -# Your preferred application launcher -set $menu wmenu-run +bindsym $mod+Return exec wezterm +bindsym $mod+backslash exec google-chrome-stable +bindsym $mod+Space exec wmenu-run +bindsym $mod+o exec lockbook-desktop output 'LG Electronics LG ULTRAGEAR 301NTZNBU797' mode 3840x2160 position 3335,1420 output 'California Institute of Technology HDMI demoset-1' mode 1920x1200 position 4038,3580 @@ -47,14 +50,10 @@ output 'LG Electronics LG HDR 4K 111NTMX7X891' mode 3840x2160 position 1175,407 # # Basics: # - # Start a terminal - bindsym $mod+Return exec $term # Kill focused window bindsym $mod+Shift+q kill - # Start your launcher - bindsym $mod+d exec $menu # Drag floating windows by holding down $mod and left mouse button. # Resize them with right mouse button + $mod. @@ -140,7 +139,7 @@ output 'LG Electronics LG HDR 4K 111NTMX7X891' mode 3840x2160 position 1175,407 bindsym $mod+Shift+space floating toggle # Swap focus between the tiling area and the floating area - bindsym $mod+space focus mode_toggle + bindsym $mod+t focus mode_toggle # Move focus to the parent container bindsym $mod+a focus parent From 3028c18d2db6b5f50ff311c82aeb894e64dc7542 Mon Sep 17 00:00:00 2001 From: parth Date: Mon, 5 May 2025 21:09:21 -0400 Subject: [PATCH 091/123] insta360 --- nix/macbook.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nix/macbook.nix b/nix/macbook.nix index bd88d1e2d..d16e37252 100644 --- a/nix/macbook.nix +++ b/nix/macbook.nix @@ -103,6 +103,7 @@ "wezterm" "google-chrome" "nikitabobko/tap/aerospace" + "insta360-studio" # discord # ableton-live-standard # spotify From c1cda31594d532475783c0d64a19a492cf8675d0 Mon Sep 17 00:00:00 2001 From: parth Date: Mon, 5 May 2025 21:36:19 -0400 Subject: [PATCH 092/123] monitor workspace config? --- sway/config | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/sway/config b/sway/config index 4171429f8..fc0a1ee1f 100644 --- a/sway/config +++ b/sway/config @@ -15,9 +15,18 @@ bindsym $mod+backslash exec google-chrome-stable bindsym $mod+Space exec wmenu-run bindsym $mod+o exec lockbook-desktop -output 'LG Electronics LG ULTRAGEAR 301NTZNBU797' mode 3840x2160 position 3335,1420 -output 'California Institute of Technology HDMI demoset-1' mode 1920x1200 position 4038,3580 -output 'LG Electronics LG HDR 4K 111NTMX7X891' mode 3840x2160 position 1175,407 transform 90 +set $A 'LG Electronics LG ULTRAGEAR 301NTZNBU797' +set $B 'California Institute of Technology HDMI demoset-1' +set $C 'LG Electronics LG HDR 4K 111NTMX7X891' + +output $A mode 3840x2160 position 3335,1420 +output $B mode 1920x1200 position 4038,3580 +output $C mode 3840x2160 position 1175,407 transform 90 + +# todo: unclear whether this worked or not until restart +workspace 1 $A +workspace 2 $B +workspace 3 $C ### Idle configuration # From 38229fd4d86696284de037bab2aabdedcb383388 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 8 May 2025 14:54:17 -0400 Subject: [PATCH 093/123] obs + nautilus + vlc + helix config tweaks --- helix/config.toml | 17 +++++++++++++++++ nix/common/gui.nix | 3 +++ 2 files changed, 20 insertions(+) diff --git a/helix/config.toml b/helix/config.toml index def217109..1d7d84350 100644 --- a/helix/config.toml +++ b/helix/config.toml @@ -1,3 +1,5 @@ +# hard to tell when 2 suggestions which one is selected in code completion +# when grepping sometimes previews are un-viewable theme = "base16_default" [editor] @@ -9,3 +11,18 @@ indent-guides = { render = true, skip-levels = 1 } # status line desires # git info # lsp info +# +# ]d should prioritize errors +# +# helix config lsp? +# toml auto formatter? + +[keys.insert] +# would like to be able to scroll down and up with C-j C-k, tbd on whether cursor should move +C-e = "insert_at_line_end" + +[keys.normal] +esc = ":wa" + +[keys.normal."space"] +E = "@ D%p !tests %s ERROR" diff --git a/nix/common/gui.nix b/nix/common/gui.nix index fc068fdd8..2b645e023 100644 --- a/nix/common/gui.nix +++ b/nix/common/gui.nix @@ -42,6 +42,9 @@ spotify wezterm lockbook-desktop + obs-studio + nautilus + vlc ]; programs._1password-gui.enable = true; From ddfe3e1d7d4156fe0d6ac1e31e275eabdbada039 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 8 May 2025 21:57:40 -0400 Subject: [PATCH 094/123] more hx notes --- helix/config.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/helix/config.toml b/helix/config.toml index 1d7d84350..882ce7a18 100644 --- a/helix/config.toml +++ b/helix/config.toml @@ -1,5 +1,9 @@ # hard to tell when 2 suggestions which one is selected in code completion # when grepping sometimes previews are un-viewable +# find references of get_usage the bar is blue the text is the same blue and I +# can't see what's going on +# +# symbol highlighting also not working, possibly a theme problem theme = "base16_default" [editor] From 136197967c419f84e6f4dd0df05dfcf8696e81ff Mon Sep 17 00:00:00 2001 From: parth Date: Sat, 10 May 2025 09:58:37 -0400 Subject: [PATCH 095/123] removed themes due to problems for now, we will come back again strong --- helix/config.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix/config.toml b/helix/config.toml index 882ce7a18..4217894e2 100644 --- a/helix/config.toml +++ b/helix/config.toml @@ -4,7 +4,7 @@ # can't see what's going on # # symbol highlighting also not working, possibly a theme problem -theme = "base16_default" +# theme = "base16_default" [editor] cursor-shape = { insert = "bar" } From 4f02a02fa6e616e1b35ce55169b52611359e4752 Mon Sep 17 00:00:00 2001 From: parth Date: Wed, 14 May 2025 14:39:43 -0400 Subject: [PATCH 096/123] some notes --- helix/config.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/helix/config.toml b/helix/config.toml index 882ce7a18..d5156d1b3 100644 --- a/helix/config.toml +++ b/helix/config.toml @@ -4,6 +4,8 @@ # can't see what's going on # # symbol highlighting also not working, possibly a theme problem +# +# we cannot use any red for the text -- the diagnostics are shown in the top right and the clash is prohibitive theme = "base16_default" [editor] @@ -26,7 +28,8 @@ indent-guides = { render = true, skip-levels = 1 } C-e = "insert_at_line_end" [keys.normal] -esc = ":wa" +esc = ":write-all" +C-r = ":reload-all" [keys.normal."space"] E = "@ D%p !tests %s ERROR" From aea4ed00cd22166a9a12625eb8b1efd789cb8130 Mon Sep 17 00:00:00 2001 From: parth Date: Sat, 17 May 2025 21:43:23 -0400 Subject: [PATCH 097/123] add cargo to bin --- nix/common/headless.nix | 1 + nix/macbook.nix | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nix/common/headless.nix b/nix/common/headless.nix index 5c06f8f4b..d41258c50 100644 --- a/nix/common/headless.nix +++ b/nix/common/headless.nix @@ -32,6 +32,7 @@ in enable = true; shellInit = '' fish_vi_key_bindings + set -gx PATH $HOME/.cargo/bin $PATH ''; }; users.defaultUserShell = pkgs.fish; diff --git a/nix/macbook.nix b/nix/macbook.nix index d16e37252..a54076f76 100644 --- a/nix/macbook.nix +++ b/nix/macbook.nix @@ -58,6 +58,7 @@ enable = true; shellInit = '' fish_vi_key_bindings + set -gx PATH $HOME/.cargo/bin $PATH ''; }; @@ -153,8 +154,6 @@ # ''; }; - - xdg.configFile = { "nvim" = { source = /Users/parth/dotfiles/nvim; From b8ccad9e44eb4a999cb6acf1ffdf217395e7ab45 Mon Sep 17 00:00:00 2001 From: parth Date: Tue, 22 Jul 2025 16:03:03 -0400 Subject: [PATCH 098/123] dark light switching --- helix/config.toml | 6 +++++- nix/common/headless.nix | 2 ++ nix/macbook.nix | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/helix/config.toml b/helix/config.toml index d5156d1b3..0f832aff4 100644 --- a/helix/config.toml +++ b/helix/config.toml @@ -1,3 +1,5 @@ +theme = "adwaita-dark" + # hard to tell when 2 suggestions which one is selected in code completion # when grepping sometimes previews are un-viewable # find references of get_usage the bar is blue the text is the same blue and I @@ -6,7 +8,7 @@ # symbol highlighting also not working, possibly a theme problem # # we cannot use any red for the text -- the diagnostics are shown in the top right and the clash is prohibitive -theme = "base16_default" +# theme = "base16_default" [editor] cursor-shape = { insert = "bar" } @@ -30,6 +32,8 @@ C-e = "insert_at_line_end" [keys.normal] esc = ":write-all" C-r = ":reload-all" +C-l = ":theme adwaita-light" +C-k = ":theme adwaita-dark" [keys.normal."space"] E = "@ D%p !tests %s ERROR" diff --git a/nix/common/headless.nix b/nix/common/headless.nix index d41258c50..0007f801e 100644 --- a/nix/common/headless.nix +++ b/nix/common/headless.nix @@ -112,6 +112,8 @@ in description = "parth"; extraGroups = [ "networkmanager" "wheel" ]; packages = with pkgs; [ + zola + helix fzf diff --git a/nix/macbook.nix b/nix/macbook.nix index a54076f76..d8a21ec60 100644 --- a/nix/macbook.nix +++ b/nix/macbook.nix @@ -35,6 +35,7 @@ fzf lua-language-server + zola nixpkgs-fmt nixd rust-analyzer @@ -98,6 +99,7 @@ # "Final Cut Pro" = 424389933; "Lockbook" = 1526775001; # 1password + "Lightroom" = 1451544217; }; casks = [ @@ -105,6 +107,7 @@ "google-chrome" "nikitabobko/tap/aerospace" "insta360-studio" + "adobe-creative-cloud" # discord # ableton-live-standard # spotify From 43311a9656d69f81d5c2ef817ac9a9e4ad1ebde4 Mon Sep 17 00:00:00 2001 From: parth Date: Wed, 23 Jul 2025 12:52:28 -0400 Subject: [PATCH 099/123] desktop changes --- nix/common/gui.nix | 8 +++----- nix/common/headless.nix | 2 ++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nix/common/gui.nix b/nix/common/gui.nix index 2b645e023..4f04a8cb6 100644 --- a/nix/common/gui.nix +++ b/nix/common/gui.nix @@ -1,4 +1,4 @@ -{ pkgs, ... }: { +{ pkgs, lib, ... }: { # from: https://wiki.nixos.org/wiki/Sway @@ -22,7 +22,7 @@ # end sway services.printing.enable = true; - hardware.pulseaudio.enable = false; + services.pulseaudio.enable = false; security.rtkit.enable = true; services.pipewire = { enable = true; @@ -31,9 +31,7 @@ pulse.enable = true; }; - fonts.packages = with pkgs; [ - nerdfonts - ]; + fonts.packages = [ ] ++ builtins.filter lib.attrsets.isDerivation (builtins.attrValues pkgs.nerd-fonts); users.users.parth.packages = with pkgs; [ _1password-gui diff --git a/nix/common/headless.nix b/nix/common/headless.nix index d41258c50..5357fac4f 100644 --- a/nix/common/headless.nix +++ b/nix/common/headless.nix @@ -127,6 +127,8 @@ in nixd lua-language-server nixpkgs-fmt + + google-cloud-sdk ]; }; From ec54fcf49970fa06595262039438627066f81b1a Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 24 Jul 2025 22:14:18 -0400 Subject: [PATCH 100/123] add lockbook completions --- nix/macbook.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nix/macbook.nix b/nix/macbook.nix index d8a21ec60..adaa6657a 100644 --- a/nix/macbook.nix +++ b/nix/macbook.nix @@ -40,6 +40,7 @@ nixd rust-analyzer rustup + lockbook # listing clang here makes the macOS clang act strange ]; @@ -127,6 +128,9 @@ enable = true; userName = "parth"; userEmail = "parth@mehrotra.me"; + extraConfig = { + push.default = "current"; + }; }; programs.neovim = { From 24daecb0476079dfd51485f54406d55626ec90bb Mon Sep 17 00:00:00 2001 From: parth Date: Tue, 9 Sep 2025 13:05:29 -0400 Subject: [PATCH 101/123] cleanup macbook --- helix/config.toml | 2 ++ nix/common/headless.nix | 4 ++++ nix/macbook.nix | 10 +++++----- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/helix/config.toml b/helix/config.toml index 0f832aff4..2d5552448 100644 --- a/helix/config.toml +++ b/helix/config.toml @@ -37,3 +37,5 @@ C-k = ":theme adwaita-dark" [keys.normal."space"] E = "@ D%p !tests %s ERROR" +e = "@ D %s ERROR" +W = "@ D%p !tests %s" diff --git a/nix/common/headless.nix b/nix/common/headless.nix index c995ff296..56e4fcdc1 100644 --- a/nix/common/headless.nix +++ b/nix/common/headless.nix @@ -45,6 +45,9 @@ in enable = true; userName = "parth"; userEmail = "parth@mehrotra.me"; + extraConfig = { + push.default = "current"; + }; }; @@ -131,6 +134,7 @@ in nixpkgs-fmt google-cloud-sdk + lockbook ]; }; diff --git a/nix/macbook.nix b/nix/macbook.nix index adaa6657a..36dbddb3a 100644 --- a/nix/macbook.nix +++ b/nix/macbook.nix @@ -97,9 +97,8 @@ masApps = { "XCode" = 497799835; - # "Final Cut Pro" = 424389933; + "Final Cut Pro" = 424389933; "Lockbook" = 1526775001; - # 1password "Lightroom" = 1451544217; }; @@ -109,9 +108,9 @@ "nikitabobko/tap/aerospace" "insta360-studio" "adobe-creative-cloud" - # discord - # ableton-live-standard - # spotify + "discord" + "1password" + "spotify" ]; }; } @@ -404,3 +403,4 @@ }; }; } +# https://github.com/dustinlyons/nixos-config/blob/8a14e1f0da074b3f9060e8c822164d922bfeec29/modules/darwin/home-manager.nix#L74 From 42a5d5227dc1b3bb75075b9ad22627d7d24928b1 Mon Sep 17 00:00:00 2001 From: parth Date: Tue, 9 Sep 2025 13:29:53 -0400 Subject: [PATCH 102/123] cleanup macbook --- nix/macbook.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/macbook.nix b/nix/macbook.nix index 36dbddb3a..59a228cfe 100644 --- a/nix/macbook.nix +++ b/nix/macbook.nix @@ -81,7 +81,7 @@ { # Build darwin flake using: # $ darwin-rebuild build --flake .#simple - darwinConfigurations."parth-macbook" = nix-darwin.lib.darwinSystem { + darwinConfigurations."parth-mbp" = nix-darwin.lib.darwinSystem { modules = [ configuration From c341271daded7ad15e7c5734a084178c7f9bd2ef Mon Sep 17 00:00:00 2001 From: parth Date: Tue, 9 Sep 2025 13:31:25 -0400 Subject: [PATCH 103/123] cleanup macbook --- nix/macbook.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/macbook.nix b/nix/macbook.nix index 59a228cfe..aa1108557 100644 --- a/nix/macbook.nix +++ b/nix/macbook.nix @@ -81,7 +81,7 @@ { # Build darwin flake using: # $ darwin-rebuild build --flake .#simple - darwinConfigurations."parth-mbp" = nix-darwin.lib.darwinSystem { + darwinConfigurations."Parth-MBP" = nix-darwin.lib.darwinSystem { modules = [ configuration From 3237d627e45da7ffc2015d28f8c46c03af8f8d9c Mon Sep 17 00:00:00 2001 From: parth Date: Tue, 9 Sep 2025 13:33:24 -0400 Subject: [PATCH 104/123] cleanup macbook --- nix/macbook.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nix/macbook.nix b/nix/macbook.nix index aa1108557..0825f0b13 100644 --- a/nix/macbook.nix +++ b/nix/macbook.nix @@ -66,6 +66,7 @@ users.knownUsers = [ "parth" ]; users.users.parth.uid = 501; + system.primaryUser = "parth"; users.users.parth = { home = "/Users/parth"; From e3d931717c7cca17ec3cbedaf2a18430a390ba08 Mon Sep 17 00:00:00 2001 From: parth Date: Fri, 12 Sep 2025 14:27:41 -0400 Subject: [PATCH 105/123] chat --- nix/macbook.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nix/macbook.nix b/nix/macbook.nix index 0825f0b13..8832ae3bf 100644 --- a/nix/macbook.nix +++ b/nix/macbook.nix @@ -112,6 +112,7 @@ "discord" "1password" "spotify" + "chatgpt" ]; }; } From 134b17cc4a05f9c438af47c03fd34081c458309e Mon Sep 17 00:00:00 2001 From: parth Date: Mon, 15 Sep 2025 21:57:04 -0400 Subject: [PATCH 106/123] more pkgs --- nix/macbook.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nix/macbook.nix b/nix/macbook.nix index 8832ae3bf..859f7cf89 100644 --- a/nix/macbook.nix +++ b/nix/macbook.nix @@ -113,6 +113,8 @@ "1password" "spotify" "chatgpt" + "makemkv" + "musescore" ]; }; } From 699af4cf095193379b8bbc753e8445e96ca1e6ee Mon Sep 17 00:00:00 2001 From: parth Date: Tue, 16 Sep 2025 15:20:37 -0400 Subject: [PATCH 107/123] cleanup mac flake --- nix/apply-macbook.sh | 2 +- nix/flake.lock | 106 +++++++++++ nix/flake.nix | 410 +++++++++++++++++++++++++++++++++++++++++++ nix/macbook.nix | 2 +- 4 files changed, 518 insertions(+), 2 deletions(-) create mode 100644 nix/flake.lock create mode 100644 nix/flake.nix diff --git a/nix/apply-macbook.sh b/nix/apply-macbook.sh index 2265af9b7..7455632cf 100755 --- a/nix/apply-macbook.sh +++ b/nix/apply-macbook.sh @@ -1,3 +1,3 @@ #!/bin/sh -rm -rf /etc/nix-darwin/flake.nix && cp $HOME/dotfiles/nix/macbook.nix /etc/nix-darwin/flake.nix && nix run nix-darwin/master#darwin-rebuild -- switch --impure +sudo darwin-rebuild switch --impure --flake .#default diff --git a/nix/flake.lock b/nix/flake.lock new file mode 100644 index 000000000..1d0b17881 --- /dev/null +++ b/nix/flake.lock @@ -0,0 +1,106 @@ +{ + "nodes": { + "brew-src": { + "flake": false, + "locked": { + "lastModified": 1756059815, + "narHash": "sha256-UALOxoXoFIHbwKzcqbqCAqw5cC0MJEehLaWSet5vxfE=", + "owner": "Homebrew", + "repo": "brew", + "rev": "02947ea4edbdef5fcce9ee57fa289547f4d096c9", + "type": "github" + }, + "original": { + "owner": "Homebrew", + "ref": "4.6.7", + "repo": "brew", + "type": "github" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1757997814, + "narHash": "sha256-F+1aoG+3NH4jDDEmhnDUReISyq6kQBBuktTUqCUWSiw=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "5820376beb804de9acf07debaaff1ac84728b708", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "nix-darwin": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1757430124, + "narHash": "sha256-MhDltfXesGH8VkGv3hmJ1QEKl1ChTIj9wmGAFfWj/Wk=", + "owner": "nix-darwin", + "repo": "nix-darwin", + "rev": "830b3f0b50045cf0bcfd4dab65fad05bf882e196", + "type": "github" + }, + "original": { + "owner": "nix-darwin", + "ref": "master", + "repo": "nix-darwin", + "type": "github" + } + }, + "nix-homebrew": { + "inputs": { + "brew-src": "brew-src" + }, + "locked": { + "lastModified": 1756398546, + "narHash": "sha256-n4GVDLhKu65XFraJuCzap2AaZji4xhPaZMTJ8aQdD3s=", + "owner": "zhaofengli-wip", + "repo": "nix-homebrew", + "rev": "3aa475996cb3bc1ecefa88c99c466e6f0bc17431", + "type": "github" + }, + "original": { + "owner": "zhaofengli-wip", + "repo": "nix-homebrew", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1757967192, + "narHash": "sha256-/aA9A/OBmnuOMgwfzdsXRusqzUpd8rQnQY8jtrHK+To=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0d7c15863b251a7a50265e57c1dca1a7add2e291", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "home-manager": "home-manager", + "nix-darwin": "nix-darwin", + "nix-homebrew": "nix-homebrew", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/nix/flake.nix b/nix/flake.nix new file mode 100644 index 000000000..aa7ebbcb8 --- /dev/null +++ b/nix/flake.nix @@ -0,0 +1,410 @@ +{ + description = "Example nix-darwin system flake"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + nix-darwin.url = "github:nix-darwin/nix-darwin/master"; + nix-darwin.inputs.nixpkgs.follows = "nixpkgs"; + home-manager.url = "github:nix-community/home-manager"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; + nix-homebrew.url = "github:zhaofengli-wip/nix-homebrew"; + }; + + outputs = + inputs@{ self + , nix-darwin + , nixpkgs + , home-manager + , nix-homebrew + , + }: + let + configuration = + { pkgs, ... }: + { + nixpkgs.config.allowUnfree = true; + nix.settings.experimental-features = "nix-command flakes"; + homebrew.enable = true; + + # Set Git commit hash for darwin-version. + system.configurationRevision = self.rev or self.dirtyRev or null; + + environment.systemPackages = with pkgs; [ + helix + + fzf + + lua-language-server + zola + nixpkgs-fmt + nixd + rust-analyzer + rustup + lockbook + # listing clang here makes the macOS clang act strange + ]; + + fonts.packages = with pkgs; [ + nerd-fonts.jetbrains-mono + ]; + + + # Used for backwards compatibility, please read the changelog before changing. + # $ darwin-rebuild changelog + system.stateVersion = 6; + + # The platform the configuration will be used on. + nixpkgs.hostPlatform = "aarch64-darwin"; + + programs.fish = { + enable = true; + shellInit = '' + fish_vi_key_bindings + set -gx PATH $HOME/.cargo/bin $PATH + ''; + }; + + users.knownUsers = [ "parth" ]; + users.users.parth.uid = 501; + system.primaryUser = "parth"; + + users.users.parth = { + home = "/Users/parth"; + shell = pkgs.fish; + }; + + system.keyboard = { + enableKeyMapping = true; + remapCapsLockToEscape = true; + }; + }; + in + { + # Build darwin flake using: + # $ darwin-rebuild build --flake .#simple + darwinConfigurations.default = nix-darwin.lib.darwinSystem { + modules = [ + configuration + + nix-homebrew.darwinModules.nix-homebrew + { + nix-homebrew = { + enable = true; + user = "parth"; + }; + + homebrew = { + enable = true; + + masApps = { + "XCode" = 497799835; + "Final Cut Pro" = 424389933; + "Lockbook" = 1526775001; + "Lightroom" = 1451544217; + }; + + casks = [ + "wezterm" + "google-chrome" + "nikitabobko/tap/aerospace" + "insta360-studio" + "adobe-creative-cloud" + "discord" + "1password" + "spotify" + "chatgpt" + "makemkv" + "musescore" + ]; + }; + } + + home-manager.darwinModules.home-manager + { + home-manager.useGlobalPkgs = true; + home-manager.backupFileExtension = "backup"; + home-manager.useUserPackages = true; + home-manager.users.parth = { pkgs, lib, ... }: { + home.stateVersion = "24.05"; + + programs.git = { + enable = true; + userName = "parth"; + userEmail = "parth@mehrotra.me"; + extraConfig = { + push.default = "current"; + }; + }; + + programs.neovim = { + enable = true; + plugins = with pkgs.vimPlugins; [ + nvim-web-devicons + telescope-nvim + nvim-cmp + cmp-nvim-lsp + vim-illuminate + lualine-nvim + lsp-status-nvim + + nvim-tree-lua + nvim-lspconfig + luasnip + # todo replace "FabijanZulj/blame.nvim", + ]; + + extraPackages = with pkgs; [ + lua-language-server + # i would like to configure this here but rustup does some wack shit + # rust-analyzer + ]; + + # extraLuaConfig = '' + # dofile("/home/parth/dotfiles/nvim/init.lua") + # ''; + }; + + xdg.configFile = { + "nvim" = { + source = /Users/parth/dotfiles/nvim; + recursive = true; + }; + + "helix" = { + source = /Users/parth/dotfiles/helix; + recursive = true; + }; + + "aerospace" = { + source = /Users/parth/dotfiles/aerospace; + recursive = true; + }; + + "wezterm" = { + source = /Users/parth/dotfiles/wezterm; + recursive = true; + }; + }; + + home.file.".aerospace.toml".text = '' + # Place a copy of this config to ~/.aerospace.toml + # After that, you can edit ~/.aerospace.toml to your liking + + # You can use it to add commands that run after login to macOS user session. + # 'start-at-login' needs to be 'true' for 'after-login-command' to work + # Available commands: https://nikitabobko.github.io/AeroSpace/commands + after-login-command = [] + + # You can use it to add commands that run after AeroSpace startup. + # 'after-startup-command' is run after 'after-login-command' + # Available commands : https://nikitabobko.github.io/AeroSpace/commands + after-startup-command = [] + + # Start AeroSpace at login + start-at-login = false + + # Normalizations. See: https://nikitabobko.github.io/AeroSpace/guide#normalization + enable-normalization-flatten-containers = true + enable-normalization-opposite-orientation-for-nested-containers = true + + # See: https://nikitabobko.github.io/AeroSpace/guide#layouts + # The 'accordion-padding' specifies the size of accordion padding + # You can set 0 to disable the padding feature + accordion-padding = 30 + + # Possible values: tiles|accordion + default-root-container-layout = 'tiles' + + # Possible values: horizontal|vertical|auto + # 'auto' means: wide monitor (anything wider than high) gets horizontal orientation, + # tall monitor (anything higher than wide) gets vertical orientation + default-root-container-orientation = 'auto' + + # Mouse follows focus when focused monitor changes + # Drop it from your config, if you don't like this behavior + # See https://nikitabobko.github.io/AeroSpace/guide#on-focus-changed-callbacks + # See https://nikitabobko.github.io/AeroSpace/commands#move-mouse + # Fallback value (if you omit the key): on-focused-monitor-changed = [] + on-focused-monitor-changed = ['move-mouse monitor-lazy-center'] + + # You can effectively turn off macOS "Hide application" (cmd-h) feature by toggling this flag + # Useful if you don't use this macOS feature, but accidentally hit cmd-h or cmd-alt-h key + # Also see: https://nikitabobko.github.io/AeroSpace/goodies#disable-hide-app + automatically-unhide-macos-hidden-apps = false + + # Possible values: (qwerty|dvorak|colemak) + # See https://nikitabobko.github.io/AeroSpace/guide#key-mapping + [key-mapping] + preset = 'qwerty' + + # Gaps between windows (inner-*) and between monitor edges (outer-*). + # Possible values: + # - Constant: gaps.outer.top = 8 + # - Per monitor: gaps.outer.top = [{ monitor.main = 16 }, { monitor."some-pattern" = 32 }, 24] + # In this example, 24 is a default value when there is no match. + # Monitor pattern is the same as for 'workspace-to-monitor-force-assignment'. + # See: + # https://nikitabobko.github.io/AeroSpace/guide#assign-workspaces-to-monitors + [gaps] + inner.horizontal = 6 + inner.vertical = 6 + outer.left = 6 + outer.bottom = 6 + outer.top = 6 + outer.right = 6 + + # 'main' binding mode declaration + # See: https://nikitabobko.github.io/AeroSpace/guide#binding-modes + # 'main' binding mode must be always presented + # Fallback value (if you omit the key): mode.main.binding = {} + [mode.main.binding] + + # All possible keys: + # - Letters. a, b, c, ..., z + # - Numbers. 0, 1, 2, ..., 9 + # - Keypad numbers. keypad0, keypad1, keypad2, ..., keypad9 + # - F-keys. f1, f2, ..., f20 + # - Special keys. minus, equal, period, comma, slash, backslash, quote, semicolon, + # backtick, leftSquareBracket, rightSquareBracket, space, enter, esc, + # backspace, tab, pageUp, pageDown, home, end, forwardDelete, + # sectionSign (ISO keyboards only, european keyboards only) + # - Keypad special. keypadClear, keypadDecimalMark, keypadDivide, keypadEnter, keypadEqual, + # keypadMinus, keypadMultiply, keypadPlus + # - Arrows. left, down, up, right + + # All possible modifiers: cmd, alt, ctrl, shift + + # All possible commands: https://nikitabobko.github.io/AeroSpace/commands + + # See: https://nikitabobko.github.io/AeroSpace/commands#exec-and-forget + # You can uncomment the following lines to open up terminal with alt + enter shortcut + # (like in i3) + # alt-enter = '''exec-and-forget osascript -e ' + # tell application "Terminal" + # do script + # activate + # end tell' + # ''' + + # See: https://nikitabobko.github.io/AeroSpace/commands#layout + alt-slash = 'layout tiles horizontal vertical' + alt-comma = 'layout accordion horizontal vertical' + + # See: https://nikitabobko.github.io/AeroSpace/commands#focus + alt-h = 'focus left' + alt-j = 'focus down' + alt-k = 'focus up' + alt-l = 'focus right' + + # See: https://nikitabobko.github.io/AeroSpace/commands#move + alt-shift-h = 'move left' + alt-shift-j = 'move down' + alt-shift-k = 'move up' + alt-shift-l = 'move right' + + # See: https://nikitabobko.github.io/AeroSpace/commands#resize + alt-minus = 'resize smart -50' + alt-equal = 'resize smart +50' + + # See: https://nikitabobko.github.io/AeroSpace/commands#workspace + alt-1 = 'workspace 1' + alt-2 = 'workspace 2' + alt-3 = 'workspace 3' + alt-4 = 'workspace 4' + alt-5 = 'workspace 5' + alt-6 = 'workspace 6' + alt-7 = 'workspace 7' + alt-8 = 'workspace 8' + alt-9 = 'workspace 9' + alt-a = 'workspace A' # In your config, you can drop workspace bindings that you don't need + alt-b = 'workspace B' + alt-c = 'workspace C' + alt-d = 'workspace D' + alt-e = 'workspace E' + alt-f = 'workspace F' + alt-g = 'workspace G' + alt-i = 'workspace I' + alt-m = 'workspace M' + alt-n = 'workspace N' + alt-o = 'workspace O' + alt-p = 'workspace P' + alt-q = 'workspace Q' + alt-r = 'workspace R' + alt-s = 'workspace S' + alt-t = 'workspace T' + alt-u = 'workspace U' + alt-v = 'workspace V' + alt-w = 'workspace W' + alt-x = 'workspace X' + alt-y = 'workspace Y' + alt-z = 'workspace Z' + + # See: https://nikitabobko.github.io/AeroSpace/commands#move-node-to-workspace + alt-shift-1 = 'move-node-to-workspace 1' + alt-shift-2 = 'move-node-to-workspace 2' + alt-shift-3 = 'move-node-to-workspace 3' + alt-shift-4 = 'move-node-to-workspace 4' + alt-shift-5 = 'move-node-to-workspace 5' + alt-shift-6 = 'move-node-to-workspace 6' + alt-shift-7 = 'move-node-to-workspace 7' + alt-shift-8 = 'move-node-to-workspace 8' + alt-shift-9 = 'move-node-to-workspace 9' + alt-shift-a = 'move-node-to-workspace A' + alt-shift-b = 'move-node-to-workspace B' + alt-shift-c = 'move-node-to-workspace C' + alt-shift-d = 'move-node-to-workspace D' + alt-shift-e = 'move-node-to-workspace E' + alt-shift-f = 'move-node-to-workspace F' + alt-shift-g = 'move-node-to-workspace G' + alt-shift-i = 'move-node-to-workspace I' + alt-shift-m = 'move-node-to-workspace M' + alt-shift-n = 'move-node-to-workspace N' + alt-shift-o = 'move-node-to-workspace O' + alt-shift-p = 'move-node-to-workspace P' + alt-shift-q = 'move-node-to-workspace Q' + alt-shift-r = 'move-node-to-workspace R' + alt-shift-s = 'move-node-to-workspace S' + alt-shift-t = 'move-node-to-workspace T' + alt-shift-u = 'move-node-to-workspace U' + alt-shift-v = 'move-node-to-workspace V' + alt-shift-w = 'move-node-to-workspace W' + alt-shift-x = 'move-node-to-workspace X' + alt-shift-y = 'move-node-to-workspace Y' + alt-shift-z = 'move-node-to-workspace Z' + + # See: https://nikitabobko.github.io/AeroSpace/commands#workspace-back-and-forth + alt-tab = 'workspace-back-and-forth' + # See: https://nikitabobko.github.io/AeroSpace/commands#move-workspace-to-monitor + alt-shift-tab = 'move-workspace-to-monitor --wrap-around next' + + # See: https://nikitabobko.github.io/AeroSpace/commands#mode + alt-shift-semicolon = 'mode service' + + # 'service' binding mode declaration. + # See: https://nikitabobko.github.io/AeroSpace/guide#binding-modes + [mode.service.binding] + esc = ['reload-config', 'mode main'] + r = ['flatten-workspace-tree', 'mode main'] # reset layout + f = ['layout floating tiling', 'mode main'] # Toggle between floating and tiling layout + backspace = ['close-all-windows-but-current', 'mode main'] + + # sticky is not yet supported https://github.com/nikitabobko/AeroSpace/issues/2 + #s = ['layout sticky tiling', 'mode main'] + + alt-shift-h = ['join-with left', 'mode main'] + alt-shift-j = ['join-with down', 'mode main'] + alt-shift-k = ['join-with up', 'mode main'] + alt-shift-l = ['join-with right', 'mode main'] + + down = 'volume down' + up = 'volume up' + shift-down = ['volume set 0', 'mode main'] + ''; + }; + } + ]; + + }; + }; +} +# https://github.com/dustinlyons/nixos-config/blob/8a14e1f0da074b3f9060e8c822164d922bfeec29/modules/darwin/home-manager.nix#L74 diff --git a/nix/macbook.nix b/nix/macbook.nix index 859f7cf89..aa7ebbcb8 100644 --- a/nix/macbook.nix +++ b/nix/macbook.nix @@ -82,7 +82,7 @@ { # Build darwin flake using: # $ darwin-rebuild build --flake .#simple - darwinConfigurations."Parth-MBP" = nix-darwin.lib.darwinSystem { + darwinConfigurations.default = nix-darwin.lib.darwinSystem { modules = [ configuration From 76c07c9c2e84285fdd267a52a6b27ef7a2cffdd7 Mon Sep 17 00:00:00 2001 From: parth Date: Tue, 16 Sep 2025 16:04:02 -0400 Subject: [PATCH 108/123] dock? --- nix/macbook.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nix/macbook.nix b/nix/macbook.nix index aa7ebbcb8..efb3694ab 100644 --- a/nix/macbook.nix +++ b/nix/macbook.nix @@ -53,9 +53,12 @@ # $ darwin-rebuild changelog system.stateVersion = 6; + system.defaults.dock.autohide = true; + # The platform the configuration will be used on. nixpkgs.hostPlatform = "aarch64-darwin"; + programs.fish = { enable = true; shellInit = '' From 141759275dd1c279447bdaf55a717828977bb688 Mon Sep 17 00:00:00 2001 From: parth Date: Fri, 19 Sep 2025 12:38:28 -0400 Subject: [PATCH 109/123] ssh --- nix/common/headless.nix | 3 +++ nix/server.nix | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/nix/common/headless.nix b/nix/common/headless.nix index 56e4fcdc1..61eee1d1d 100644 --- a/nix/common/headless.nix +++ b/nix/common/headless.nix @@ -45,6 +45,7 @@ in enable = true; userName = "parth"; userEmail = "parth@mehrotra.me"; + lfs.enable = true; extraConfig = { push.default = "current"; }; @@ -135,6 +136,8 @@ in google-cloud-sdk lockbook + + git-lfs ]; }; diff --git a/nix/server.nix b/nix/server.nix index 3c706f869..79b366ea9 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -46,4 +46,12 @@ LIBRARY_PATH = "${pkgs.libxkbcommon}/lib"; }; }; + + users.users.parth = { + openssh.authorizedKeys.keys = [ + "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDMjLtM4DKvdCdgajSHcEwFsG2DSdgJ4I4IB4t53YhW8j9iwzmh4wSGQ/lpEiXenfByoeDT6m5idVqMVzTaQScMxKoo+CMcu3gQhj1lK+QKbdCGtXZe6fI8KAJklJxLL11FB8dh3C7LNqI7IQJQD6b2YBqnT1sNlXloNu/ZtOvrt4nOBNrubAipXnTBJDp77ZJfLEv+mlG7cgLWBpTlHTIL5iFfr4sm3hQwqK393FGamVFm6IefEdI8kYXtTHo1WX35XCAgblGjyAk/ic6Xp1va/l6NQRvdYJVaCeI93xWQQ0xuOj7WoicVF6sKrg5HRMYR/YLFLUonSkZeNEXkkgWSpQdwIiYllz4DqFtMnZ6iZKpg4ZmVXFikG2eifCub48YQL31mwGzmpDMfdHjP92CyjgOsJtG23uyEX6RA+3XLrkoSowFql2FwKGV+bQ5ymfzIIwdS8FSZootgDP+KVFG1CJhffcHdQ8TosBqjqZ/NkNhvee1jwbCO/uR4Qv5yxL0=" + ]; + }; } + + From b909434d6e635a24e4288fe6ccbe3f5da334ac6e Mon Sep 17 00:00:00 2001 From: parth Date: Fri, 19 Sep 2025 12:39:38 -0400 Subject: [PATCH 110/123] no more password auth --- nix/server.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/server.nix b/nix/server.nix index 79b366ea9..33be575e6 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -16,7 +16,7 @@ enable = true; settings = { PermitRootLogin = "yes"; - PasswordAuthentication = true; + PasswordAuthentication = false; }; }; From 1927d2a91bf168ae066229dd9630e29a4820fe5d Mon Sep 17 00:00:00 2001 From: parth Date: Fri, 19 Sep 2025 12:42:39 -0400 Subject: [PATCH 111/123] adam --- nix/server.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nix/server.nix b/nix/server.nix index 33be575e6..84c815cc7 100644 --- a/nix/server.nix +++ b/nix/server.nix @@ -52,6 +52,16 @@ "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDMjLtM4DKvdCdgajSHcEwFsG2DSdgJ4I4IB4t53YhW8j9iwzmh4wSGQ/lpEiXenfByoeDT6m5idVqMVzTaQScMxKoo+CMcu3gQhj1lK+QKbdCGtXZe6fI8KAJklJxLL11FB8dh3C7LNqI7IQJQD6b2YBqnT1sNlXloNu/ZtOvrt4nOBNrubAipXnTBJDp77ZJfLEv+mlG7cgLWBpTlHTIL5iFfr4sm3hQwqK393FGamVFm6IefEdI8kYXtTHo1WX35XCAgblGjyAk/ic6Xp1va/l6NQRvdYJVaCeI93xWQQ0xuOj7WoicVF6sKrg5HRMYR/YLFLUonSkZeNEXkkgWSpQdwIiYllz4DqFtMnZ6iZKpg4ZmVXFikG2eifCub48YQL31mwGzmpDMfdHjP92CyjgOsJtG23uyEX6RA+3XLrkoSowFql2FwKGV+bQ5ymfzIIwdS8FSZootgDP+KVFG1CJhffcHdQ8TosBqjqZ/NkNhvee1jwbCO/uR4Qv5yxL0=" ]; }; + + users.users.adam = { + isNormalUser = true; + home = "/home/adam"; + description = "Adam's account"; + extraGroups = [ "wheel" "networkmanager" ]; + openssh.authorizedKeys.keys = [ + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBLMux74pTJaMlfX/sqBnggtRjwoIMgp2Glg6puQZxgC aew31gcmuy@gmail.com" + ]; + }; } From 912d57f5c64100b22a8e6695078bb3b4e7ebcaab Mon Sep 17 00:00:00 2001 From: parth Date: Tue, 30 Sep 2025 12:32:02 -0400 Subject: [PATCH 112/123] +gimp --- nix/macbook.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nix/macbook.nix b/nix/macbook.nix index efb3694ab..0b6a08592 100644 --- a/nix/macbook.nix +++ b/nix/macbook.nix @@ -31,6 +31,7 @@ environment.systemPackages = with pkgs; [ helix + ffmpeg_6 fzf @@ -107,6 +108,7 @@ }; casks = [ + "gimp" "wezterm" "google-chrome" "nikitabobko/tap/aerospace" From c5c9154e1ffca28cef5ed8848e426d222356d8b0 Mon Sep 17 00:00:00 2001 From: parth Date: Thu, 2 Oct 2025 14:45:30 -0400 Subject: [PATCH 113/123] finally some peace --- nix/flake.nix | 11 +- nix/macbook.nix | 415 ------------------------------------------------ 2 files changed, 9 insertions(+), 417 deletions(-) delete mode 100644 nix/macbook.nix diff --git a/nix/flake.nix b/nix/flake.nix index aa7ebbcb8..3e66d0576 100644 --- a/nix/flake.nix +++ b/nix/flake.nix @@ -31,6 +31,7 @@ environment.systemPackages = with pkgs; [ helix + ffmpeg_6 fzf @@ -53,14 +54,19 @@ # $ darwin-rebuild changelog system.stateVersion = 6; + system.defaults.dock.autohide = true; + # The platform the configuration will be used on. nixpkgs.hostPlatform = "aarch64-darwin"; + programs.fish = { enable = true; - shellInit = '' + interactiveShellInit = '' fish_vi_key_bindings - set -gx PATH $HOME/.cargo/bin $PATH + set -Ux PATH $HOME/.cargo/bin $PATH + set -gx EDITOR nvim + set -gx VISUAL nvim ''; }; @@ -104,6 +110,7 @@ }; casks = [ + "gimp" "wezterm" "google-chrome" "nikitabobko/tap/aerospace" diff --git a/nix/macbook.nix b/nix/macbook.nix deleted file mode 100644 index 0b6a08592..000000000 --- a/nix/macbook.nix +++ /dev/null @@ -1,415 +0,0 @@ -{ - description = "Example nix-darwin system flake"; - - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - nix-darwin.url = "github:nix-darwin/nix-darwin/master"; - nix-darwin.inputs.nixpkgs.follows = "nixpkgs"; - home-manager.url = "github:nix-community/home-manager"; - home-manager.inputs.nixpkgs.follows = "nixpkgs"; - nix-homebrew.url = "github:zhaofengli-wip/nix-homebrew"; - }; - - outputs = - inputs@{ self - , nix-darwin - , nixpkgs - , home-manager - , nix-homebrew - , - }: - let - configuration = - { pkgs, ... }: - { - nixpkgs.config.allowUnfree = true; - nix.settings.experimental-features = "nix-command flakes"; - homebrew.enable = true; - - # Set Git commit hash for darwin-version. - system.configurationRevision = self.rev or self.dirtyRev or null; - - environment.systemPackages = with pkgs; [ - helix - ffmpeg_6 - - fzf - - lua-language-server - zola - nixpkgs-fmt - nixd - rust-analyzer - rustup - lockbook - # listing clang here makes the macOS clang act strange - ]; - - fonts.packages = with pkgs; [ - nerd-fonts.jetbrains-mono - ]; - - - # Used for backwards compatibility, please read the changelog before changing. - # $ darwin-rebuild changelog - system.stateVersion = 6; - - system.defaults.dock.autohide = true; - - # The platform the configuration will be used on. - nixpkgs.hostPlatform = "aarch64-darwin"; - - - programs.fish = { - enable = true; - shellInit = '' - fish_vi_key_bindings - set -gx PATH $HOME/.cargo/bin $PATH - ''; - }; - - users.knownUsers = [ "parth" ]; - users.users.parth.uid = 501; - system.primaryUser = "parth"; - - users.users.parth = { - home = "/Users/parth"; - shell = pkgs.fish; - }; - - system.keyboard = { - enableKeyMapping = true; - remapCapsLockToEscape = true; - }; - }; - in - { - # Build darwin flake using: - # $ darwin-rebuild build --flake .#simple - darwinConfigurations.default = nix-darwin.lib.darwinSystem { - modules = [ - configuration - - nix-homebrew.darwinModules.nix-homebrew - { - nix-homebrew = { - enable = true; - user = "parth"; - }; - - homebrew = { - enable = true; - - masApps = { - "XCode" = 497799835; - "Final Cut Pro" = 424389933; - "Lockbook" = 1526775001; - "Lightroom" = 1451544217; - }; - - casks = [ - "gimp" - "wezterm" - "google-chrome" - "nikitabobko/tap/aerospace" - "insta360-studio" - "adobe-creative-cloud" - "discord" - "1password" - "spotify" - "chatgpt" - "makemkv" - "musescore" - ]; - }; - } - - home-manager.darwinModules.home-manager - { - home-manager.useGlobalPkgs = true; - home-manager.backupFileExtension = "backup"; - home-manager.useUserPackages = true; - home-manager.users.parth = { pkgs, lib, ... }: { - home.stateVersion = "24.05"; - - programs.git = { - enable = true; - userName = "parth"; - userEmail = "parth@mehrotra.me"; - extraConfig = { - push.default = "current"; - }; - }; - - programs.neovim = { - enable = true; - plugins = with pkgs.vimPlugins; [ - nvim-web-devicons - telescope-nvim - nvim-cmp - cmp-nvim-lsp - vim-illuminate - lualine-nvim - lsp-status-nvim - - nvim-tree-lua - nvim-lspconfig - luasnip - # todo replace "FabijanZulj/blame.nvim", - ]; - - extraPackages = with pkgs; [ - lua-language-server - # i would like to configure this here but rustup does some wack shit - # rust-analyzer - ]; - - # extraLuaConfig = '' - # dofile("/home/parth/dotfiles/nvim/init.lua") - # ''; - }; - - xdg.configFile = { - "nvim" = { - source = /Users/parth/dotfiles/nvim; - recursive = true; - }; - - "helix" = { - source = /Users/parth/dotfiles/helix; - recursive = true; - }; - - "aerospace" = { - source = /Users/parth/dotfiles/aerospace; - recursive = true; - }; - - "wezterm" = { - source = /Users/parth/dotfiles/wezterm; - recursive = true; - }; - }; - - home.file.".aerospace.toml".text = '' - # Place a copy of this config to ~/.aerospace.toml - # After that, you can edit ~/.aerospace.toml to your liking - - # You can use it to add commands that run after login to macOS user session. - # 'start-at-login' needs to be 'true' for 'after-login-command' to work - # Available commands: https://nikitabobko.github.io/AeroSpace/commands - after-login-command = [] - - # You can use it to add commands that run after AeroSpace startup. - # 'after-startup-command' is run after 'after-login-command' - # Available commands : https://nikitabobko.github.io/AeroSpace/commands - after-startup-command = [] - - # Start AeroSpace at login - start-at-login = false - - # Normalizations. See: https://nikitabobko.github.io/AeroSpace/guide#normalization - enable-normalization-flatten-containers = true - enable-normalization-opposite-orientation-for-nested-containers = true - - # See: https://nikitabobko.github.io/AeroSpace/guide#layouts - # The 'accordion-padding' specifies the size of accordion padding - # You can set 0 to disable the padding feature - accordion-padding = 30 - - # Possible values: tiles|accordion - default-root-container-layout = 'tiles' - - # Possible values: horizontal|vertical|auto - # 'auto' means: wide monitor (anything wider than high) gets horizontal orientation, - # tall monitor (anything higher than wide) gets vertical orientation - default-root-container-orientation = 'auto' - - # Mouse follows focus when focused monitor changes - # Drop it from your config, if you don't like this behavior - # See https://nikitabobko.github.io/AeroSpace/guide#on-focus-changed-callbacks - # See https://nikitabobko.github.io/AeroSpace/commands#move-mouse - # Fallback value (if you omit the key): on-focused-monitor-changed = [] - on-focused-monitor-changed = ['move-mouse monitor-lazy-center'] - - # You can effectively turn off macOS "Hide application" (cmd-h) feature by toggling this flag - # Useful if you don't use this macOS feature, but accidentally hit cmd-h or cmd-alt-h key - # Also see: https://nikitabobko.github.io/AeroSpace/goodies#disable-hide-app - automatically-unhide-macos-hidden-apps = false - - # Possible values: (qwerty|dvorak|colemak) - # See https://nikitabobko.github.io/AeroSpace/guide#key-mapping - [key-mapping] - preset = 'qwerty' - - # Gaps between windows (inner-*) and between monitor edges (outer-*). - # Possible values: - # - Constant: gaps.outer.top = 8 - # - Per monitor: gaps.outer.top = [{ monitor.main = 16 }, { monitor."some-pattern" = 32 }, 24] - # In this example, 24 is a default value when there is no match. - # Monitor pattern is the same as for 'workspace-to-monitor-force-assignment'. - # See: - # https://nikitabobko.github.io/AeroSpace/guide#assign-workspaces-to-monitors - [gaps] - inner.horizontal = 6 - inner.vertical = 6 - outer.left = 6 - outer.bottom = 6 - outer.top = 6 - outer.right = 6 - - # 'main' binding mode declaration - # See: https://nikitabobko.github.io/AeroSpace/guide#binding-modes - # 'main' binding mode must be always presented - # Fallback value (if you omit the key): mode.main.binding = {} - [mode.main.binding] - - # All possible keys: - # - Letters. a, b, c, ..., z - # - Numbers. 0, 1, 2, ..., 9 - # - Keypad numbers. keypad0, keypad1, keypad2, ..., keypad9 - # - F-keys. f1, f2, ..., f20 - # - Special keys. minus, equal, period, comma, slash, backslash, quote, semicolon, - # backtick, leftSquareBracket, rightSquareBracket, space, enter, esc, - # backspace, tab, pageUp, pageDown, home, end, forwardDelete, - # sectionSign (ISO keyboards only, european keyboards only) - # - Keypad special. keypadClear, keypadDecimalMark, keypadDivide, keypadEnter, keypadEqual, - # keypadMinus, keypadMultiply, keypadPlus - # - Arrows. left, down, up, right - - # All possible modifiers: cmd, alt, ctrl, shift - - # All possible commands: https://nikitabobko.github.io/AeroSpace/commands - - # See: https://nikitabobko.github.io/AeroSpace/commands#exec-and-forget - # You can uncomment the following lines to open up terminal with alt + enter shortcut - # (like in i3) - # alt-enter = '''exec-and-forget osascript -e ' - # tell application "Terminal" - # do script - # activate - # end tell' - # ''' - - # See: https://nikitabobko.github.io/AeroSpace/commands#layout - alt-slash = 'layout tiles horizontal vertical' - alt-comma = 'layout accordion horizontal vertical' - - # See: https://nikitabobko.github.io/AeroSpace/commands#focus - alt-h = 'focus left' - alt-j = 'focus down' - alt-k = 'focus up' - alt-l = 'focus right' - - # See: https://nikitabobko.github.io/AeroSpace/commands#move - alt-shift-h = 'move left' - alt-shift-j = 'move down' - alt-shift-k = 'move up' - alt-shift-l = 'move right' - - # See: https://nikitabobko.github.io/AeroSpace/commands#resize - alt-minus = 'resize smart -50' - alt-equal = 'resize smart +50' - - # See: https://nikitabobko.github.io/AeroSpace/commands#workspace - alt-1 = 'workspace 1' - alt-2 = 'workspace 2' - alt-3 = 'workspace 3' - alt-4 = 'workspace 4' - alt-5 = 'workspace 5' - alt-6 = 'workspace 6' - alt-7 = 'workspace 7' - alt-8 = 'workspace 8' - alt-9 = 'workspace 9' - alt-a = 'workspace A' # In your config, you can drop workspace bindings that you don't need - alt-b = 'workspace B' - alt-c = 'workspace C' - alt-d = 'workspace D' - alt-e = 'workspace E' - alt-f = 'workspace F' - alt-g = 'workspace G' - alt-i = 'workspace I' - alt-m = 'workspace M' - alt-n = 'workspace N' - alt-o = 'workspace O' - alt-p = 'workspace P' - alt-q = 'workspace Q' - alt-r = 'workspace R' - alt-s = 'workspace S' - alt-t = 'workspace T' - alt-u = 'workspace U' - alt-v = 'workspace V' - alt-w = 'workspace W' - alt-x = 'workspace X' - alt-y = 'workspace Y' - alt-z = 'workspace Z' - - # See: https://nikitabobko.github.io/AeroSpace/commands#move-node-to-workspace - alt-shift-1 = 'move-node-to-workspace 1' - alt-shift-2 = 'move-node-to-workspace 2' - alt-shift-3 = 'move-node-to-workspace 3' - alt-shift-4 = 'move-node-to-workspace 4' - alt-shift-5 = 'move-node-to-workspace 5' - alt-shift-6 = 'move-node-to-workspace 6' - alt-shift-7 = 'move-node-to-workspace 7' - alt-shift-8 = 'move-node-to-workspace 8' - alt-shift-9 = 'move-node-to-workspace 9' - alt-shift-a = 'move-node-to-workspace A' - alt-shift-b = 'move-node-to-workspace B' - alt-shift-c = 'move-node-to-workspace C' - alt-shift-d = 'move-node-to-workspace D' - alt-shift-e = 'move-node-to-workspace E' - alt-shift-f = 'move-node-to-workspace F' - alt-shift-g = 'move-node-to-workspace G' - alt-shift-i = 'move-node-to-workspace I' - alt-shift-m = 'move-node-to-workspace M' - alt-shift-n = 'move-node-to-workspace N' - alt-shift-o = 'move-node-to-workspace O' - alt-shift-p = 'move-node-to-workspace P' - alt-shift-q = 'move-node-to-workspace Q' - alt-shift-r = 'move-node-to-workspace R' - alt-shift-s = 'move-node-to-workspace S' - alt-shift-t = 'move-node-to-workspace T' - alt-shift-u = 'move-node-to-workspace U' - alt-shift-v = 'move-node-to-workspace V' - alt-shift-w = 'move-node-to-workspace W' - alt-shift-x = 'move-node-to-workspace X' - alt-shift-y = 'move-node-to-workspace Y' - alt-shift-z = 'move-node-to-workspace Z' - - # See: https://nikitabobko.github.io/AeroSpace/commands#workspace-back-and-forth - alt-tab = 'workspace-back-and-forth' - # See: https://nikitabobko.github.io/AeroSpace/commands#move-workspace-to-monitor - alt-shift-tab = 'move-workspace-to-monitor --wrap-around next' - - # See: https://nikitabobko.github.io/AeroSpace/commands#mode - alt-shift-semicolon = 'mode service' - - # 'service' binding mode declaration. - # See: https://nikitabobko.github.io/AeroSpace/guide#binding-modes - [mode.service.binding] - esc = ['reload-config', 'mode main'] - r = ['flatten-workspace-tree', 'mode main'] # reset layout - f = ['layout floating tiling', 'mode main'] # Toggle between floating and tiling layout - backspace = ['close-all-windows-but-current', 'mode main'] - - # sticky is not yet supported https://github.com/nikitabobko/AeroSpace/issues/2 - #s = ['layout sticky tiling', 'mode main'] - - alt-shift-h = ['join-with left', 'mode main'] - alt-shift-j = ['join-with down', 'mode main'] - alt-shift-k = ['join-with up', 'mode main'] - alt-shift-l = ['join-with right', 'mode main'] - - down = 'volume down' - up = 'volume up' - shift-down = ['volume set 0', 'mode main'] - ''; - }; - } - ]; - - }; - }; -} -# https://github.com/dustinlyons/nixos-config/blob/8a14e1f0da074b3f9060e8c822164d922bfeec29/modules/darwin/home-manager.nix#L74 From e5d28dfd24f1a6d00868c2ddfd643b50f1236e2a Mon Sep 17 00:00:00 2001 From: parth Date: Mon, 6 Oct 2025 15:20:31 -0400 Subject: [PATCH 114/123] correct path --- nix/flake.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nix/flake.nix b/nix/flake.nix index 3e66d0576..62e1862ff 100644 --- a/nix/flake.nix +++ b/nix/flake.nix @@ -64,7 +64,7 @@ enable = true; interactiveShellInit = '' fish_vi_key_bindings - set -Ux PATH $HOME/.cargo/bin $PATH + set -gx PATH $HOME/.cargo/bin $PATH set -gx EDITOR nvim set -gx VISUAL nvim ''; @@ -110,6 +110,7 @@ }; casks = [ + "zed" "gimp" "wezterm" "google-chrome" From bbddb7380e914c0297ca3105a297ce392977ded1 Mon Sep 17 00:00:00 2001 From: parth Date: Mon, 20 Oct 2025 23:39:20 -0400 Subject: [PATCH 115/123] obs & amd, sway colors, nvim markdown render --- nix/common/gui.nix | 9 +- nix/common/headless.nix | 24 +++- nix/flake.nix | 8 +- nix/workstation.nix | 5 +- nvim/lua/packages.lua | 2 + sway/config | 271 +++++++++++++++++++++------------------- wezterm/wezterm.lua | 9 +- 7 files changed, 187 insertions(+), 141 deletions(-) diff --git a/nix/common/gui.nix b/nix/common/gui.nix index 4f04a8cb6..8be653dbf 100644 --- a/nix/common/gui.nix +++ b/nix/common/gui.nix @@ -34,17 +34,24 @@ fonts.packages = [ ] ++ builtins.filter lib.attrsets.isDerivation (builtins.attrValues pkgs.nerd-fonts); users.users.parth.packages = with pkgs; [ + zed-editor _1password-gui google-chrome discord spotify wezterm lockbook-desktop - obs-studio nautilus vlc ]; + programs.obs-studio = { + enable = true; + plugins = with pkgs.obs-studio-plugins; [ + obs-vaapi #optional AMD hardware acceleration + ]; + }; + programs._1password-gui.enable = true; programs.chromium = { enable = true; diff --git a/nix/common/headless.nix b/nix/common/headless.nix index 61eee1d1d..145bd42ab 100644 --- a/nix/common/headless.nix +++ b/nix/common/headless.nix @@ -30,9 +30,11 @@ in programs.fish = { enable = true; - shellInit = '' - fish_vi_key_bindings + interactiveShellInit = '' + fish_vi_key_bindings set -gx PATH $HOME/.cargo/bin $PATH + set -gx EDITOR nvim + set -gx VISUAL nvim ''; }; users.defaultUserShell = pkgs.fish; @@ -65,6 +67,7 @@ in nvim-tree-lua nvim-lspconfig luasnip + render-markdown-nvim # todo replace "FabijanZulj/blame.nvim", ]; @@ -121,6 +124,7 @@ in helix fzf + eza xclip ripgrep @@ -141,7 +145,23 @@ in ]; }; + environment.variables = { EDITOR = "nvim"; VISUAL = "nvim"; }; + programs.git.enable = true; nixpkgs.config.allowUnfree = true; system.stateVersion = "24.05"; + + fileSystems."/truenas" = { + device = "//192.168.12.2/parth-dataset"; + fsType = "cifs"; + options = [ + "credentials=/etc/nixos/smb-secrets" + "uid=1000" + "gid=100" + "vers=3.0" + "x-systemd.automount" + "noauto" + ]; + }; + } diff --git a/nix/flake.nix b/nix/flake.nix index 62e1862ff..48bcb30aa 100644 --- a/nix/flake.nix +++ b/nix/flake.nix @@ -63,10 +63,10 @@ programs.fish = { enable = true; interactiveShellInit = '' - fish_vi_key_bindings - set -gx PATH $HOME/.cargo/bin $PATH - set -gx EDITOR nvim - set -gx VISUAL nvim + fish_vi_key_bindings + set -gx PATH $HOME/.cargo/bin $PATH + set -gx EDITOR nvim + set -gx VISUAL nvim ''; }; diff --git a/nix/workstation.nix b/nix/workstation.nix index a3c32668e..c789c7f60 100644 --- a/nix/workstation.nix +++ b/nix/workstation.nix @@ -1,4 +1,4 @@ -{ config, ... }: +{ config, pkgs, ... }: { networking.hostName = "parth-workstation-nix"; @@ -8,6 +8,9 @@ hardware.graphics = { enable = true; enable32Bit = true; + extraPackages = with pkgs; [ + rocmPackages.clr.icd + ]; }; imports = [ diff --git a/nvim/lua/packages.lua b/nvim/lua/packages.lua index a61bfedf7..8100642b7 100644 --- a/nvim/lua/packages.lua +++ b/nvim/lua/packages.lua @@ -103,5 +103,7 @@ lspconfig.nixd.setup { }, } +require('render-markdown').enable() + -- blame -- require("blame").setup() diff --git a/sway/config b/sway/config index fc0a1ee1f..e212d8170 100644 --- a/sway/config +++ b/sway/config @@ -13,6 +13,8 @@ set $right l bindsym $mod+Return exec wezterm bindsym $mod+backslash exec google-chrome-stable bindsym $mod+Space exec wmenu-run +bindsym $mod+d exec discord +bindsym $mod+shift+t exec wezterm start bash -c 'lockbook edit todo.md && lockbook sync && read -p "enter to cont"' bindsym $mod+o exec lockbook-desktop set $A 'LG Electronics LG ULTRAGEAR 301NTZNBU797' @@ -23,135 +25,97 @@ output $A mode 3840x2160 position 3335,1420 output $B mode 1920x1200 position 4038,3580 output $C mode 3840x2160 position 1175,407 transform 90 -# todo: unclear whether this worked or not until restart -workspace 1 $A -workspace 2 $B -workspace 3 $C - -### Idle configuration -# -# Example configuration: -# -# exec swayidle -w \ -# timeout 300 'swaylock -f -c 000000' \ -# timeout 600 'swaymsg "output * power off"' resume 'swaymsg "output * power on"' \ -# before-sleep 'swaylock -f -c 000000' -# -# This will lock your screen after 300 seconds of inactivity, then turn off -# your displays after another 300 seconds, and turn your screens back on when -# resumed. It will also lock your screen before your computer goes to sleep. - -### Input configuration -# -# Example configuration: -# -# input "2:14:SynPS/2_Synaptics_TouchPad" { -# dwt enabled -# tap enabled -# natural_scroll enabled -# middle_emulation enabled -# } -# -# You can get the names of your inputs by running: swaymsg -t get_inputs -# Read `man 5 sway-input` for more information about this section. - -### Key bindings -# -# Basics: -# - - # Kill focused window - bindsym $mod+Shift+q kill - - - # Drag floating windows by holding down $mod and left mouse button. - # Resize them with right mouse button + $mod. - # Despite the name, also works for non-floating windows. - # Change normal to inverse to use left mouse button for resizing and right - # mouse button for dragging. - floating_modifier $mod normal - - # Reload the configuration file - bindsym $mod+Shift+c reload - - # Exit sway (logs you out of your Wayland session) - bindsym $mod+Shift+e exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -B 'Yes, exit sway' 'swaymsg exit' -# -# Moving around: -# - # Move your focus around - bindsym $mod+$left focus left - bindsym $mod+$down focus down - bindsym $mod+$up focus up - bindsym $mod+$right focus right - # Or use $mod+[up|down|left|right] - bindsym $mod+Left focus left - bindsym $mod+Down focus down - bindsym $mod+Up focus up - bindsym $mod+Right focus right - - # Move the focused window with the same, but add Shift - bindsym $mod+Shift+$left move left - bindsym $mod+Shift+$down move down - bindsym $mod+Shift+$up move up - bindsym $mod+Shift+$right move right - # Ditto, with arrow keys - bindsym $mod+Shift+Left move left - bindsym $mod+Shift+Down move down - bindsym $mod+Shift+Up move up - bindsym $mod+Shift+Right move right +exec swayidle -w \ + timeout 300 'swaylock -f -c 000000' \ + timeout 600 'swaymsg "output * power off"' resume 'swaymsg "output * power on"' \ + before-sleep 'swaylock -f -c 000000' + +# Kill focused window +bindsym $mod+Shift+q kill + +# Drag floating windows by holding down $mod and left mouse button. +# Resize them with right mouse button + $mod. +# Despite the name, also works for non-floating windows. +# Change normal to inverse to use left mouse button for resizing and right +# mouse button for dragging. +floating_modifier $mod normal + +# Reload the configuration file +bindsym $mod+Shift+c reload + +# Exit sway (logs you out of your Wayland session) +bindsym $mod+Shift+e exec swaynag -t warning -m 'You pressed the exit shortcut. Do you really want to exit sway? This will end your Wayland session.' -B 'Yes, exit sway' 'swaymsg exit' + +# Move your focus around +bindsym $mod+$left focus left +bindsym $mod+$down focus down +bindsym $mod+$up focus up +bindsym $mod+$right focus right +# Or use $mod+[up|down|left|right] +bindsym $mod+Left focus left +bindsym $mod+Down focus down +bindsym $mod+Up focus up +bindsym $mod+Right focus right + +# Move the focused window with the same, but add Shift +bindsym $mod+Shift+$left move left +bindsym $mod+Shift+$down move down +bindsym $mod+Shift+$up move up +bindsym $mod+Shift+$right move right +# Ditto, with arrow keys +bindsym $mod+Shift+Left move left +bindsym $mod+Shift+Down move down +bindsym $mod+Shift+Up move up +bindsym $mod+Shift+Right move right # # Workspaces: # - # Switch to workspace - bindsym $mod+1 workspace number 1 - bindsym $mod+2 workspace number 2 - bindsym $mod+3 workspace number 3 - bindsym $mod+4 workspace number 4 - bindsym $mod+5 workspace number 5 - bindsym $mod+6 workspace number 6 - bindsym $mod+7 workspace number 7 - bindsym $mod+8 workspace number 8 - bindsym $mod+9 workspace number 9 - bindsym $mod+0 workspace number 10 - # Move focused container to workspace - bindsym $mod+Shift+1 move container to workspace number 1 - bindsym $mod+Shift+2 move container to workspace number 2 - bindsym $mod+Shift+3 move container to workspace number 3 - bindsym $mod+Shift+4 move container to workspace number 4 - bindsym $mod+Shift+5 move container to workspace number 5 - bindsym $mod+Shift+6 move container to workspace number 6 - bindsym $mod+Shift+7 move container to workspace number 7 - bindsym $mod+Shift+8 move container to workspace number 8 - bindsym $mod+Shift+9 move container to workspace number 9 - bindsym $mod+Shift+0 move container to workspace number 10 - # Note: workspaces can have any name you want, not just numbers. - # We just use 1-10 as the default. -# -# Layout stuff: -# - # You can "split" the current object of your focus with - # $mod+b or $mod+v, for horizontal and vertical splits - # respectively. - bindsym $mod+b splith - bindsym $mod+v splitv - # Switch the current container between different layout styles - bindsym $mod+s layout stacking - bindsym $mod+w layout tabbed - bindsym $mod+e layout toggle split - - # Make the current focus fullscreen - bindsym $mod+f fullscreen - - # Toggle the current focus between tiling and floating mode - bindsym $mod+Shift+space floating toggle - - # Swap focus between the tiling area and the floating area - bindsym $mod+t focus mode_toggle - - # Move focus to the parent container - bindsym $mod+a focus parent +# Switch to workspace +bindsym $mod+1 workspace number 1 +bindsym $mod+2 workspace number 2 +bindsym $mod+3 workspace number 3 +bindsym $mod+4 workspace number 4 +bindsym $mod+5 workspace number 5 +bindsym $mod+6 workspace number 6 +bindsym $mod+7 workspace number 7 +bindsym $mod+8 workspace number 8 +bindsym $mod+9 workspace number 9 +bindsym $mod+0 workspace number 10 +# Move focused container to workspace +bindsym $mod+Shift+1 move container to workspace number 1 +bindsym $mod+Shift+2 move container to workspace number 2 +bindsym $mod+Shift+3 move container to workspace number 3 +bindsym $mod+Shift+4 move container to workspace number 4 +bindsym $mod+Shift+5 move container to workspace number 5 +bindsym $mod+Shift+6 move container to workspace number 6 +bindsym $mod+Shift+7 move container to workspace number 7 +bindsym $mod+Shift+8 move container to workspace number 8 +bindsym $mod+Shift+9 move container to workspace number 9 +bindsym $mod+Shift+0 move container to workspace number 10 + +# You can "split" the current object of your focus with +# $mod+b or $mod+v, for horizontal and vertical splits +# respectively. +bindsym $mod+b splith +bindsym $mod+v splitv + +# Switch the current container between different layout styles +bindsym $mod+s layout stacking +bindsym $mod+w layout tabbed +bindsym $mod+e layout toggle split + +# Make the current focus fullscreen +bindsym $mod+f fullscreen + +# Toggle the current focus between tiling and floating mode +bindsym $mod+Shift+space floating toggle + +# Swap focus between the tiling area and the floating area +bindsym $mod+t focus mode_toggle + +# Move focus to the parent container +bindsym $mod+a focus parent # # Scratchpad: # @@ -206,18 +170,69 @@ bindsym $mod+r mode "resize" # Status Bar: # # Read `man 5 sway-bar` for more information about this section. + +set $grey #808080 +set $red #FF6680 +set $green #67E4B6 +set $yellow #FFDB70 +set $blue #66B2FF +set $magenta #AC8CD9 +set $cyan #6EECF7 +set $white #F0F0F0 + bar { position top # When the status_command prints a new line to stdout, swaybar updates. # The default just shows the current date and time. - status_command while date +'%Y-%m-%d %X'; do sleep 1; done + status_command while date +'%Y-%m-%d %X '; do sleep 1; done colors { statusline #ffffff - background #323232 - inactive_workspace #32323200 #32323200 #5c5c5c + background #000000 + +# border background text + focused_workspace $yellow $yellow #000000 + active_workspace $yellow #000000 $yellow + inactive_workspace #000000 #000000 $yellow + urgent_workspace $red $red #000000 + binding_mode $magenta $magenta #000000 } } +# default_border pixel 2 +# default_floating_border pixel 2 +default_border normal +default_floating_border normal +titlebar_padding 6 8 + +# === Palette === +exec_always swaybg -c '#000000' + +set $grey #808080 +set $red #FF6680 +set $green #67E4B6 +set $yellow #FFDB70 +set $blue #66B2FF +set $magenta #AC8CD9 +set $cyan #6EECF7 +set $white #F0F0F0 + +# set $black #505050 +# set $red #DF2040 +# set $green #2DD296 +# set $yellow #FFBF00 +# set $blue #207FDF +# set $magenta #7855AA +# set $cyan #13DAEC +# set $white #D0D0D0 + +# client. +client.focused $yellow $yellow #000000 $yellow $yellow +client.focused_inactive $grey #000000 $yellow $grey $grey +client.unfocused $grey #000000 #ffffff $grey $grey +client.urgent $red $red #000000 $red $red + +client.background $black + include /etc/sway/config.d/* diff --git a/wezterm/wezterm.lua b/wezterm/wezterm.lua index 21737c1a4..49cc18310 100644 --- a/wezterm/wezterm.lua +++ b/wezterm/wezterm.lua @@ -5,10 +5,10 @@ local config = wezterm.config_builder() config.enable_tab_bar = false config.window_padding = { - left = 0, - right = 0, - top = 0, - bottom = 0, + left = 20, + right = 20, + top = 20, + bottom = 20, } config.macos_window_background_blur = 100 config.win32_system_backdrop = 'Acrylic' @@ -71,4 +71,3 @@ else end return config - From b3858840a10e3b40414d485350e079be6d9afc88 Mon Sep 17 00:00:00 2001 From: parth Date: Tue, 21 Oct 2025 00:04:25 -0400 Subject: [PATCH 116/123] idle --- sway/config | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sway/config b/sway/config index e212d8170..dae726a27 100644 --- a/sway/config +++ b/sway/config @@ -25,10 +25,12 @@ output $A mode 3840x2160 position 3335,1420 output $B mode 1920x1200 position 4038,3580 output $C mode 3840x2160 position 1175,407 transform 90 -exec swayidle -w \ - timeout 300 'swaylock -f -c 000000' \ - timeout 600 'swaymsg "output * power off"' resume 'swaymsg "output * power on"' \ - before-sleep 'swaylock -f -c 000000' +bindsym $mod+shift+control+q exec swaylock -f -F -c 000000 --ring-color FFDB70 --inside-color FFDB70 --inside-wrong-color FF6680 --inside-ver-color AC8CD9 --key-hl-color 66B2FF + +# exec swayidle -w \ +# timeout 300 'swaylock -f -c 000000' \ +# timeout 600 'swaymsg "output * power off"' resume 'swaymsg "output * power on"' \ +# before-sleep 'swaylock -f -c 000000' # Kill focused window bindsym $mod+Shift+q kill From 5c1c00b5513f8d8381cb9174cff9d1d8007996dd Mon Sep 17 00:00:00 2001 From: parth Date: Tue, 21 Oct 2025 14:26:19 -0400 Subject: [PATCH 117/123] more cleanup --- nix/common/nvim.nix | 30 ++++++++++++++++++++++++++++++ nix/flake.nix | 34 ++++++---------------------------- nvim/lazy-lock.json | 20 -------------------- nvim/lua/packages.lua | 2 -- 4 files changed, 36 insertions(+), 50 deletions(-) create mode 100644 nix/common/nvim.nix delete mode 100644 nvim/lazy-lock.json diff --git a/nix/common/nvim.nix b/nix/common/nvim.nix new file mode 100644 index 000000000..36bf991a3 --- /dev/null +++ b/nix/common/nvim.nix @@ -0,0 +1,30 @@ +{ pkgs, ... }: +{ + programs.neovim = { + enable = true; + plugins = with pkgs.vimPlugins; [ + nvim-web-devicons + telescope-nvim + nvim-cmp + cmp-nvim-lsp + vim-illuminate + lualine-nvim + lsp-status-nvim + + nvim-tree-lua + nvim-lspconfig + luasnip + # todo replace "FabijanZulj/blame.nvim", + ]; + + extraPackages = with pkgs; [ + lua-language-server + # i would like to configure this here but rustup does some wack shit + # rust-analyzer + ]; + + # extraLuaConfig = '' + # dofile("/home/parth/dotfiles/nvim/init.lua") + # ''; + }; +} diff --git a/nix/flake.nix b/nix/flake.nix index 48bcb30aa..b166cd775 100644 --- a/nix/flake.nix +++ b/nix/flake.nix @@ -92,6 +92,7 @@ modules = [ configuration + nix-homebrew.darwinModules.nix-homebrew { nix-homebrew = { @@ -104,7 +105,6 @@ masApps = { "XCode" = 497799835; - "Final Cut Pro" = 424389933; "Lockbook" = 1526775001; "Lightroom" = 1451544217; }; @@ -127,6 +127,7 @@ }; } + home-manager.darwinModules.home-manager { home-manager.useGlobalPkgs = true; @@ -135,6 +136,10 @@ home-manager.users.parth = { pkgs, lib, ... }: { home.stateVersion = "24.05"; + imports = [ + ./common/nvim.nix + ]; + programs.git = { enable = true; userName = "parth"; @@ -144,33 +149,6 @@ }; }; - programs.neovim = { - enable = true; - plugins = with pkgs.vimPlugins; [ - nvim-web-devicons - telescope-nvim - nvim-cmp - cmp-nvim-lsp - vim-illuminate - lualine-nvim - lsp-status-nvim - - nvim-tree-lua - nvim-lspconfig - luasnip - # todo replace "FabijanZulj/blame.nvim", - ]; - - extraPackages = with pkgs; [ - lua-language-server - # i would like to configure this here but rustup does some wack shit - # rust-analyzer - ]; - - # extraLuaConfig = '' - # dofile("/home/parth/dotfiles/nvim/init.lua") - # ''; - }; xdg.configFile = { "nvim" = { diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json deleted file mode 100644 index 77edae7b2..000000000 --- a/nvim/lazy-lock.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "LuaSnip": { "branch": "master", "commit": "50fcf17db7c75af80e6b6109acfbfb4504768780" }, - "blame.nvim": { "branch": "main", "commit": "dedbcdce857f708c63f261287ac7491a893912d0" }, - "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, - "lazy.nvim": { "branch": "main", "commit": "b0ba3f9399bf48c86abaa4db1a40bd0b681d5018" }, - "lsp-status.nvim": { "branch": "master", "commit": "54f48eb5017632d81d0fd40112065f1d062d0629" }, - "lsp-zero.nvim": { "branch": "v3.x", "commit": "16de3b18c5f7b6230d89b8e64ce9a4801b6f8d08" }, - "lualine.nvim": { "branch": "master", "commit": "0a5a66803c7407767b799067986b4dc3036e1983" }, - "mason-lspconfig.nvim": { "branch": "main", "commit": "8db12610bcb7ce67013cfdfaba4dd47a23c6e851" }, - "mason.nvim": { "branch": "main", "commit": "0950b15060067f752fde13a779a994f59516ce3d" }, - "neodev.nvim": { "branch": "main", "commit": "02893eeb9d6e8503817bd52385e111cba9a90500" }, - "nvim-cmp": { "branch": "main", "commit": "5260e5e8ecadaf13e6b82cf867a909f54e15fd07" }, - "nvim-lspconfig": { "branch": "master", "commit": "92166b89ab4b3d60f24e58170cac53b7141fd032" }, - "nvim-tree.lua": { "branch": "master", "commit": "26632f496e7e3c0450d8ecff88f49068cecc8bda" }, - "nvim-treesitter": { "branch": "master", "commit": "c5cbd3ec74f6f5ddbac939e6f24b99fe78262b4c" }, - "nvim-web-devicons": { "branch": "master", "commit": "b4b302d6ae229f67df7a87ef69fa79473fe788a9" }, - "plenary.nvim": { "branch": "master", "commit": "a3e3bc82a3f95c5ed0d7201546d5d2c19b20d683" }, - "telescope.nvim": { "branch": "master", "commit": "6312868392331c9c0f22725041f1ec2bef57c751" }, - "vim-illuminate": { "branch": "master", "commit": "5eeb7951fc630682c322e88a9bbdae5c224ff0aa" } -} \ No newline at end of file diff --git a/nvim/lua/packages.lua b/nvim/lua/packages.lua index 8100642b7..a61bfedf7 100644 --- a/nvim/lua/packages.lua +++ b/nvim/lua/packages.lua @@ -103,7 +103,5 @@ lspconfig.nixd.setup { }, } -require('render-markdown').enable() - -- blame -- require("blame").setup() From 666a78bcec0139e772e0b9210e0e994092ebd5e0 Mon Sep 17 00:00:00 2001 From: parth Date: Tue, 21 Oct 2025 15:42:18 -0400 Subject: [PATCH 118/123] dry --- nix/common/fish.nix | 12 ++ nix/common/git.nix | 11 ++ nix/common/headless.nix | 126 +++---------------- nix/common/nvim.nix | 46 ++++--- nix/common/xdg.nix | 31 +++++ nix/flake.nix | 269 ++-------------------------------------- nvim/lua/packages.lua | 11 +- 7 files changed, 110 insertions(+), 396 deletions(-) create mode 100644 nix/common/fish.nix create mode 100644 nix/common/git.nix create mode 100644 nix/common/xdg.nix diff --git a/nix/common/fish.nix b/nix/common/fish.nix new file mode 100644 index 000000000..2f07e4ad4 --- /dev/null +++ b/nix/common/fish.nix @@ -0,0 +1,12 @@ +{ ... }: +{ + programs.fish = { + enable = true; + interactiveShellInit = '' + fish_vi_key_bindings + set -gx PATH $HOME/.cargo/bin $PATH + set -gx EDITOR nvim + set -gx VISUAL nvim + ''; + }; +} diff --git a/nix/common/git.nix b/nix/common/git.nix new file mode 100644 index 000000000..7a73e67db --- /dev/null +++ b/nix/common/git.nix @@ -0,0 +1,11 @@ +{ ... }: +{ + programs.git = { + enable = true; + userName = "parth"; + userEmail = "parth@mehrotra.me"; + extraConfig = { + push.default = "current"; + }; + }; +} diff --git a/nix/common/headless.nix b/nix/common/headless.nix index 145bd42ab..06aa5ece5 100644 --- a/nix/common/headless.nix +++ b/nix/common/headless.nix @@ -1,7 +1,7 @@ -{ pkgs, lib, ... }: +{ pkgs, ... }: let - home-manager = builtins.fetchTarball "https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz"; + home-manager = builtins.fetchTarball "https://github.com/nix-community/home-manager/archive/release-25.05.tar.gz"; in { imports = @@ -9,6 +9,7 @@ in # Include the results of the hardware scan. # ./hardware-configuration.nix "/etc/nixos/hardware-configuration.nix" + "/home/parth/dotfiles/nix/headless/common/fish.nix" (import "${home-manager}/nixos") ]; @@ -28,89 +29,17 @@ in LC_TIME = "en_US.UTF-8"; }; - programs.fish = { - enable = true; - interactiveShellInit = '' - fish_vi_key_bindings - set -gx PATH $HOME/.cargo/bin $PATH - set -gx EDITOR nvim - set -gx VISUAL nvim - ''; - }; users.defaultUserShell = pkgs.fish; home-manager.users.parth = { /* The home.stateVersion option does not have a default and must be set */ home.stateVersion = "18.09"; /* Here goes the rest of your home-manager config, e.g. home.packages = [ pkgs.foo ]; */ - programs.git = { - enable = true; - userName = "parth"; - userEmail = "parth@mehrotra.me"; - lfs.enable = true; - extraConfig = { - push.default = "current"; - }; - }; - - - programs.neovim = { - enable = true; - plugins = with pkgs.vimPlugins; [ - nvim-web-devicons - telescope-nvim - nvim-cmp - cmp-nvim-lsp - vim-illuminate - lualine-nvim - lsp-status-nvim - nvim-tree-lua - nvim-lspconfig - luasnip - render-markdown-nvim - # todo replace "FabijanZulj/blame.nvim", - ]; - - extraPackages = with pkgs; [ - lua-language-server - # i would like to configure this here but rustup does some wack shit - # rust-analyzer - ]; - - # extraLuaConfig = '' - # dofile("/home/parth/dotfiles/nvim/init.lua") - # ''; - }; - - - xdg.configFile = { - "nvim" = { - source = /home/parth/dotfiles/nvim; - recursive = true; - }; - - "helix" = { - source = /home/parth/dotfiles/helix; - recursive = true; - }; - - "aerospace" = { - source = /home/parth/dotfiles/aerospace; - recursive = true; - }; - - "wezterm" = { - source = /home/parth/dotfiles/wezterm; - recursive = true; - }; - "sway" = { - source = /home/parth/dotfiles/sway; - recursive = true; - }; - }; - home.sessionPath = [ - "$HOME/.cargo/bin" + imports = [ + "/home/parth/dotfiles/nix/common/nvim.nix" + "/home/parth/dotfiles/nix/common/fish.nix" + "/home/parth/dotfiles/nix/common/xdg.nix" ]; }; @@ -119,49 +48,32 @@ in description = "parth"; extraGroups = [ "networkmanager" "wheel" ]; packages = with pkgs; [ - zola - - helix - fzf - eza - xclip - ripgrep clang - samba - rust-analyzer rustup - nixd - lua-language-server nixpkgs-fmt - google-cloud-sdk lockbook - - git-lfs ]; }; environment.variables = { EDITOR = "nvim"; VISUAL = "nvim"; }; - - programs.git.enable = true; nixpkgs.config.allowUnfree = true; system.stateVersion = "24.05"; - fileSystems."/truenas" = { - device = "//192.168.12.2/parth-dataset"; - fsType = "cifs"; - options = [ - "credentials=/etc/nixos/smb-secrets" - "uid=1000" - "gid=100" - "vers=3.0" - "x-systemd.automount" - "noauto" - ]; - }; - + fileSystems."/truenas" = { + device = "//192.168.12.2/parth-dataset"; + fsType = "cifs"; + options = [ + "credentials=/etc/nixos/smb-secrets" + "uid=1000" + "gid=100" + "vers=3.0" + "x-systemd.automount" + "noauto" + ]; + }; } diff --git a/nix/common/nvim.nix b/nix/common/nvim.nix index 36bf991a3..802dc762b 100644 --- a/nix/common/nvim.nix +++ b/nix/common/nvim.nix @@ -1,30 +1,26 @@ { pkgs, ... }: { - programs.neovim = { - enable = true; - plugins = with pkgs.vimPlugins; [ - nvim-web-devicons - telescope-nvim - nvim-cmp - cmp-nvim-lsp - vim-illuminate - lualine-nvim - lsp-status-nvim + programs.neovim = { + enable = true; + plugins = with pkgs.vimPlugins; [ + nvim-web-devicons + telescope-nvim + nvim-cmp + cmp-nvim-lsp + vim-illuminate + lualine-nvim + lsp-status-nvim - nvim-tree-lua - nvim-lspconfig - luasnip - # todo replace "FabijanZulj/blame.nvim", - ]; + nvim-tree-lua + nvim-lspconfig + luasnip + # todo replace "FabijanZulj/blame.nvim", + ]; - extraPackages = with pkgs; [ - lua-language-server - # i would like to configure this here but rustup does some wack shit - # rust-analyzer - ]; - - # extraLuaConfig = '' - # dofile("/home/parth/dotfiles/nvim/init.lua") - # ''; - }; + extraPackages = with pkgs; [ + lua-language-server + nil + nixd + ]; + }; } diff --git a/nix/common/xdg.nix b/nix/common/xdg.nix new file mode 100644 index 000000000..8af9d9318 --- /dev/null +++ b/nix/common/xdg.nix @@ -0,0 +1,31 @@ +{ ... }: +{ + xdg.configFile = { + "nvim" = { + source = /home/parth/dotfiles/nvim; + recursive = true; + }; + + "helix" = { + source = /home/parth/dotfiles/helix; + recursive = true; + }; + + "aerospace" = { + source = /home/parth/dotfiles/aerospace; + recursive = true; + }; + + "wezterm" = { + source = /home/parth/dotfiles/wezterm; + recursive = true; + }; + "sway" = { + source = /home/parth/dotfiles/sway; + recursive = true; + }; + }; + home.sessionPath = [ + "$HOME/.cargo/bin" + ]; +} diff --git a/nix/flake.nix b/nix/flake.nix index b166cd775..bbd1eea02 100644 --- a/nix/flake.nix +++ b/nix/flake.nix @@ -30,7 +30,6 @@ system.configurationRevision = self.rev or self.dirtyRev or null; environment.systemPackages = with pkgs; [ - helix ffmpeg_6 fzf @@ -60,15 +59,9 @@ nixpkgs.hostPlatform = "aarch64-darwin"; - programs.fish = { - enable = true; - interactiveShellInit = '' - fish_vi_key_bindings - set -gx PATH $HOME/.cargo/bin $PATH - set -gx EDITOR nvim - set -gx VISUAL nvim - ''; - }; + imports = [ + ./common/fish.nix + ]; users.knownUsers = [ "parth" ]; users.users.parth.uid = 501; @@ -92,7 +85,6 @@ modules = [ configuration - nix-homebrew.darwinModules.nix-homebrew { nix-homebrew = { @@ -133,259 +125,14 @@ home-manager.useGlobalPkgs = true; home-manager.backupFileExtension = "backup"; home-manager.useUserPackages = true; - home-manager.users.parth = { pkgs, lib, ... }: { + home-manager.users.parth = { ... }: { home.stateVersion = "24.05"; - imports = [ + imports = [ ./common/nvim.nix - ]; - - programs.git = { - enable = true; - userName = "parth"; - userEmail = "parth@mehrotra.me"; - extraConfig = { - push.default = "current"; - }; - }; - - - xdg.configFile = { - "nvim" = { - source = /Users/parth/dotfiles/nvim; - recursive = true; - }; - - "helix" = { - source = /Users/parth/dotfiles/helix; - recursive = true; - }; - - "aerospace" = { - source = /Users/parth/dotfiles/aerospace; - recursive = true; - }; - - "wezterm" = { - source = /Users/parth/dotfiles/wezterm; - recursive = true; - }; - }; - - home.file.".aerospace.toml".text = '' - # Place a copy of this config to ~/.aerospace.toml - # After that, you can edit ~/.aerospace.toml to your liking - - # You can use it to add commands that run after login to macOS user session. - # 'start-at-login' needs to be 'true' for 'after-login-command' to work - # Available commands: https://nikitabobko.github.io/AeroSpace/commands - after-login-command = [] - - # You can use it to add commands that run after AeroSpace startup. - # 'after-startup-command' is run after 'after-login-command' - # Available commands : https://nikitabobko.github.io/AeroSpace/commands - after-startup-command = [] - - # Start AeroSpace at login - start-at-login = false - - # Normalizations. See: https://nikitabobko.github.io/AeroSpace/guide#normalization - enable-normalization-flatten-containers = true - enable-normalization-opposite-orientation-for-nested-containers = true - - # See: https://nikitabobko.github.io/AeroSpace/guide#layouts - # The 'accordion-padding' specifies the size of accordion padding - # You can set 0 to disable the padding feature - accordion-padding = 30 - - # Possible values: tiles|accordion - default-root-container-layout = 'tiles' - - # Possible values: horizontal|vertical|auto - # 'auto' means: wide monitor (anything wider than high) gets horizontal orientation, - # tall monitor (anything higher than wide) gets vertical orientation - default-root-container-orientation = 'auto' - - # Mouse follows focus when focused monitor changes - # Drop it from your config, if you don't like this behavior - # See https://nikitabobko.github.io/AeroSpace/guide#on-focus-changed-callbacks - # See https://nikitabobko.github.io/AeroSpace/commands#move-mouse - # Fallback value (if you omit the key): on-focused-monitor-changed = [] - on-focused-monitor-changed = ['move-mouse monitor-lazy-center'] - - # You can effectively turn off macOS "Hide application" (cmd-h) feature by toggling this flag - # Useful if you don't use this macOS feature, but accidentally hit cmd-h or cmd-alt-h key - # Also see: https://nikitabobko.github.io/AeroSpace/goodies#disable-hide-app - automatically-unhide-macos-hidden-apps = false - - # Possible values: (qwerty|dvorak|colemak) - # See https://nikitabobko.github.io/AeroSpace/guide#key-mapping - [key-mapping] - preset = 'qwerty' - - # Gaps between windows (inner-*) and between monitor edges (outer-*). - # Possible values: - # - Constant: gaps.outer.top = 8 - # - Per monitor: gaps.outer.top = [{ monitor.main = 16 }, { monitor."some-pattern" = 32 }, 24] - # In this example, 24 is a default value when there is no match. - # Monitor pattern is the same as for 'workspace-to-monitor-force-assignment'. - # See: - # https://nikitabobko.github.io/AeroSpace/guide#assign-workspaces-to-monitors - [gaps] - inner.horizontal = 6 - inner.vertical = 6 - outer.left = 6 - outer.bottom = 6 - outer.top = 6 - outer.right = 6 - - # 'main' binding mode declaration - # See: https://nikitabobko.github.io/AeroSpace/guide#binding-modes - # 'main' binding mode must be always presented - # Fallback value (if you omit the key): mode.main.binding = {} - [mode.main.binding] - - # All possible keys: - # - Letters. a, b, c, ..., z - # - Numbers. 0, 1, 2, ..., 9 - # - Keypad numbers. keypad0, keypad1, keypad2, ..., keypad9 - # - F-keys. f1, f2, ..., f20 - # - Special keys. minus, equal, period, comma, slash, backslash, quote, semicolon, - # backtick, leftSquareBracket, rightSquareBracket, space, enter, esc, - # backspace, tab, pageUp, pageDown, home, end, forwardDelete, - # sectionSign (ISO keyboards only, european keyboards only) - # - Keypad special. keypadClear, keypadDecimalMark, keypadDivide, keypadEnter, keypadEqual, - # keypadMinus, keypadMultiply, keypadPlus - # - Arrows. left, down, up, right - - # All possible modifiers: cmd, alt, ctrl, shift - - # All possible commands: https://nikitabobko.github.io/AeroSpace/commands - - # See: https://nikitabobko.github.io/AeroSpace/commands#exec-and-forget - # You can uncomment the following lines to open up terminal with alt + enter shortcut - # (like in i3) - # alt-enter = '''exec-and-forget osascript -e ' - # tell application "Terminal" - # do script - # activate - # end tell' - # ''' - - # See: https://nikitabobko.github.io/AeroSpace/commands#layout - alt-slash = 'layout tiles horizontal vertical' - alt-comma = 'layout accordion horizontal vertical' - - # See: https://nikitabobko.github.io/AeroSpace/commands#focus - alt-h = 'focus left' - alt-j = 'focus down' - alt-k = 'focus up' - alt-l = 'focus right' - - # See: https://nikitabobko.github.io/AeroSpace/commands#move - alt-shift-h = 'move left' - alt-shift-j = 'move down' - alt-shift-k = 'move up' - alt-shift-l = 'move right' - - # See: https://nikitabobko.github.io/AeroSpace/commands#resize - alt-minus = 'resize smart -50' - alt-equal = 'resize smart +50' - - # See: https://nikitabobko.github.io/AeroSpace/commands#workspace - alt-1 = 'workspace 1' - alt-2 = 'workspace 2' - alt-3 = 'workspace 3' - alt-4 = 'workspace 4' - alt-5 = 'workspace 5' - alt-6 = 'workspace 6' - alt-7 = 'workspace 7' - alt-8 = 'workspace 8' - alt-9 = 'workspace 9' - alt-a = 'workspace A' # In your config, you can drop workspace bindings that you don't need - alt-b = 'workspace B' - alt-c = 'workspace C' - alt-d = 'workspace D' - alt-e = 'workspace E' - alt-f = 'workspace F' - alt-g = 'workspace G' - alt-i = 'workspace I' - alt-m = 'workspace M' - alt-n = 'workspace N' - alt-o = 'workspace O' - alt-p = 'workspace P' - alt-q = 'workspace Q' - alt-r = 'workspace R' - alt-s = 'workspace S' - alt-t = 'workspace T' - alt-u = 'workspace U' - alt-v = 'workspace V' - alt-w = 'workspace W' - alt-x = 'workspace X' - alt-y = 'workspace Y' - alt-z = 'workspace Z' - - # See: https://nikitabobko.github.io/AeroSpace/commands#move-node-to-workspace - alt-shift-1 = 'move-node-to-workspace 1' - alt-shift-2 = 'move-node-to-workspace 2' - alt-shift-3 = 'move-node-to-workspace 3' - alt-shift-4 = 'move-node-to-workspace 4' - alt-shift-5 = 'move-node-to-workspace 5' - alt-shift-6 = 'move-node-to-workspace 6' - alt-shift-7 = 'move-node-to-workspace 7' - alt-shift-8 = 'move-node-to-workspace 8' - alt-shift-9 = 'move-node-to-workspace 9' - alt-shift-a = 'move-node-to-workspace A' - alt-shift-b = 'move-node-to-workspace B' - alt-shift-c = 'move-node-to-workspace C' - alt-shift-d = 'move-node-to-workspace D' - alt-shift-e = 'move-node-to-workspace E' - alt-shift-f = 'move-node-to-workspace F' - alt-shift-g = 'move-node-to-workspace G' - alt-shift-i = 'move-node-to-workspace I' - alt-shift-m = 'move-node-to-workspace M' - alt-shift-n = 'move-node-to-workspace N' - alt-shift-o = 'move-node-to-workspace O' - alt-shift-p = 'move-node-to-workspace P' - alt-shift-q = 'move-node-to-workspace Q' - alt-shift-r = 'move-node-to-workspace R' - alt-shift-s = 'move-node-to-workspace S' - alt-shift-t = 'move-node-to-workspace T' - alt-shift-u = 'move-node-to-workspace U' - alt-shift-v = 'move-node-to-workspace V' - alt-shift-w = 'move-node-to-workspace W' - alt-shift-x = 'move-node-to-workspace X' - alt-shift-y = 'move-node-to-workspace Y' - alt-shift-z = 'move-node-to-workspace Z' - - # See: https://nikitabobko.github.io/AeroSpace/commands#workspace-back-and-forth - alt-tab = 'workspace-back-and-forth' - # See: https://nikitabobko.github.io/AeroSpace/commands#move-workspace-to-monitor - alt-shift-tab = 'move-workspace-to-monitor --wrap-around next' - - # See: https://nikitabobko.github.io/AeroSpace/commands#mode - alt-shift-semicolon = 'mode service' - - # 'service' binding mode declaration. - # See: https://nikitabobko.github.io/AeroSpace/guide#binding-modes - [mode.service.binding] - esc = ['reload-config', 'mode main'] - r = ['flatten-workspace-tree', 'mode main'] # reset layout - f = ['layout floating tiling', 'mode main'] # Toggle between floating and tiling layout - backspace = ['close-all-windows-but-current', 'mode main'] - - # sticky is not yet supported https://github.com/nikitabobko/AeroSpace/issues/2 - #s = ['layout sticky tiling', 'mode main'] - - alt-shift-h = ['join-with left', 'mode main'] - alt-shift-j = ['join-with down', 'mode main'] - alt-shift-k = ['join-with up', 'mode main'] - alt-shift-l = ['join-with right', 'mode main'] - - down = 'volume down' - up = 'volume up' - shift-down = ['volume set 0', 'mode main'] - ''; + ./common/git.nix + ./common/xdg.nix + ]; }; } ]; diff --git a/nvim/lua/packages.lua b/nvim/lua/packages.lua index a61bfedf7..1326387c2 100644 --- a/nvim/lua/packages.lua +++ b/nvim/lua/packages.lua @@ -98,10 +98,15 @@ lspconfig.lua_ls.setup { }, } lspconfig.nixd.setup { - formatters_by_ft = { - nix = { "nixpkgs_fmt" }, - }, + settings = { + nixd = { + formatting = { + command = { "nixpkgs-fmt" } + } + } + } } +lspconfig.nil_ls.setup {} -- blame -- require("blame").setup() From 79896c8ac1c99ade6824c78bb4cef1f534f0f99b Mon Sep 17 00:00:00 2001 From: parth Date: Tue, 21 Oct 2025 16:20:03 -0400 Subject: [PATCH 119/123] even better dotfilesing --- helix/config.toml | 41 ----------------------------------------- helix/languages.toml | 4 ---- nix/common/headless.nix | 4 ++-- nix/common/nvim.nix | 1 + nix/common/xdg.nix | 16 ++++++---------- 5 files changed, 9 insertions(+), 57 deletions(-) delete mode 100644 helix/config.toml delete mode 100644 helix/languages.toml diff --git a/helix/config.toml b/helix/config.toml deleted file mode 100644 index 2d5552448..000000000 --- a/helix/config.toml +++ /dev/null @@ -1,41 +0,0 @@ -theme = "adwaita-dark" - -# hard to tell when 2 suggestions which one is selected in code completion -# when grepping sometimes previews are un-viewable -# find references of get_usage the bar is blue the text is the same blue and I -# can't see what's going on -# -# symbol highlighting also not working, possibly a theme problem -# -# we cannot use any red for the text -- the diagnostics are shown in the top right and the clash is prohibitive -# theme = "base16_default" - -[editor] -cursor-shape = { insert = "bar" } -cursorline = true -cursorcolumn = true -indent-guides = { render = true, skip-levels = 1 } - -# status line desires -# git info -# lsp info -# -# ]d should prioritize errors -# -# helix config lsp? -# toml auto formatter? - -[keys.insert] -# would like to be able to scroll down and up with C-j C-k, tbd on whether cursor should move -C-e = "insert_at_line_end" - -[keys.normal] -esc = ":write-all" -C-r = ":reload-all" -C-l = ":theme adwaita-light" -C-k = ":theme adwaita-dark" - -[keys.normal."space"] -E = "@ D%p !tests %s ERROR" -e = "@ D %s ERROR" -W = "@ D%p !tests %s" diff --git a/helix/languages.toml b/helix/languages.toml deleted file mode 100644 index 780ec6c50..000000000 --- a/helix/languages.toml +++ /dev/null @@ -1,4 +0,0 @@ -[[language]] -name = "nix" -auto-format = true -formatter = { command = "nixpkgs-fmt" } diff --git a/nix/common/headless.nix b/nix/common/headless.nix index 06aa5ece5..f70f5bbe4 100644 --- a/nix/common/headless.nix +++ b/nix/common/headless.nix @@ -9,7 +9,7 @@ in # Include the results of the hardware scan. # ./hardware-configuration.nix "/etc/nixos/hardware-configuration.nix" - "/home/parth/dotfiles/nix/headless/common/fish.nix" + "/home/parth/dotfiles/nix/common/fish.nix" (import "${home-manager}/nixos") ]; @@ -38,7 +38,7 @@ in imports = [ "/home/parth/dotfiles/nix/common/nvim.nix" - "/home/parth/dotfiles/nix/common/fish.nix" + "/home/parth/dotfiles/nix/common/git.nix" "/home/parth/dotfiles/nix/common/xdg.nix" ]; }; diff --git a/nix/common/nvim.nix b/nix/common/nvim.nix index 802dc762b..018ba097b 100644 --- a/nix/common/nvim.nix +++ b/nix/common/nvim.nix @@ -14,6 +14,7 @@ nvim-tree-lua nvim-lspconfig luasnip + vim-sleuth # todo replace "FabijanZulj/blame.nvim", ]; diff --git a/nix/common/xdg.nix b/nix/common/xdg.nix index 8af9d9318..70b52cc9d 100644 --- a/nix/common/xdg.nix +++ b/nix/common/xdg.nix @@ -1,30 +1,26 @@ -{ ... }: +{ config, ... }: { xdg.configFile = { "nvim" = { - source = /home/parth/dotfiles/nvim; - recursive = true; - }; - - "helix" = { - source = /home/parth/dotfiles/helix; + source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/dotfiles/nvim"; recursive = true; }; "aerospace" = { - source = /home/parth/dotfiles/aerospace; + source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/dotfiles/aerospace"; recursive = true; }; "wezterm" = { - source = /home/parth/dotfiles/wezterm; + source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/dotfiles/wezterm"; recursive = true; }; "sway" = { - source = /home/parth/dotfiles/sway; + source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/dotfiles/sway"; recursive = true; }; }; + home.sessionPath = [ "$HOME/.cargo/bin" ]; From 2714b05dd6ef8d8e6f8ec206f65b18a7cb23d1f0 Mon Sep 17 00:00:00 2001 From: parth Date: Tue, 21 Oct 2025 16:34:08 -0400 Subject: [PATCH 120/123] even better dotfilesing --- nix/common/nvim.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/common/nvim.nix b/nix/common/nvim.nix index 018ba097b..0aff8f784 100644 --- a/nix/common/nvim.nix +++ b/nix/common/nvim.nix @@ -14,7 +14,7 @@ nvim-tree-lua nvim-lspconfig luasnip - vim-sleuth + # vim-sleuth # todo replace "FabijanZulj/blame.nvim", ]; From 3200ff5de2e5977916808664712989a52debc5ea Mon Sep 17 00:00:00 2001 From: parth Date: Tue, 21 Oct 2025 18:52:41 -0400 Subject: [PATCH 121/123] finally some auto dark light switching --- nix/common/nvim.nix | 6 +- nvim/deploy.sh | 3 - nvim/init.lua | 1 + nvim/lua/auto-dark-mode/health.lua | 102 ++++++++++++ nvim/lua/auto-dark-mode/init.lua | 179 ++++++++++++++++++++ nvim/lua/auto-dark-mode/interval.lua | 157 ++++++++++++++++++ nvim/lua/auto-dark-mode/types.lua | 21 +++ nvim/lua/dark_theme.lua | 236 +++++++++++++++++++++++++++ nvim/lua/light_theme.lua | 235 ++++++++++++++++++++++++++ nvim/lua/packages.lua | 17 +- sway/config | 1 + wezterm/wezterm.lua | 2 +- 12 files changed, 951 insertions(+), 9 deletions(-) delete mode 100644 nvim/deploy.sh create mode 100644 nvim/lua/auto-dark-mode/health.lua create mode 100644 nvim/lua/auto-dark-mode/init.lua create mode 100644 nvim/lua/auto-dark-mode/interval.lua create mode 100644 nvim/lua/auto-dark-mode/types.lua create mode 100644 nvim/lua/dark_theme.lua create mode 100644 nvim/lua/light_theme.lua diff --git a/nix/common/nvim.nix b/nix/common/nvim.nix index 0aff8f784..ec990403b 100644 --- a/nix/common/nvim.nix +++ b/nix/common/nvim.nix @@ -14,8 +14,10 @@ nvim-tree-lua nvim-lspconfig luasnip - # vim-sleuth - # todo replace "FabijanZulj/blame.nvim", + vim-sleuth + nvim-treesitter + nvim-treesitter.withAllGrammars + gitsigns-nvim ]; extraPackages = with pkgs; [ diff --git a/nvim/deploy.sh b/nvim/deploy.sh deleted file mode 100644 index 02f46d6ff..000000000 --- a/nvim/deploy.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -ln -s $HOME/dotfiles/nvim $HOME/.config/nvim diff --git a/nvim/init.lua b/nvim/init.lua index a352f1574..f009b17b3 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1,5 +1,6 @@ vim.g.mapleader = ' '; +require("light_theme").colorscheme() require("packages") require("keyboard") require("config") diff --git a/nvim/lua/auto-dark-mode/health.lua b/nvim/lua/auto-dark-mode/health.lua new file mode 100644 index 000000000..66a231847 --- /dev/null +++ b/nvim/lua/auto-dark-mode/health.lua @@ -0,0 +1,102 @@ +local M = {} + +local uv = vim.uv or vim.loop + +local adm = require("auto-dark-mode") +local interval = require("auto-dark-mode.interval") + +M.benchmark = function(iterations) + local result = { + avg = 0, + max = 0, + min = math.huge, + all_results = {}, + stdout = nil, + stderr = nil, + parsed = nil, + } + + for _ = 1, iterations do + local _start = uv.hrtime() + -- parsing the response is measured, but actually syncing the vim theme isn't performed + local function callback(_stdout, _stderr) + result.stdout = _stdout + result.stderr = _stderr + result.parsed = interval.parse_callback(_stdout, _stderr) + vim.schedule_wrap(function() + vim.print(result) + end) + end + + local success, _ = pcall(interval.poll_dark_mode, callback) + -- bail early if polling fails + if not success then + break + end + local _end = uv.hrtime() + + table.insert(result.all_results, (_end - _start) / 1e6) + end + + local sum = 0 + for _, v in pairs(result.all_results) do + result.max = result.max > v and result.max or v + result.min = result.min < v and result.min or v + sum = sum + v + end + result.avg = sum / iterations + + return result +end + +-- support for neovim < 0.9.0 +local H = vim.health +local health = {} +health.start = H.start or H.report_start +health.ok = H.ok or H.report_ok +health.info = H.info or H.report_info +health.error = H.error or H.report_error + +M.check = function() + health.start("auto-dark-mode.nvim") + + if adm.state.setup_correct then + health.ok("Setup is correct") + else + health.error("Setup is incorrect") + end + + health.info(string.format("Detected operating system: %s", adm.state.system)) + health.info(string.format("Using query command: `%s`", table.concat(adm.state.query_command, " "))) + + interval.poll_dark_mode(function(stdout, stderr) + vim.schedule(function() + health.info(string.format("Query response:\nstdout: %s\nstderr: %s\n", stdout, stderr)) + end) + end) + + local benchmark = M.benchmark(30) + health.info( + string.format("Benchmark: %.2fms avg / %.2fms min / %.2fms max", benchmark.avg, benchmark.min, benchmark.max) + ) + + local update_interval = adm.options.update_interval + local ratio = update_interval / benchmark.avg + local msg = { + info = string.format("Update interval (%dms) is %.2fx the average query time", update_interval, ratio), + error = string.format( + "Update interval (%dms) seems too short compared to current benchmarks, consider increasing it", + update_interval + ), + } + + if ratio > 30 then + health.ok(msg.info) + elseif ratio > 5 then + health.warn(msg.info) + else + health.error(msg.error) + end +end + +return M diff --git a/nvim/lua/auto-dark-mode/init.lua b/nvim/lua/auto-dark-mode/init.lua new file mode 100644 index 000000000..0c0184f1d --- /dev/null +++ b/nvim/lua/auto-dark-mode/init.lua @@ -0,0 +1,179 @@ +local M = {} + +local uv = vim.uv or vim.loop + +---@type AutoDarkModeOptions +local default_options = { + fallback = "dark", + + set_dark_mode = function() + vim.api.nvim_set_option_value("background", "dark", {}) + end, + + set_light_mode = function() + vim.api.nvim_set_option_value("background", "light", {}) + end, + + update_interval = 3000, +} + +---@param options AutoDarkModeOptions +local function validate_options(options) + local version = vim.version() + + if (version.major == 0 and version.minor >= 11) or version.major > 0 then + vim.validate("fallback", options.fallback, function(opt) + return vim.tbl_contains({ "dark", "light" }, opt) + end, "`fallback` to be either 'light' or 'dark'") + vim.validate("set_dark_mode", options.set_dark_mode, "function") + vim.validate("set_light_mode", options.set_light_mode, "function") + vim.validate("update_interval", options.update_interval, "number") + else + vim.validate({ + fallback = { + options.fallback, + function(opt) + return vim.tbl_contains({ "dark", "light" }, opt) + end, + "`fallback` to be either 'light' or 'dark'", + }, + set_dark_mode = { options.set_dark_mode, "function" }, + set_light_mode = { options.set_light_mode, "function" }, + update_interval = { options.update_interval, "number" }, + }) + end + + M.state.setup_correct = true +end + +---@class AutoDarkModeState +M.state = { + ---@type boolean + setup_correct = false, + ---@type DetectedOS + system = nil, + ---@type table + query_command = {}, +} + +---@return nil +M.init = function() + local os_uname = uv.os_uname() + + if string.match(os_uname.release, "WSL") then + M.state.system = "WSL" + elseif string.match(os_uname.release, "orbstack") then + M.state.system = "OrbStack" + else + M.state.system = os_uname.sysname + end + + if M.state.system == "Darwin" or M.state.system == "OrbStack" then + local query_command = { "defaults", "read", "-g", "AppleInterfaceStyle" } + if M.state.system == "OrbStack" then + query_command = vim.list_extend({ "mac" }, query_command) + end + M.state.query_command = query_command + elseif M.state.system == "Linux" then + if vim.fn.executable("dbus-send") == 0 then + error( + "auto-dark-mode.nvim: `dbus-send` is not available. The Linux implementation of auto-dark-mode.nvim relies on `dbus-send` being on the `$PATH`." + ) + end + + M.state.query_command = { + "dbus-send", + "--session", + "--print-reply=literal", + "--reply-timeout=1000", + "--dest=org.freedesktop.portal.Desktop", + "/org/freedesktop/portal/desktop", + "org.freedesktop.portal.Settings.Read", + "string:org.freedesktop.appearance", + "string:color-scheme", + } + elseif M.state.system == "Windows_NT" or M.state.system == "WSL" then + local reg = "reg.exe" + + -- gracefully handle a bunch of WSL specific errors + if M.state.system == "WSL" then + -- automount not being enabled + if not uv.fs_stat("/mnt/c/Windows") then + error( + "auto-dark-mode.nvim: Your WSL configuration doesn't enable `automount`. Please see https://learn.microsoft.com/en-us/windows/wsl/wsl-config#automount-settings." + ) + end + + -- binfmt not being provided for windows executables + if + not ( + uv.fs_stat("/proc/sys/fs/binfmt_misc/WSLInterop") + or uv.fs_stat("/proc/sys/fs/binfmt_misc/WSLInterop-late") + ) + then + error( + "auto-dark-mode.nvim: Your WSL configuration doesn't enable `interop`. Please see https://learn.microsoft.com/en-us/windows/wsl/wsl-config#interop-settings." + ) + end + + -- `appendWindowsPath` being set to false + if vim.fn.executable("reg.exe") == 0 then + local hardcoded_path = "/mnt/c/Windows/system32/reg.exe" + if uv.fs_stat(hardcoded_path) then + reg = hardcoded_path + else + error( + "auto-dark-mode.nvim: `reg.exe` cannot be found. To support syncing with the host system, this plugin relies on `reg.exe` being on the `$PATH`." + ) + end + end + end + + M.state.query_command = { + reg, + "Query", + "HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", + "/v", + "AppsUseLightTheme", + } + else + return + end + + -- when on a supported unix system, and the userid is root + if (M.state.system == "Darwin" or M.state.system == "Linux") and uv.getuid() == 0 then + local sudo_user = vim.env.SUDO_USER + + if not sudo_user then + error( + "auto-dark-mode.nvim: Running as `root`, but `$SUDO_USER` is not set. Please open an issue to add support for your setup." + ) + end + + local prefixed_cmd = { "sudo", "--user", sudo_user } + vim.list_extend(prefixed_cmd, M.state.query_command) + + M.state.query_command = prefixed_cmd + end + + local interval = require("auto-dark-mode.interval") + + interval.start(M.options, M.state) + + -- expose the previous `require("auto-dark-mode").disable()` function + M.disable = interval.stop_timer +end + +---@param options? AutoDarkModeOptions +---@return nil +M.setup = function(options) + if not options then + options = {} + end + M.options = vim.tbl_deep_extend("keep", options or {}, default_options) + validate_options(M.options) + + M.init() +end + +return M diff --git a/nvim/lua/auto-dark-mode/interval.lua b/nvim/lua/auto-dark-mode/interval.lua new file mode 100644 index 000000000..887e37548 --- /dev/null +++ b/nvim/lua/auto-dark-mode/interval.lua @@ -0,0 +1,157 @@ +local M = { + ---@type uv_timer_t + timer = nil, + ---@type number + timer_id = nil, + ---@type Appearance? + current_appearance = nil, +} + +local uv = vim.uv or vim.loop + +-- Parses the query response for each system, returning the current appearance, +-- or `nil` if it can't be resolved. +---@param stdout string +---@param stderr string +---@return Appearance? +local function parse_query_response(stdout, stderr) + if M.state.system == "Linux" then + if stderr ~= "" then + return nil; + end + + -- https://github.com/flatpak/xdg-desktop-portal/blob/c0f0eb103effdcf3701a1bf53f12fe953fbf0b75/data/org.freedesktop.impl.portal.Settings.xml#L32-L46 + -- 0: no preference + -- 1: dark + -- 2: light + if string.match(stdout, "uint32 1") ~= nil then + return "dark" + elseif string.match(stdout, "uint32 [02]") ~= nil then + return "light" + else + return M.options.fallback + end + elseif M.state.system == "Darwin" or M.state.system == "OrbStack" then + return stdout == "Dark\n" and "dark" or "light" + elseif M.state.system == "Windows_NT" or M.state.system == "WSL" then + -- AppsUseLightTheme REG_DWORD 0x0 : dark + -- AppsUseLightTheme REG_DWORD 0x1 : light + return string.match(stdout, "0x1") and "light" or "dark" + end + + return nil +end + +-- Executes the `set_dark_mode` and `set_light_mode` hooks when needed, +-- otherwise it's a no-op. +---@param appearance Appearance +---@return nil +local function sync_theme(appearance) + if appearance == M.current_appearance then + return + end + + M.current_appearance = appearance + if M.current_appearance == "dark" then + if vim.system then + vim.schedule(M.options.set_dark_mode) + else + M.options.set_dark_mode() + end + elseif M.current_appearance == "light" then + if vim.system then + vim.schedule(M.options.set_light_mode) + else + M.options.set_light_mode() + end + end +end + +-- Uses a subprocess to query the system for the current dark mode setting. +-- The callback is called with the plaintext stdout response of the query. +---@param callback? fun(stdout: string, stderr: string): nil +---@return nil +M.poll_dark_mode = function(callback) + -- if no callback is provided, use a no-op + if callback == nil then + callback = function() end + end + + if vim.system then + vim.system(M.state.query_command, { text = true }, function(data) + callback(data.stdout, data.stderr) + end) + else + -- Legacy implementation using `vim.fn.jobstart` instead of `vim.system`, + -- for use in neovim <0.10.0 + local stdout = "" + local stderr = "" + + vim.fn.jobstart(M.state.query_command, { + stderr_buffered = true, + stdout_buffered = true, + on_stderr = function(_, data, _) + stderr = table.concat(data, " ") + end, + on_stdout = function(_, data, _) + stdout = table.concat(data, " ") + end, + on_exit = function(_, _, _) + callback(stdout, stderr) + end, + }) + end +end + +---@param stdout string +---@param stderr string +---@return nil +M.parse_callback = function(stdout, stderr) + local appearance = parse_query_response(stdout, stderr) + + if appearance ~= nil then + sync_theme(appearance) + end +end + +local timer_callback = function() + M.poll_dark_mode(M.parse_callback) +end + +---@return nil +M.start_timer = function() + ---@type number + local interval = M.options.update_interval + + -- needs to check for `vim.system` because the poll function depends on it + if uv and vim.system then + M.timer = uv.new_timer() + M.timer:start(interval, interval, timer_callback) + else + M.timer_id = vim.fn.timer_start(interval, timer_callback, { ["repeat"] = -1 }) + end +end + +---@return nil +M.stop_timer = function() + if uv.timer_stop then + uv.timer_stop(M.timer) + else + vim.fn.timer_stop(M.timer_id) + end +end + +---@param options AutoDarkModeOptions +---@param state AutoDarkModeState +---@return nil +M.start = function(options, state) + M.options = options + M.state = state + + -- act as if the timer has finished once to instantly sync on startup + timer_callback() + + M.start_timer() +end + +return M diff --git a/nvim/lua/auto-dark-mode/types.lua b/nvim/lua/auto-dark-mode/types.lua new file mode 100644 index 000000000..ac67c8ceb --- /dev/null +++ b/nvim/lua/auto-dark-mode/types.lua @@ -0,0 +1,21 @@ +---@meta + +---@alias Appearance "light" | "dark" +---@alias DetectedOS "Linux" | "Darwin" | "Windows_NT" | "WSL" | "OrbStack" + +---@class AutoDarkModeOptions +-- Optional. Fallback theme to use if the system theme can't be detected. +-- Useful for linux and environments without a desktop manager. +---@field fallback? Appearance +-- Optional. The default runs: +-- ```lua +-- vim.api.nvim_set_option_value('background', 'dark', {}) +-- ``` +---@field set_dark_mode? fun(): nil +-- Optional. The default runs: +-- ```lua +-- vim.api.nvim_set_option_value('background', 'light', {}) +-- ``` +---@field set_light_mode? fun(): nil +-- Optional. Specifies the `update_interval` milliseconds a theme check will be performed. +---@field update_interval? number diff --git a/nvim/lua/dark_theme.lua b/nvim/lua/dark_theme.lua new file mode 100644 index 000000000..8dd055748 --- /dev/null +++ b/nvim/lua/dark_theme.lua @@ -0,0 +1,236 @@ +local M = {}; + +-- lua/colors/premonition_dark.lua +-- Mnemonic Dark Premonition – Neovim colorscheme (starter) +-- Palette derived from your JSON theme. + +local p = { + bg = "#080808", + fg = "#FFFFFF", + fg_muted = "#D0D0D0", + comment = "#808080", + border = "#505050", + + -- Accents + cyan = "#6EECF7", + cyan_bright = "#9EF2FA", + green = "#67E4B6", + green_bright = "#93ECCB", + yellow = "#FFDB70", + yellow_bright = "#FFE699", + red = "#FF6680", + red_bright = "#FF99AA", + blue = "#66B2FF", + blue_bright = "#80BFFF", + magenta = "#AC8CD9", + magenta_bright= "#BA9FDF", + + -- UI surfaces + ui = "#1A1A1A", -- status/tab/toolbars + panel = "#00000000", -- transparent-ish; we’ll blend to ui + active_line = "#242424", -- approx of #A0A0A020 over bg + selection = "#2A2A2A", -- comfy visual selection + search_bg = "#16454A", -- readable take on #13DAEC40 + gutter_bg = "#00000000", -- transparent in your theme + + -- Diagnostics backgrounds from your JSON (softened) + info_bg = "#26322D", + hint_bg = "#003366", + error_bg = "#660011", + warn_bg = "#806000", +} + +local function set(name, val) vim.api.nvim_set_hl(0, name, val) end + +local function setup_terminal() + -- Map terminal ANSI to your palette + vim.g.terminal_color_0 = p.border -- black + vim.g.terminal_color_8 = p.fg_muted -- bright black (gray) + + vim.g.terminal_color_1 = p.red + vim.g.terminal_color_9 = p.red_bright + + vim.g.terminal_color_2 = p.green + vim.g.terminal_color_10 = p.green_bright + + vim.g.terminal_color_3 = p.yellow + vim.g.terminal_color_11 = p.yellow_bright + + vim.g.terminal_color_4 = p.blue + vim.g.terminal_color_12 = p.blue_bright + + vim.g.terminal_color_5 = p.magenta + vim.g.terminal_color_13 = p.magenta_bright + + vim.g.terminal_color_6 = p.cyan + vim.g.terminal_color_14 = p.cyan_bright + + vim.g.terminal_color_7 = p.fg_muted + vim.g.terminal_color_15 = p.fg +end + +function M.colorscheme() + vim.cmd("highlight clear") + if vim.fn.exists("syntax_on") == 1 then vim.cmd("syntax reset") end + + vim.o.background = "dark" + vim.g.colors_name = "premonition_dark" + setup_terminal() + + --------------------------------------------------------------------------- + -- Core editor + --------------------------------------------------------------------------- + set("Normal", { fg = p.fg, bg = p.bg }) + set("NormalNC", { fg = p.fg_muted, bg = p.bg }) + set("SignColumn", { bg = p.bg }) + set("LineNr", { fg = p.fg_muted, bg = p.bg }) + set("CursorLineNr", { fg = p.cyan, bg = p.active_line, bold = true }) + set("CursorLine", { bg = p.active_line }) + set("CursorColumn", { bg = p.active_line }) + set("ColorColumn", { bg = p.active_line }) + set("VertSplit", { fg = p.border, bg = p.bg }) + set("WinSeparator", { fg = p.border, bg = p.bg }) + + set("Folded", { fg = p.fg_muted, bg = p.active_line }) + set("FoldColumn", { fg = p.fg_muted, bg = p.bg }) + + set("Visual", { bg = p.selection }) + set("Search", { fg = p.bg, bg = p.search_bg }) + set("IncSearch", { fg = p.bg, bg = p.cyan }) + set("MatchParen", { fg = p.yellow, bold = true }) + + set("Pmenu", { fg = p.fg, bg = p.ui }) + set("PmenuSel", { fg = p.bg, bg = p.cyan }) + set("PmenuSbar", { bg = p.active_line }) + set("PmenuThumb", { bg = p.border }) + + set("StatusLine", { fg = p.fg, bg = p.ui }) + set("StatusLineNC", { fg = p.fg_muted, bg = p.ui }) + set("TabLine", { fg = p.fg_muted, bg = p.ui }) + set("TabLineSel", { fg = p.fg, bg = p.active_line, bold = true }) + set("TabLineFill", { bg = p.ui }) + + set("Whitespace", { fg = p.border }) + set("NonText", { fg = p.border }) + set("SpecialKey", { fg = p.border }) + + --------------------------------------------------------------------------- + -- Syntax (Vim groups) + --------------------------------------------------------------------------- + set("Comment", { fg = p.comment, italic = true }) + set("Identifier", { fg = p.fg }) + set("Function", { fg = p.green, bold = true }) + set("Statement", { fg = p.magenta }) -- e.g. if/for/return + set("Keyword", { fg = p.magenta, italic = true }) + set("Conditional", { fg = p.magenta }) + set("Repeat", { fg = p.magenta }) + set("Operator", { fg = p.comment }) + set("Type", { fg = p.blue }) + set("StorageClass", { fg = p.blue }) + set("Structure", { fg = p.blue }) + set("Constant", { fg = p.cyan }) + set("Boolean", { fg = p.cyan }) + set("Number", { fg = p.cyan }) + set("String", { fg = p.cyan }) + set("Character", { fg = p.cyan }) + set("Special", { fg = p.green }) + set("Delimiter", { fg = p.comment }) + + --------------------------------------------------------------------------- + -- Diagnostics (LSP) + --------------------------------------------------------------------------- + set("Error", { fg = p.red }) + set("Todo", { fg = p.yellow, bold = true }) + set("ErrorMsg", { fg = p.red, bg = p.error_bg, bold = true }) + set("WarningMsg", { fg = p.yellow, bg = p.warn_bg }) + set("MoreMsg", { fg = p.green }) + set("Question", { fg = p.green }) + + set("DiagnosticError", { fg = p.red }) + set("DiagnosticWarn", { fg = p.yellow }) + set("DiagnosticInfo", { fg = p.fg_muted }) + set("DiagnosticHint", { fg = p.fg_muted }) + set("DiagnosticOk", { fg = p.green }) + + set("DiagnosticUnderlineError", { sp = p.red, undercurl = true }) + set("DiagnosticUnderlineWarn", { sp = p.yellow, undercurl = true }) + set("DiagnosticUnderlineInfo", { sp = p.blue, undercurl = true }) + set("DiagnosticUnderlineHint", { sp = p.magenta, undercurl = true }) + + set("DiagnosticVirtualTextError", { fg = p.red, bg = p.error_bg }) + set("DiagnosticVirtualTextWarn", { fg = p.yellow, bg = p.warn_bg }) + set("DiagnosticVirtualTextInfo", { fg = p.fg_muted, bg = p.info_bg }) + set("DiagnosticVirtualTextHint", { fg = p.fg_muted, bg = p.hint_bg }) + + --------------------------------------------------------------------------- + -- Diff / Git + --------------------------------------------------------------------------- + set("DiffAdd", { bg = "#1f2b26", fg = p.green }) -- soft green bg + set("DiffChange", { bg = "#2b2b1f", fg = p.yellow }) + set("DiffDelete", { bg = "#2b1f23", fg = p.red }) + set("DiffText", { bg = "#354134", bold = true }) + + set("GitSignsAdd", { fg = p.green }) + set("GitSignsChange", { fg = p.yellow }) + set("GitSignsDelete", { fg = p.red }) + + --------------------------------------------------------------------------- + -- Treesitter (link to Vim groups to keep it lean) + --------------------------------------------------------------------------- + local links = { + -- Basics + ["@comment"] = "Comment", + ["@punctuation"] = "Delimiter", + ["@operator"] = "Operator", + ["@keyword"] = "Keyword", + ["@conditional"] = "Conditional", + ["@repeat"] = "Repeat", + + ["@type"] = "Type", + ["@type.builtin"] = "Type", + ["@type.definition"] = "Type", + ["@storageclass"] = "StorageClass", + + ["@string"] = "String", + ["@string.escape"] = "Special", + ["@string.regex"] = "Special", + ["@character"] = "Character", + ["@boolean"] = "Boolean", + ["@number"] = "Number", + ["@constant"] = "Constant", + + ["@variable"] = "Identifier", + ["@variable.builtin"] = "Identifier", + ["@constant.builtin"] = "Constant", + + ["@function"] = "Function", + ["@function.builtin"] = "Function", + ["@method"] = "Function", + ["@constructor"] = "Function", + ["@parameter"] = "Identifier", + ["@field"] = "Identifier", + ["@property"] = "Identifier", + ["@attribute"] = "Identifier", + + -- Diagnostics / misc + ["@text.literal"] = "String", + ["@tag"] = "Type", + } + for from, to in pairs(links) do set(from, { link = to }) end + + --------------------------------------------------------------------------- + -- Plugin niceties (Telescope minimal) + --------------------------------------------------------------------------- + set("TelescopeNormal", { fg = p.fg, bg = p.ui }) + set("TelescopeBorder", { fg = p.border, bg = p.ui }) + set("TelescopeSelection", { bg = p.selection }) + set("TelescopeMatching", { fg = p.cyan, bold = true }) + + -- Make current line stand out just a bit + set("Cursor", { reverse = true }) + set("VisualNOS", { bg = p.selection }) +end + +M.setup = M.colorscheme +return M + diff --git a/nvim/lua/light_theme.lua b/nvim/lua/light_theme.lua new file mode 100644 index 000000000..725fcee2d --- /dev/null +++ b/nvim/lua/light_theme.lua @@ -0,0 +1,235 @@ +-- lua/colors/premonition_light.lua +-- Mnemonic Light Innovation – Neovim colorscheme (starter) +-- Palette mapped from your JSON. + +local M = {} + +local p = { + -- Core + bg = "#FFFFFF", + fg = "#1A1A1A", + fg_muted = "#505050", + comment = "#808080", + border = "#D0D0D0", + + -- Accents (from JSON) + blue = "#207FDF", + blue_bright = "#66B2FF", + magenta = "#7855AA", + magenta_bright= "#AC8CD9", + green = "#00B371", + green_bright = "#2DD296", + yellow = "#E6AC00", + yellow_bright = "#FFBF00", + red = "#DF2040", + red_bright = "#FF6680", + cyan = "#0FAEBD", + cyan_bright = "#13DAEC", + -- syntax cyan in your block uses 00BBCC; keep both: + cyan_syntax = "#00BBCC", + + -- UI + ui = "#FFFFFF", -- status/tab/toolbars + tabbar = "#F0F0F0", + active_line = "#F6F6F6", -- approx of #A0A0A010 over white + selection = "#EEF6FF", -- gentle selection for light bg + search_bg = "#DCEFF8", -- readable take on #13DAEC40 + + -- Diagnostics backgrounds + error_bg = "#F5DCE0", + warn_bg = "#FDF5D9", + hint_bg = "#DCEAFB", + info_bg = "#E3F5EE", +} + +local function set(name, val) vim.api.nvim_set_hl(0, name, val) end + +local function setup_terminal() + -- Terminal ANSI (from your "terminal.ansi.*") + vim.g.terminal_color_0 = "#1A1A1A" -- black + vim.g.terminal_color_8 = "#808080" -- bright black + + vim.g.terminal_color_1 = p.red + vim.g.terminal_color_9 = p.red_bright + + vim.g.terminal_color_2 = p.green + vim.g.terminal_color_10 = p.green_bright + + vim.g.terminal_color_3 = p.yellow + vim.g.terminal_color_11 = p.yellow_bright + + vim.g.terminal_color_4 = p.blue + vim.g.terminal_color_12 = p.blue_bright + + vim.g.terminal_color_5 = p.magenta + vim.g.terminal_color_13 = p.magenta_bright + + vim.g.terminal_color_6 = p.cyan + vim.g.terminal_color_14 = p.cyan_bright + + vim.g.terminal_color_7 = "#D0D0D0" -- white + vim.g.terminal_color_15 = "#1A1A1A" -- bright white (your JSON maps this dark) +end + +function M.colorscheme() + vim.cmd("highlight clear") + if vim.fn.exists("syntax_on") == 1 then vim.cmd("syntax reset") end + + vim.o.background = "light" + vim.g.colors_name = "premonition_light" + setup_terminal() + + --------------------------------------------------------------------------- + -- Core UI + --------------------------------------------------------------------------- + set("Normal", { fg = p.fg, bg = p.bg }) + set("NormalNC", { fg = p.fg_muted, bg = p.bg }) + set("SignColumn", { bg = p.bg }) + set("LineNr", { fg = p.fg_muted, bg = p.bg }) + set("CursorLineNr", { fg = p.blue, bg = p.active_line, bold = true }) + set("CursorLine", { bg = p.active_line }) + set("CursorColumn", { bg = p.active_line }) + set("ColorColumn", { bg = p.active_line }) + set("VertSplit", { fg = p.border, bg = p.bg }) + set("WinSeparator", { fg = p.border, bg = p.bg }) + + set("Folded", { fg = p.fg_muted, bg = p.active_line }) + set("FoldColumn", { fg = p.fg_muted, bg = p.bg }) + + set("Visual", { bg = p.selection }) + set("Search", { fg = p.fg, bg = p.search_bg }) + set("IncSearch", { fg = p.bg, bg = p.cyan_bright, bold = true }) + set("MatchParen", { fg = p.yellow_bright, bold = true }) + + set("Pmenu", { fg = p.fg, bg = p.ui, blend = 0 }) + set("PmenuSel", { fg = p.bg, bg = p.blue }) + set("PmenuSbar", { bg = p.active_line }) + set("PmenuThumb", { bg = p.border }) + + set("StatusLine", { fg = p.fg, bg = p.ui }) + set("StatusLineNC", { fg = p.fg_muted, bg = p.ui }) + set("TabLine", { fg = p.fg_muted, bg = p.tabbar }) + set("TabLineSel", { fg = p.fg, bg = p.ui, bold = true }) + set("TabLineFill", { bg = p.tabbar }) + + set("Whitespace", { fg = p.border }) + set("NonText", { fg = p.border }) + set("SpecialKey", { fg = p.border }) + + --------------------------------------------------------------------------- + -- Syntax (Vim groups) + --------------------------------------------------------------------------- + set("Comment", { fg = p.comment, italic = true }) + set("Identifier", { fg = p.fg }) + set("Function", { fg = p.green, bold = true }) + set("Statement", { fg = p.magenta }) -- if/for/return + set("Keyword", { fg = p.magenta, italic = true }) + set("Conditional", { fg = p.magenta }) + set("Repeat", { fg = p.magenta }) + set("Operator", { fg = p.comment }) + set("Type", { fg = p.blue }) + set("StorageClass", { fg = p.blue }) + set("Structure", { fg = p.blue }) + set("Constant", { fg = p.cyan_syntax }) + set("Boolean", { fg = p.cyan_syntax }) + set("Number", { fg = p.cyan_syntax }) + set("String", { fg = p.cyan_syntax }) + set("Character", { fg = p.cyan_syntax }) + set("Special", { fg = p.green }) + set("Delimiter", { fg = p.comment }) + + --------------------------------------------------------------------------- + -- Diagnostics (LSP) + --------------------------------------------------------------------------- + set("Error", { fg = p.red }) + set("Todo", { fg = p.yellow_bright, bold = true }) + set("ErrorMsg", { fg = p.red, bg = p.error_bg, bold = true }) + set("WarningMsg", { fg = p.yellow_bright, bg = p.warn_bg }) + set("MoreMsg", { fg = p.green }) + set("Question", { fg = p.green }) + + set("DiagnosticError", { fg = p.red }) + set("DiagnosticWarn", { fg = p.yellow_bright }) + set("DiagnosticInfo", { fg = p.fg_muted }) + set("DiagnosticHint", { fg = p.fg_muted }) + set("DiagnosticOk", { fg = p.green }) + + set("DiagnosticUnderlineError", { sp = p.red, undercurl = true }) + set("DiagnosticUnderlineWarn", { sp = p.yellow_bright, undercurl = true }) + set("DiagnosticUnderlineInfo", { sp = p.blue, undercurl = true }) + set("DiagnosticUnderlineHint", { sp = p.magenta, undercurl = true }) + + set("DiagnosticVirtualTextError", { fg = p.red, bg = p.error_bg }) + set("DiagnosticVirtualTextWarn", { fg = p.yellow_bright, bg = p.warn_bg }) + set("DiagnosticVirtualTextInfo", { fg = p.fg_muted, bg = p.info_bg }) + set("DiagnosticVirtualTextHint", { fg = p.fg_muted, bg = p.hint_bg }) + + --------------------------------------------------------------------------- + -- Diff / Git + --------------------------------------------------------------------------- + set("DiffAdd", { bg = "#E9F6F0", fg = p.green }) + set("DiffChange", { bg = "#F6F1E5", fg = p.yellow }) + set("DiffDelete", { bg = "#F6E9EC", fg = p.red }) + set("DiffText", { bg = "#E3EFE7", bold = true }) + + set("GitSignsAdd", { fg = p.green }) + set("GitSignsChange", { fg = p.yellow }) + set("GitSignsDelete", { fg = p.red }) + + --------------------------------------------------------------------------- + -- Treesitter (link to Vim groups) + --------------------------------------------------------------------------- + local links = { + ["@comment"] = "Comment", + ["@punctuation"] = "Delimiter", + ["@operator"] = "Operator", + ["@keyword"] = "Keyword", + ["@conditional"] = "Conditional", + ["@repeat"] = "Repeat", + + ["@type"] = "Type", + ["@type.builtin"] = "Type", + ["@type.definition"] = "Type", + ["@storageclass"] = "StorageClass", + + ["@string"] = "String", + ["@string.escape"] = "Special", + ["@string.regex"] = "Special", + ["@character"] = "Character", + ["@boolean"] = "Boolean", + ["@number"] = "Number", + ["@constant"] = "Constant", + + ["@variable"] = "Identifier", + ["@variable.builtin"] = "Identifier", + ["@constant.builtin"] = "Constant", + + ["@function"] = "Function", + ["@function.builtin"] = "Function", + ["@method"] = "Function", + ["@constructor"] = "Function", + ["@parameter"] = "Identifier", + ["@field"] = "Identifier", + ["@property"] = "Identifier", + ["@attribute"] = "Identifier", + + ["@text.literal"] = "String", + ["@tag"] = "Type", + } + for from, to in pairs(links) do set(from, { link = to }) end + + --------------------------------------------------------------------------- + -- Telescope (minimal) + --------------------------------------------------------------------------- + set("TelescopeNormal", { fg = p.fg, bg = p.ui }) + set("TelescopeBorder", { fg = p.border, bg = p.ui }) + set("TelescopeSelection", { bg = p.selection }) + set("TelescopeMatching", { fg = p.blue, bold = true }) + + set("Cursor", { reverse = true }) + set("VisualNOS", { bg = p.selection }) +end + +M.setup = M.colorscheme +return M + diff --git a/nvim/lua/packages.lua b/nvim/lua/packages.lua index 1326387c2..6fb4f60db 100644 --- a/nvim/lua/packages.lua +++ b/nvim/lua/packages.lua @@ -4,12 +4,16 @@ vim.api.nvim_set_hl(0, "IlluminatedWordText", { link = "CursorLine" }) vim.api.nvim_set_hl(0, "IlluminatedWordRead", { link = "CursorLine" }) vim.api.nvim_set_hl(0, "IlluminatedWordWrite", { link = "CursorLine" }) +require("gitsigns").setup { + current_line_blame = true, +} + -- for status line things require('lsp-status').register_progress() require('lualine').setup { options = { icons_enabled = true, - theme = '16color', + -- theme = '16color', component_separators = { left = '', right = '' }, section_separators = { left = '', right = '' }, disabled_filetypes = { @@ -108,5 +112,12 @@ lspconfig.nixd.setup { } lspconfig.nil_ls.setup {} --- blame --- require("blame").setup() +require('auto-dark-mode').setup { + set_dark_mode = function() + require('dark_theme').colorscheme() + end, + set_light_mode = function() + require('light_theme').colorscheme() + end, +} + diff --git a/sway/config b/sway/config index dae726a27..9588415f6 100644 --- a/sway/config +++ b/sway/config @@ -34,6 +34,7 @@ bindsym $mod+shift+control+q exec swaylock -f -F -c 000000 --ring-color FFDB70 - # Kill focused window bindsym $mod+Shift+q kill +bindsym $mod+shift+control+4 exec grim -g "$(slurp)" - | wl-copy # Drag floating windows by holding down $mod and left mouse button. # Resize them with right mouse button + $mod. diff --git a/wezterm/wezterm.lua b/wezterm/wezterm.lua index 49cc18310..f88ded085 100644 --- a/wezterm/wezterm.lua +++ b/wezterm/wezterm.lua @@ -40,7 +40,7 @@ if wezterm.gui.get_appearance():find 'Dark' then }, foreground = '#FFFFFF', - background = '#000000', + background = '#080808', } else config.colors = { From 4954ad92f783413d1d9de53f075eb2fc00b49c0a Mon Sep 17 00:00:00 2001 From: parth Date: Tue, 21 Oct 2025 23:49:08 -0400 Subject: [PATCH 122/123] it's pretty now --- nix/common/nvim.nix | 2 +- nvim/init.lua | 14 ++++++- nvim/lua/light_theme.lua | 2 + nvim/lua/packages.lua | 88 ++++++++++++++++++++++++++++++---------- 4 files changed, 81 insertions(+), 25 deletions(-) diff --git a/nix/common/nvim.nix b/nix/common/nvim.nix index ec990403b..37dd5018e 100644 --- a/nix/common/nvim.nix +++ b/nix/common/nvim.nix @@ -9,7 +9,6 @@ cmp-nvim-lsp vim-illuminate lualine-nvim - lsp-status-nvim nvim-tree-lua nvim-lspconfig @@ -18,6 +17,7 @@ nvim-treesitter nvim-treesitter.withAllGrammars gitsigns-nvim + fidget-nvim ]; extraPackages = with pkgs; [ diff --git a/nvim/init.lua b/nvim/init.lua index f009b17b3..791758dec 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1,6 +1,16 @@ vim.g.mapleader = ' '; -require("light_theme").colorscheme() -require("packages") require("keyboard") require("config") + +require('auto-dark-mode').setup { + set_dark_mode = function() + require('dark_theme').colorscheme() + require('packages') + end, + set_light_mode = function() + require('light_theme').colorscheme() + require('packages') + end, +} + diff --git a/nvim/lua/light_theme.lua b/nvim/lua/light_theme.lua index 725fcee2d..e3040f094 100644 --- a/nvim/lua/light_theme.lua +++ b/nvim/lua/light_theme.lua @@ -228,6 +228,8 @@ function M.colorscheme() set("Cursor", { reverse = true }) set("VisualNOS", { bg = p.selection }) + + end M.setup = M.colorscheme diff --git a/nvim/lua/packages.lua b/nvim/lua/packages.lua index 6fb4f60db..1c3abc8b0 100644 --- a/nvim/lua/packages.lua +++ b/nvim/lua/packages.lua @@ -9,32 +9,57 @@ require("gitsigns").setup { } -- for status line things -require('lsp-status').register_progress() +-- require('lsp-status').register_progress() +require('fidget').setup {} require('lualine').setup { options = { icons_enabled = true, - -- theme = '16color', + theme = { + normal = { + a = { fg = "#000000", bg = "#66B2FF", gui = "bold" }, + b = { fg = "#FFFFFF", bg = "#242424" }, + c = { fg = "#FFFFFF", bg = "#1A1A1A" } + }, + insert = { a = { fg = "#1A1A1A", bg = "#FFDB70", gui = "bold" } }, + visual = { a = { fg = "#1A1A1A", bg = "#AC8CD9", gui = "bold" } }, + replace = { a = { fg = "#1A1A1A", bg = "#FF6680", gui = "bold" } }, + command = { a = { fg = "#1A1A1A", bg = "#6EECF7", gui = "bold" } }, + inactive = { + a = { fg = "#D0D0D0", bg = "#1A1A1A" }, + b = { fg = "#D0D0D0", bg = "#1A1A1A" }, + c = { fg = "#D0D0D0", bg = "#1A1A1A" } + }, + }, component_separators = { left = '', right = '' }, section_separators = { left = '', right = '' }, disabled_filetypes = { - statusline = {}, - winbar = {}, + statusline = { 'NvimTree' }, + winbar = { 'NvimTree' }, }, ignore_focus = {}, always_divide_middle = true, globalstatus = false, refresh = { - statusline = 1000, - tabline = 1000, - winbar = 1000, + statusline = 100, + tabline = 100, + winbar = 100, } }, sections = { lualine_a = { 'mode' }, - lualine_b = { 'branch', 'diff', 'diagnostics' }, - lualine_c = { 'filename' }, - lualine_x = { 'encoding', 'fileformat', 'filetype' }, - lualine_y = { "require'lsp-status'.status()" }, + lualine_b = { 'branch', { + 'diff', + symbols = { added = ' ', modified = ' ', removed = ' ' }, + diff_color = { + added = { fg = '#67E4B6' }, + modified = { fg = '#66B2FF' }, + removed = { fg = '#FF6680' }, + }, + color = { bg = '#2A2A2A', fg = '#FFFFFF' }, -- ← custom background here + } }, + lualine_c = {}, + lualine_x = { 'filetype' }, + -- lualine_y = { "require'lsp-status'.status()" }, lualine_z = { 'location' } }, inactive_sections = { @@ -46,7 +71,36 @@ require('lualine').setup { lualine_z = {} }, tabline = {}, - winbar = {}, + winbar = { + lualine_a = { + { + 'filename', + path = 3, -- 0: just filename, 1: relative, 2: absolute, 3: absolute + tilde (~) + symbols = { + modified = ' ●', + readonly = ' ', + unnamed = '[No Name]', + }, + }, + }, + lualine_z = { + { + 'diagnostics', + sources = { 'nvim_diagnostic' }, + sections = { 'error', 'warn', 'info', 'hint' }, + symbols = { error = ' ', warn = ' ', info = ' ', hint = ' ' }, + -- per-severity colors (foregrounds) + diagnostics_color = { + error = { fg = '#FF6680', bg = '#2A2A2A' }, -- red text on dark gray + warn = { fg = '#FFDB70', bg = '#2A2A2A' }, -- yellow + info = { fg = '#6EECF7', bg = '#2A2A2A' }, -- cyan + hint = { fg = '#D0D0D0', bg = '#2A2A2A' }, -- light gray + }, + color = { fg = '#FFFFFF', bg = '#2A2A2A' }, -- set both! + -- always_visible = true, -- uncomment to test even with 0 diags + }, + }, + }, inactive_winbar = {}, extensions = {} } @@ -111,13 +165,3 @@ lspconfig.nixd.setup { } } lspconfig.nil_ls.setup {} - -require('auto-dark-mode').setup { - set_dark_mode = function() - require('dark_theme').colorscheme() - end, - set_light_mode = function() - require('light_theme').colorscheme() - end, -} - From 2fbdec4174051ab1067e42768e6f84aba3b06af6 Mon Sep 17 00:00:00 2001 From: parth Date: Mon, 27 Oct 2025 14:17:18 -0400 Subject: [PATCH 123/123] add ripgrep to macbook --- nix/flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nix/flake.nix b/nix/flake.nix index bbd1eea02..b33103c85 100644 --- a/nix/flake.nix +++ b/nix/flake.nix @@ -33,6 +33,7 @@ ffmpeg_6 fzf + ripgrep lua-language-server zola