Initial commit, zsh config

This commit is contained in:
naoto 2024-08-09 22:39:10 +02:00
commit b525faea7e
14 changed files with 223 additions and 0 deletions

9
.gitmodules vendored Normal file
View file

@ -0,0 +1,9 @@
[submodule "zsh/.zsh/zsh-history-substring-search"]
path = zsh/.zsh/zsh-history-substring-search
url = git@rustylab.net:mirrors/zsh-history-substring-search.git
[submodule "zsh/.zsh/zsh-autosuggestions"]
path = zsh/.zsh/zsh-autosuggestions
url = git@rustylab.net:mirrors/zsh-autosuggestions.git
[submodule "zsh/.zsh/zsh-syntax-highlighting"]
path = zsh/.zsh/zsh-syntax-highlighting
url = git@rustylab.net:mirrors/zsh-syntax-highlighting.git

22
setup Executable file
View file

@ -0,0 +1,22 @@
#!/usr/bin/env bash
install_all () {
ls | grep -v setup | while read app; do
echo install_config $app
done
}
install_config () {
[ -z "${1+x}" ] && echo "Usage: $0 install <app>" && return 1
stow $1
}
uninstall_config () {
stow -D $1
}
case $1 in
install) install_config $2;;
install-all) install_all;;
uninstall) uninstall_config $2;;
esac

15
zsh/.zsh/aliases.zsh Normal file
View file

@ -0,0 +1,15 @@
alias ls="ls --color"
alias swayimg="swayimg -w image -c info.show=no -c general.position=20\,20"
alias podman="sudo podman"
findfile () {
local search
if [ "$1" = "--update" ]; then
sudo updatedb
search=$2
else
search=$1
fi
locate "$PWD*$search*"
}

6
zsh/.zsh/bun.zsh Normal file
View file

@ -0,0 +1,6 @@
# bun completions
[ -s "$HOME/.bun/_bun" ] && source "$HOME/.bun/_bun"
# bun
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"

View file

@ -0,0 +1,14 @@
# This loads zoxide and fnm in background
# Generates script and sources it when it's ready.
# Makes startup times faster
trap 'source /tmp/zsh_deferred_source.$$ && rm /tmp/zsh_deferred_source.$$' USR2
zi () {}
deferred_source_prepare () {
zoxide init zsh > /tmp/zsh_deferred_source.$$
fnm env --use-on-cd --shell zsh >> /tmp/zsh_deferred_source.$$
sleep 0.2
kill -s USR2 $$ > /dev/null 2> /dev/null
}
deferred_source_prepare &!

33
zsh/.zsh/git_branch.zsh Normal file
View file

@ -0,0 +1,33 @@
GIT_BRANCH=
GIT_BG_PID=0
trap 'git_callback' USR1
get_git_branch () {
git rev-parse --abbrev-ref HEAD 2> /dev/null > "/tmp/zsh_git_branch.$$"
# git rev-parse --verify REBASE_HEAD 2> /dev/null && echo 1 > "/tmp/zsh_git_rebase.$$"
kill -s USR1 $$ > /dev/null 2> /dev/null
}
git_branch_bg () {
if [[ $GIT_BG_PID != 0 ]]; then
kill -s HUP $GIT_BG_PID > /dev/null 2>&1
fi
if [ -f "/tmp/zsh_git_branch.$$" ]; then
rm "/tmp/zsh_git_branch.$$"
fi
get_git_branch &!
GIT_BG_PID=$!
}
git_callback () {
GIT_BRANCH=$(cat "/tmp/zsh_git_branch.$$")
rm "/tmp/zsh_git_branch.$$"
update_right_prompt
GIT_BG_PID=0
}
autoload -U add-zsh-hook
# add-zsh-hook chpwd git_branch_bg
add-zsh-hook precmd git_branch_bg
git_branch_bg

15
zsh/.zsh/prompt.zsh Normal file
View file

@ -0,0 +1,15 @@
PS1='%F{blue}%~ %(?.%F{green}.%F{red})%#%f '
source "$HOME/.zsh/vim-mode.zsh"
update_right_prompt () {
RPS1="%F{blue}-- $VI_KEYMAP --%f"
if [ ! -z "$GIT_BRANCH" ]; then
RPS1="%F{red} $GIT_BRANCH%f $RPS1"
fi
zle reset-prompt 2> /dev/null
}
update_right_prompt
source "$HOME/.zsh/git_branch.zsh"

