Compare commits
39 Commits
9962c7159b
...
main
Author | SHA1 | Date | |
---|---|---|---|
9247e7de79
|
|||
d41f82c771
|
|||
c77fa00f98
|
|||
da8cc2b511
|
|||
ef9c4afff3
|
|||
9dcf45baa5
|
|||
4ac2c06595
|
|||
4935fdbf15
|
|||
ffb23c98fc
|
|||
8bc2b5efe5
|
|||
2ff695ea43
|
|||
b784c01fc2
|
|||
cd640456b1
|
|||
6b7760784a
|
|||
74d4fab26a
|
|||
645a6858b6
|
|||
1af11843ad
|
|||
743332253a
|
|||
f4526ea7a7
|
|||
b2e82b80d3
|
|||
c06a7bffee
|
|||
b8c898b3cc
|
|||
5ff2811927
|
|||
8579ba568b
|
|||
5ed7f948ef
|
|||
4d0a221db4
|
|||
d20b129666
|
|||
b5c3ea0edb
|
|||
7c85a1d3ee
|
|||
c3a8204ad2
|
|||
5fae0b7ece
|
|||
cfae639ad5
|
|||
db749437ee
|
|||
4a3a91dd9c
|
|||
f21f778bd5
|
|||
ed1ccdcaec
|
|||
e6fdd25097
|
|||
58da9200fc
|
|||
b57afeec32
|
@ -151,7 +151,7 @@ function bm {
|
|||||||
if (( ${#__bm_res} != 0 )) && [[ -e "${bm_loc}" ]]; then
|
if (( ${#__bm_res} != 0 )) && [[ -e "${bm_loc}" ]]; then
|
||||||
if [[ -d "${target}" ]]; then
|
if [[ -d "${target}" ]]; then
|
||||||
cd "${target}"
|
cd "${target}"
|
||||||
(( "${BM_CWD_LS:-0}" )) && ls || true
|
[[ "${BM_CWD_LS}" == 'true' ]] && ls || true
|
||||||
elif [[ -e "${bm_loc}" ]]; then
|
elif [[ -e "${bm_loc}" ]]; then
|
||||||
let offset="${__bm_res[2]}"
|
let offset="${__bm_res[2]}"
|
||||||
local rowcol=(${(0)"$(__bm_offset_to_row_col "${bm_loc}" "${offset}")"})
|
local rowcol=(${(0)"$(__bm_offset_to_row_col "${bm_loc}" "${offset}")"})
|
||||||
@ -233,15 +233,15 @@ function bmadd {
|
|||||||
(( ${ans} != 0 )) && return 1
|
(( ${ans} != 0 )) && return 1
|
||||||
fi
|
fi
|
||||||
local res="$(emacsclient --eval \
|
local res="$(emacsclient --eval \
|
||||||
"(let* ((loc \"${loc:gs#\\#\\\\#:gs#\"#\\\"#}\")
|
"(let* ((loc (pop server-eval-args-left))
|
||||||
(name \"${name:gs#\\#\\\\#:gs#\"#\\\"#}\")
|
(name (pop server-eval-args-left))
|
||||||
(res (with-temp-buffer
|
(res (with-temp-buffer
|
||||||
(set-visited-file-name loc t nil)
|
(set-visited-file-name loc t nil)
|
||||||
(bookmark-set name)
|
(bookmark-set name)
|
||||||
(set-buffer-modified-p nil)))
|
(set-buffer-modified-p nil)))
|
||||||
(inhibit-message t))
|
(inhibit-message t))
|
||||||
(bookmark-save)
|
(bookmark-save)
|
||||||
res)")"
|
res)" "${loc}" "${name}")"
|
||||||
[[ "${res}" = 'nil' ]] && printf 'Added bookmark "%s"\n' "${(q)name}" \
|
[[ "${res}" = 'nil' ]] && printf 'Added bookmark "%s"\n' "${(q)name}" \
|
||||||
|| { printf '%s\n' "${res}"; return 1 }
|
|| { printf '%s\n' "${res}"; return 1 }
|
||||||
__bm_update_bookmark_list
|
__bm_update_bookmark_list
|
||||||
@ -269,10 +269,10 @@ function bmrm {
|
|||||||
if read -q; then
|
if read -q; then
|
||||||
printf '\n'
|
printf '\n'
|
||||||
local res="$(emacsclient --eval \
|
local res="$(emacsclient --eval \
|
||||||
"(let* ((res (bookmark-delete \"${1:gs#\\#\\\\#:gs#\"#\\\"#}\"))
|
"(let* ((res (bookmark-delete (pop server-eval-args-left)))
|
||||||
(inhibit-message t))
|
(inhibit-message t))
|
||||||
(bookmark-save)
|
(bookmark-save)
|
||||||
res)")"
|
res)" "${1}")"
|
||||||
[[ "${res}" = 'nil' ]] && printf 'Deleted bookmark "%s"\n' "${(q)1}" \
|
[[ "${res}" = 'nil' ]] && printf 'Deleted bookmark "%s"\n' "${(q)1}" \
|
||||||
|| { printf '%s\n' "${res}"; return 1 }
|
|| { printf '%s\n' "${res}"; return 1 }
|
||||||
|
|
||||||
@ -289,8 +289,8 @@ compdef _bmrm bmrm
|
|||||||
|
|
||||||
function __bm_precmd_hook {
|
function __bm_precmd_hook {
|
||||||
# Auto reload
|
# Auto reload
|
||||||
if (( "${BM_AUTO_RELOAD:-0}" )) &&
|
if [[ "${BM_AUTO_RELOAD}" == true ]] &&
|
||||||
(( ${__bm_last_read_time} < "$(zstat +mtime "${BM_BOOKMARK_PATH}")" )); then
|
(( ${__bm_last_read_time} < $(zstat +mtime "${BM_BOOKMARK_PATH}") )); then
|
||||||
__bm_update_bookmark_list
|
__bm_update_bookmark_list
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
121
init.zsh
121
init.zsh
@ -17,7 +17,6 @@ function load_plugin {
|
|||||||
function cmd_exists {
|
function cmd_exists {
|
||||||
hash "${1}" >/dev/null 2>&1
|
hash "${1}" >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
# source_user_file <name>
|
# source_user_file <name>
|
||||||
function source_user_file {
|
function source_user_file {
|
||||||
local machine_specific="${ZSH_CONFIG_DIR}/${1}.${HOST}.zsh"
|
local machine_specific="${ZSH_CONFIG_DIR}/${1}.${HOST}.zsh"
|
||||||
@ -32,14 +31,47 @@ function source_user_file {
|
|||||||
# Load user early init file
|
# Load user early init file
|
||||||
source_user_file "early-init"
|
source_user_file "early-init"
|
||||||
|
|
||||||
|
# Load distrobox early init file
|
||||||
|
local is_in_distrobox=false
|
||||||
|
if [[ -e /run/.containerenv ]] && cmd_exists distrobox-host-exec; then
|
||||||
|
is_in_distrobox=true
|
||||||
|
local ctenv=("${(@f)"$(</run/.containerenv)"}")
|
||||||
|
for line in ${ctenv}; do
|
||||||
|
if [[ "${line}" == 'name='* ]]; then
|
||||||
|
export DISTROBOX_MY_NAME="${(Q)${line:5}}"
|
||||||
|
if [[ -d "${HOME}/src/compat/${DISTROBOX_MY_NAME}" ]]; then
|
||||||
|
export DISTROBOX_MY_COMPAT="${HOME}/src/compat/${DISTROBOX_MY_NAME}"
|
||||||
|
local init_file="${DISTROBOX_MY_COMPAT}/early-init.zsh"
|
||||||
|
[[ -e "${init_file}" ]] && source "${init_file}"
|
||||||
|
fi
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
# Some options
|
# Some options
|
||||||
setopt autocd extendedglob rm_star_silent completealiases rc_quotes histignorespace
|
setopt autocd extendedglob rm_star_silent completealiases rc_quotes histignorespace
|
||||||
unsetopt beep notify
|
unsetopt beep notify
|
||||||
|
|
||||||
# Some general, random configuration
|
# Some general, random configuration
|
||||||
# History stuff
|
# History stuff
|
||||||
[ -v HISTFILE ] || HISTFILE="${HOME}/.cache/zsh/history"
|
if [[ -v INSIDE_EMACS ]]; then
|
||||||
|
() {
|
||||||
|
emulate -L zsh
|
||||||
|
set -o rematchpcre
|
||||||
|
if [[ "${HISTFILE}" =~ '^~([^/]*)($|/.*)' ]]; then
|
||||||
|
local user="${match[1]}"
|
||||||
|
local rest="${match[2]}"
|
||||||
|
if [[ -z "${user}" ]]; then
|
||||||
|
HISTFILE="${HOME}${rest}"
|
||||||
|
else
|
||||||
|
HISTFILE="${userdirs[${user}]}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
fi
|
||||||
[ ! -d "${HISTFILE:h}" ] && mkdir -p "${HISTFILE:h}"
|
[ ! -d "${HISTFILE:h}" ] && mkdir -p "${HISTFILE:h}"
|
||||||
|
[ -v HISTFILE ] || HISTFILE="${HOME}/.cache/zsh/history"
|
||||||
HISTSIZE=1000
|
HISTSIZE=1000
|
||||||
SAVEHIST=10000
|
SAVEHIST=10000
|
||||||
|
|
||||||
@ -69,6 +101,7 @@ else
|
|||||||
__zsh_sudo_cmd=sudo
|
__zsh_sudo_cmd=sudo
|
||||||
alias sudo='sudo '
|
alias sudo='sudo '
|
||||||
alias se='sudoedit '
|
alias se='sudoedit '
|
||||||
|
alias doas='sudo '
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Emacs and Neovim stuff
|
# Emacs and Neovim stuff
|
||||||
@ -78,17 +111,31 @@ if [[ -v NVIM ]]; then
|
|||||||
alias nvim=nvr
|
alias nvim=nvr
|
||||||
alias e=nvr
|
alias e=nvr
|
||||||
alias emacs=nvr
|
alias emacs=nvr
|
||||||
|
elif [[ "${is_in_distrobox}" == true ]]; then
|
||||||
|
if [[ -v INSIDE_EMACS ]]; then
|
||||||
|
[[ -z "${XDG_RUNTIME_DIR}" ]] && \
|
||||||
|
export XDG_RUNTIME_DIR="/run/user/${UID}"
|
||||||
|
export EDITOR='distrobox-host-exec emacsclient -a nvim '
|
||||||
|
alias emacs='distrobox-host-exec emacsclient -a nvim '
|
||||||
|
else
|
||||||
|
export EDITOR='distrobox-host-exec emacsclient -a nvim -c '
|
||||||
|
alias emacs='distrobox-host-exec emacsclient -a nvim -c '
|
||||||
|
fi
|
||||||
|
alias n='emacs '
|
||||||
|
alias e='emacs '
|
||||||
elif [[ -v INSIDE_EMACS ]]; then
|
elif [[ -v INSIDE_EMACS ]]; then
|
||||||
export EDITOR='emacsclient'
|
export EDITOR='emacsclient'
|
||||||
alias e='emacsclient '
|
alias e='emacsclient '
|
||||||
alias emacs='emacsclient '
|
alias emacs='emacsclient '
|
||||||
alias n='emacsclient '
|
alias n='emacsclient '
|
||||||
|
alias nvim='emacsclient '
|
||||||
else
|
else
|
||||||
export EDITOR='emacsclient -a nvim -nw'
|
export EDITOR='emacsclient -a nvim -nw'
|
||||||
# Because I keep using n by mistake
|
# Because I keep using n by mistake
|
||||||
alias emacs="${EDITOR} "
|
alias emacs="${EDITOR} "
|
||||||
alias n=emacs
|
alias n=emacs
|
||||||
alias e=emacs
|
alias e=emacs
|
||||||
|
alias nvim=emacs
|
||||||
fi
|
fi
|
||||||
export VISUAL="${EDITOR}"
|
export VISUAL="${EDITOR}"
|
||||||
|
|
||||||
@ -120,30 +167,41 @@ fi
|
|||||||
export LESS="--mouse"
|
export LESS="--mouse"
|
||||||
|
|
||||||
# Bat configuration
|
# Bat configuration
|
||||||
|
local bat_exec
|
||||||
if cmd_exists bat; then
|
if cmd_exists bat; then
|
||||||
|
bat_exec=bat
|
||||||
|
elif cmd_exists batcat; then
|
||||||
|
bat_exec=batcat;
|
||||||
|
alias bat=batcat
|
||||||
|
fi
|
||||||
|
if ! [[ -z "${bat_exec}" ]]; then
|
||||||
# Pager
|
# Pager
|
||||||
export PAGER="bat --paging=always"
|
export PAGER="${bat_exec} --paging=always"
|
||||||
|
|
||||||
# Less syntax highlighting in interactive shells
|
# Less syntax highlighting in interactive shells
|
||||||
alias less="bat --paging=always"
|
alias less="${bat_exec} --paging=always"
|
||||||
|
|
||||||
# Use bat instead of cat
|
# Use bat instead of cat
|
||||||
alias cat="bat --paging=never"
|
alias cat="${bat_exec} --paging=never"
|
||||||
alias pcat="bat -pp"
|
alias pcat="${bat_exec} -pp"
|
||||||
alias ncat="bat -pp --color=never"
|
alias ncat="${bat_exec} -pp --color=never"
|
||||||
|
|
||||||
# Bat as man pager
|
# Bat as man pager
|
||||||
export MANPAGER="zsh -c 'col -bx | bat -l man --paging=always --style=plain'"
|
if [[ "${bat_exec}" = (bat|*/bat) ]]; then
|
||||||
export MANROFFOPT="-c"
|
export MANPAGER="zsh -c 'col -bx | ${bat_exec} -l man --paging=always --style=plain'"
|
||||||
|
export MANROFFOPT="-c"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
unset bat_exec
|
||||||
|
|
||||||
# Eza configuration
|
# Eza configuration
|
||||||
if cmd_exists eza; then
|
# Don't define an alias if ls is already an alias
|
||||||
|
if cmd_exists eza && ! alias ls >/dev/null; then
|
||||||
alias ls="eza --git -F=auto"
|
alias ls="eza --git -F=auto"
|
||||||
alias la="ls -a"
|
|
||||||
alias l="ls -l"
|
|
||||||
alias ll="ls -al"
|
|
||||||
fi
|
fi
|
||||||
|
alias la="ls -a"
|
||||||
|
alias l="ls -l"
|
||||||
|
alias ll="ls -al"
|
||||||
|
|
||||||
# Delta configuration
|
# Delta configuration
|
||||||
if cmd_exists delta; then
|
if cmd_exists delta; then
|
||||||
@ -196,7 +254,7 @@ function overwrite-mode {
|
|||||||
zle -N overwrite-mode
|
zle -N overwrite-mode
|
||||||
|
|
||||||
# Fancy prompt (starship)
|
# Fancy prompt (starship)
|
||||||
eval "$(starship init zsh)"
|
cmd_exists starship && eval "$(starship init zsh)"
|
||||||
# Change cursor shape for different vi modes.
|
# Change cursor shape for different vi modes.
|
||||||
function __zsh_vim_key_prompt_handler {
|
function __zsh_vim_key_prompt_handler {
|
||||||
SPACESHIP_CHAR_SYMBOL="❮"
|
SPACESHIP_CHAR_SYMBOL="❮"
|
||||||
@ -247,23 +305,27 @@ if cmd_exists pyenv; then
|
|||||||
export PYENV_ROOT="${HOME}/.pyenv"
|
export PYENV_ROOT="${HOME}/.pyenv"
|
||||||
[[ -d "${PYENV_ROOT/bin}" ]] && export PATH="${PYENV_ROOT}/bin:${PATH}"
|
[[ -d "${PYENV_ROOT/bin}" ]] && export PATH="${PYENV_ROOT}/bin:${PATH}"
|
||||||
eval "$(pyenv init - zsh)"
|
eval "$(pyenv init - zsh)"
|
||||||
|
eval "$(pyenv virtualenv-init - zsh)"
|
||||||
|
__zsh_fix_pyenv_prompt() {
|
||||||
|
if [[ -v _OLD_VIRTUAL_PS1 ]]; then
|
||||||
|
PS1="${_OLD_VIRTUAL_PS1}"
|
||||||
|
unset _OLD_VIRTUAL_PS1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
precmd_functions+=(__zsh_fix_pyenv_prompt)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Bookmarks
|
# Bookmarks
|
||||||
[[ -v BM_CWD_LS ]] || BM_CWD_LS=1
|
if cmd_exists emacs; then
|
||||||
[[ -v BM_MODE ]] || BM_MODE=daemon
|
[[ -v BM_CWD_LS ]] || BM_CWD_LS=true
|
||||||
[[ -v BM_AUTO_RELOAD ]] || BM_AUTO_RELOAD=1
|
[[ -v BM_MODE ]] || BM_MODE=daemon
|
||||||
source "${ZSH_CONFIG_DIR}/emacs-bookmark.zsh"
|
[[ -v BM_AUTO_RELOAD ]] || BM_AUTO_RELOAD=true
|
||||||
|
source "${ZSH_CONFIG_DIR}/emacs-bookmark.zsh"
|
||||||
|
fi
|
||||||
|
|
||||||
# Platform specific stuff
|
# Platform specific stuff
|
||||||
[ -f /usr/bin/pacman ] && source "${ZSH_CONFIG_DIR}/arch.zsh"
|
[ -f /usr/bin/pacman ] && source "${ZSH_CONFIG_DIR}/arch.zsh"
|
||||||
|
|
||||||
# Ros2 instll on arch
|
|
||||||
if [[ -d /opt/ros/humble/ ]]; then
|
|
||||||
# ZSH_ROS2_ROOT=/opt/ros/humble/
|
|
||||||
source "${ZSH_CONFIG_DIR}/lazy-ros2.zsh"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# FZF Integration
|
# FZF Integration
|
||||||
load_plugin fzf-tab
|
load_plugin fzf-tab
|
||||||
# Disable sort when completing `git checkout`
|
# Disable sort when completing `git checkout`
|
||||||
@ -289,6 +351,12 @@ bindkey '^ ' autosuggest-accept
|
|||||||
# Load user init file
|
# Load user init file
|
||||||
source_user_file 'local'
|
source_user_file 'local'
|
||||||
|
|
||||||
|
# Load distrobox normal init file
|
||||||
|
if [[ -v DISTROBOX_MY_COMPAT ]] && \
|
||||||
|
[[ -f "${DISTROBOX_MY_COMPAT}/init.zsh" ]]; then
|
||||||
|
source "${DISTROBOX_MY_COMPAT}/init.zsh"
|
||||||
|
fi
|
||||||
|
|
||||||
# THE FOLLOWING PLUGINS MUST COME LAST
|
# THE FOLLOWING PLUGINS MUST COME LAST
|
||||||
|
|
||||||
# More completions
|
# More completions
|
||||||
@ -321,12 +389,15 @@ if cmd_exists fortune && cmd_exists cowsay; then
|
|||||||
fortune | cowsay -felephant-in-snake -n
|
fortune | cowsay -felephant-in-snake -n
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# [[ -v EAT_SHELL_INTEGRATION_DIR ]] && source "${EAT_SHELL_INTEGRATION_DIR}/zsh"
|
||||||
|
|
||||||
# Clean up internal functions
|
# Clean up internal functions
|
||||||
unfunction load_plugin
|
unfunction load_plugin
|
||||||
unfunction cmd_exists
|
unfunction cmd_exists
|
||||||
unfunction source_user_file
|
unfunction source_user_file
|
||||||
|
unset is_in_distrobox
|
||||||
|
|
||||||
(( ZSH_INIT_TIME="${EPOCHREALTIME}" - __init_zsh_start ))
|
let ZSH_INIT_TIME="$(( EPOCHREALTIME - __init_zsh_start ))"
|
||||||
function zsh-init-time {
|
function zsh-init-time {
|
||||||
printf 'Zsh initialization took: %05fms\n' "$(( ZSH_INIT_TIME * 1000 ))"
|
printf 'Zsh initialization took: %05fms\n' "$(( ZSH_INIT_TIME * 1000 ))"
|
||||||
}
|
}
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
# Lazy-load ros2 stuff
|
|
||||||
|
|
||||||
function __zsh_load_ros2 {
|
|
||||||
export AMENT_PREFIX_PATH=/opt/ros/humble
|
|
||||||
export CMAKE_PREFIX_PATH=/opt/ros/humble
|
|
||||||
export COLCON_PREFIX_PATH=/opt/ros/humble
|
|
||||||
export ROS_DISTRO=humble
|
|
||||||
export ROS_LOCALHOST_ONLY=0
|
|
||||||
export ROS_PYTHON_VERSION=3
|
|
||||||
export ROS_VERSION=2
|
|
||||||
export LD_LIBRARY_PATH="/opt/ros/humble/opt/rviz_ogre_vendor/lib:/opt/ros/humble/lib:${LD_LIBRARY_PATH}"
|
|
||||||
export PATH="/opt/ros/humble/bin:${PATH}"
|
|
||||||
export PKG_CONFIG_PATH="/opt/ros/humble/lib/pkgconfig:${PKG_CONFIG_PATH}"
|
|
||||||
export PYTHONPATH="/opt/ros/humble/lib/python3.13/dist-packages/:/opt/ros/humble/lib/python3.13/site-packages:${PYTHONPATH}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# (( ${+ZSH_ROS2_ROOT} )) || return
|
|
||||||
|
|
||||||
local defined=()
|
|
||||||
|
|
||||||
local file
|
|
||||||
for file in "${ZSH_ROS2_ROOT}/bin/"*; do
|
|
||||||
local base="${file:t}"
|
|
||||||
hash -- "${base}" 2>/dev/null && continue
|
|
||||||
defined+=("${base}")
|
|
||||||
done
|
|
||||||
|
|
||||||
local undef_args=() def
|
|
||||||
for def in ${defined}; do
|
|
||||||
undef_args+=("${(q)def}")
|
|
||||||
done
|
|
||||||
|
|
||||||
local exec
|
|
||||||
for exec in ${defined}; do
|
|
||||||
eval "
|
|
||||||
function \${(q)exec} {
|
|
||||||
printf 'Setting up ros2 with \"%s\"...\n\n' \\
|
|
||||||
\"\${(q)ZSH_ROS2_ROOT%/}/setup.zsh\"
|
|
||||||
unfunction ${undef_args}
|
|
||||||
__zsh_load_ros2 ||
|
|
||||||
{ echo 'Failed to load ros2 libraries!'; return }
|
|
||||||
(( \${#} == 0 )) && ${(q)exec} || ${(q)exec} \"\${@}\"
|
|
||||||
}"
|
|
||||||
done
|
|
||||||
|
|
||||||
unset exec def file defined undef_args
|
|
Submodule plugins/fast-syntax-highlighting updated: cf318e06a9...3d574ccf48
Submodule plugins/fzf-tab updated: 6aced3f35d...fc6f0dcb2d
Submodule plugins/zsh-autosuggestions updated: 0e810e5afa...85919cd1ff
Submodule plugins/zsh-completions updated: 85e041be36...5f24f3bc42
Reference in New Issue
Block a user