23
zsh/.zsh/runfile.zsh Normal file
View file

@ -0,0 +1,23 @@
# It's like makefile/justfile but using a simple script!
# usage: run <arguments passed to runfile>
# runfile can be placed in CWD or parents
run () {
local runfile
runfile="$(_run "$PWD")" && "$runfile" "$@"
}
_run () {
RUNFILE_DIR=$1
if [ ! -e "$RUNFILE_DIR/runfile" ] && [ ! -e "$RUNFILE_DIR/.runfile" ]; then
if [ "$RUNFILE_DIR" = "/" ]; then
echo "Runfile not found" 1>&2; return 1
else
_run "$(dirname $RUNFILE_DIR)"
fi
elif [ -e "$RUNFILE_DIR/runfile" ]; then
echo "$RUNFILE_DIR/runfile"
elif [ -e "$RUNFILE_DIR/.runfile" ]; then
echo "$RUNFILE_DIR/.runfile"
fi
}

39
zsh/.zsh/vim-mode.zsh Normal file
View file

@ -0,0 +1,39 @@
bindkey -v
export KEYTIMEOUT=1
autoload -U add-zle-hook-widget
line_pre_redraw () {
local previous_vi_keymap="${VI_KEYMAP}"
case "${KEYMAP}" in
vicmd)
case "${REGION_ACTIVE}" in
1)
VI_KEYMAP="VISUAL"
;;
2)
VI_KEYMAP="V-LINE"
;;
*)
VI_KEYMAP="NORMAL"
;;
esac
;;
viins|main)
if [[ "${ZLE_STATE}" == *overwrite* ]]; then
VI_KEYMAP="REPLACE"
else
VI_KEYMAP="INSERT"
fi
;;
esac
if [[ "${VI_KEYMAP}" != "${previous_vi_keymap}" ]]; then
update_right_prompt
fi
}
VI_KEYMAP="INSERT"
add-zle-hook-widget zle-line-pre-redraw line_pre_redraw

@ -0,0 +1 @@
Subproject commit c3d4e576c9c86eac62884bd47c01f6faed043fc5

@ -0,0 +1 @@
Subproject commit 87ce96b1862928d84b1afe7c173316614b30e301

@ -0,0 +1 @@
Subproject commit e0165eaa730dd0fa321a6a6de74f092fe87630b0

3
zsh/.zshenv Normal file
View file

@ -0,0 +1,3 @@
export GTK_THEME=Adwaita:dark
export PATH="$HOME/.local/bin":$PATH
export EDITOR=nvim

41
zsh/.zshrc Normal file
View file

@ -0,0 +1,41 @@
source "$HOME/.zsh/deferred-eval-source.zsh" # Useful when you use fnm (https://github.com/Schniz/fnm) and zoxide (https://github.com/ajeetdsouza/zoxide), remove otherwise
HISTFILE=~/.zsh_history # File where history is stored
HISTSIZE=1000000
SAVEHIST=1000000
setopt appendhistory # Enable history
setopt extendedhistory # Timestamps in history
setopt incappendhistory # Write history immediately
setopt histfindnodups # Skip duplicates in history
zstyle ':completion:*' menu select # Highlight completion option
bindkey -v '^?' backward-delete-char # BACKSPACE key enable
bindkey -v "^[[H" beginning-of-line # HOME key enable
bindkey -v "^[[F" end-of-line # END key enable
bindkey -v "^[[3~" delete-char # DELETE key enable
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND="fg=blue,bold"
zstyle ":completion:*:commands" rehash 1 # Better completion for newly installed commands (ignores cache)
bindkey '^[[A' history-substring-search-up # Arrow up for history search up
bindkey '^[[B' history-substring-search-down # Arrow down for history search down
bindkey -M vicmd 'k' history-substring-search-up # K for history search up in vim normal mode
bindkey -M vicmd 'j' history-substring-search-down # J for history search down in vim normal mode
bindkey '^[[Z' reverse-menu-complete # SHIFT+TAB for previous completion
autoload -Uz compinit # Enable completions
compinit
source "$HOME/.zsh/aliases.zsh"
source "$HOME/.zsh/prompt.zsh"
source "$HOME/.zsh/runfile.zsh"
source "$HOME/.zsh/bun.zsh" # Useful when you use bun (https://bun.sh/), remove otherwise
# External plugins
source "$HOME/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh"
source "$HOME/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
source "$HOME/.zsh/zsh-history-substring-search/zsh-history-substring-search.zsh"