Compare commits

...

39 Commits

Author SHA1 Message Date
9247e7de79 Update submodules 2025-08-02 15:52:34 +09:00
d41f82c771 Update submodules 2025-06-29 18:49:21 +09:00
c77fa00f98 Fix pyenv 2025-06-21 18:28:35 +09:00
da8cc2b511 Update submodules 2025-05-19 22:16:31 +09:00
ef9c4afff3 Update submodules 2025-04-30 21:43:41 +09:00
9dcf45baa5 Update submodules 2025-04-17 21:28:52 +09:00
4ac2c06595 Merge branch 'main' of git.zander.im:Zander671/zsh-config 2025-03-18 22:53:43 +09:00
4935fdbf15 Update submodules 2025-03-18 22:53:29 +09:00
ffb23c98fc Remove ros2 stuff 2025-03-18 22:53:12 +09:00
8bc2b5efe5 Update aliases 2025-03-01 21:42:25 -08:00
2ff695ea43 Undo last commit 2025-02-26 15:09:46 -08:00
b784c01fc2 Source $EAT_SHELL_INTEGRATION_DIR/zsh 2025-02-26 14:48:24 -08:00
cd640456b1 Update submodules 2025-02-24 21:54:04 -08:00
6b7760784a Use the new server-eval-args-left 2025-02-24 19:10:33 -08:00
74d4fab26a Fix the last commit 2025-02-22 03:50:38 -08:00
645a6858b6 Fix tramp creating random files 2025-02-22 03:49:54 -08:00
1af11843ad Fix last commit 2025-02-20 19:28:55 -08:00
743332253a More bat stuff 2025-02-20 19:24:56 -08:00
f4526ea7a7 Fix bat in distrobox 2025-02-20 18:48:41 -08:00
b2e82b80d3 Improve distrobox detection 2025-02-18 13:13:15 -08:00
c06a7bffee Fix last commit 2025-02-18 06:25:44 -08:00
b8c898b3cc Some container stuff 2025-02-18 06:25:06 -08:00
5ff2811927 (Even x3) more changes to distrobox stuff 2025-02-17 21:27:08 -08:00
8579ba568b (Even even) more stuff for distrobox 2025-02-17 02:21:03 -08:00
5ed7f948ef Fix the last commit 2025-02-17 02:09:01 -08:00
4d0a221db4 Change editor for distrobox (again) 2025-02-17 02:07:08 -08:00
d20b129666 More stuff for older versions 2025-02-17 01:57:44 -08:00
b5c3ea0edb Make emacs-bookmark.zsh work on older versions of zsh 2025-02-17 01:10:03 -08:00
7c85a1d3ee (Even) more ros2 stuff 2025-02-17 00:50:44 -08:00
c3a8204ad2 Update lazy-ros2.zsh 2025-02-17 00:13:11 -08:00
5fae0b7ece Fix formatting 2025-02-17 00:05:33 -08:00
cfae639ad5 A few more compatability things 2025-02-16 23:58:26 -08:00
db749437ee More distrobox changes 2025-02-16 23:13:58 -08:00
4a3a91dd9c Add some more distrobox stuff 2025-02-16 23:06:32 -08:00
f21f778bd5 Alias doas to sudo if doas is not installed 2025-02-16 20:53:51 -08:00
ed1ccdcaec Add conditions to some init stuff 2025-02-16 20:52:45 -08:00
e6fdd25097 Remove debug statements 2025-02-15 22:43:00 -08:00
58da9200fc Merge branch 'main' of git.zander.im:Zander671/zsh-config 2025-02-15 22:41:31 -08:00
b57afeec32 Fix ros2 stuff 2025-02-15 22:41:04 -08:00
7 changed files with 108 additions and 83 deletions

View File

@ -151,7 +151,7 @@ function bm {
if (( ${#__bm_res} != 0 )) && [[ -e "${bm_loc}" ]]; then
if [[ -d "${target}" ]]; then
cd "${target}"
(( "${BM_CWD_LS:-0}" )) && ls || true
[[ "${BM_CWD_LS}" == 'true' ]] && ls || true
elif [[ -e "${bm_loc}" ]]; then
let offset="${__bm_res[2]}"
local rowcol=(${(0)"$(__bm_offset_to_row_col "${bm_loc}" "${offset}")"})
@ -233,15 +233,15 @@ function bmadd {
(( ${ans} != 0 )) && return 1
fi
local res="$(emacsclient --eval \
"(let* ((loc \"${loc:gs#\\#\\\\#:gs#\"#\\\"#}\")
(name \"${name:gs#\\#\\\\#:gs#\"#\\\"#}\")
"(let* ((loc (pop server-eval-args-left))
(name (pop server-eval-args-left))
(res (with-temp-buffer
(set-visited-file-name loc t nil)
(bookmark-set name)
(set-buffer-modified-p nil)))
(inhibit-message t))
(bookmark-save)
res)")"
res)" "${loc}" "${name}")"
[[ "${res}" = 'nil' ]] && printf 'Added bookmark "%s"\n' "${(q)name}" \
|| { printf '%s\n' "${res}"; return 1 }
__bm_update_bookmark_list
@ -269,10 +269,10 @@ function bmrm {
if read -q; then
printf '\n'
local res="$(emacsclient --eval \
"(let* ((res (bookmark-delete \"${1:gs#\\#\\\\#:gs#\"#\\\"#}\"))
"(let* ((res (bookmark-delete (pop server-eval-args-left)))
(inhibit-message t))
(bookmark-save)
res)")"
res)" "${1}")"
[[ "${res}" = 'nil' ]] && printf 'Deleted bookmark "%s"\n' "${(q)1}" \
|| { printf '%s\n' "${res}"; return 1 }
@ -289,8 +289,8 @@ compdef _bmrm bmrm
function __bm_precmd_hook {
# Auto reload
if (( "${BM_AUTO_RELOAD:-0}" )) &&
(( ${__bm_last_read_time} < "$(zstat +mtime "${BM_BOOKMARK_PATH}")" )); then
if [[ "${BM_AUTO_RELOAD}" == true ]] &&
(( ${__bm_last_read_time} < $(zstat +mtime "${BM_BOOKMARK_PATH}") )); then
__bm_update_bookmark_list
fi
}

111
init.zsh
View File

@ -17,7 +17,6 @@ function load_plugin {
function cmd_exists {
hash "${1}" >/dev/null 2>&1
}
# source_user_file <name>
function source_user_file {
local machine_specific="${ZSH_CONFIG_DIR}/${1}.${HOST}.zsh"
@ -32,14 +31,47 @@ function source_user_file {
# Load user early init file
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
setopt autocd extendedglob rm_star_silent completealiases rc_quotes histignorespace
unsetopt beep notify
# Some general, random configuration
# 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}"
[ -v HISTFILE ] || HISTFILE="${HOME}/.cache/zsh/history"
HISTSIZE=1000
SAVEHIST=10000
@ -69,6 +101,7 @@ else
__zsh_sudo_cmd=sudo
alias sudo='sudo '
alias se='sudoedit '
alias doas='sudo '
fi
# Emacs and Neovim stuff
@ -78,17 +111,31 @@ if [[ -v NVIM ]]; then
alias nvim=nvr
alias e=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
export EDITOR='emacsclient'
alias e='emacsclient '
alias emacs='emacsclient '
alias n='emacsclient '
alias nvim='emacsclient '
else
export EDITOR='emacsclient -a nvim -nw'
# Because I keep using n by mistake
alias emacs="${EDITOR} "
alias n=emacs
alias e=emacs
alias nvim=emacs
fi
export VISUAL="${EDITOR}"
@ -120,30 +167,41 @@ fi
export LESS="--mouse"
# Bat configuration
local bat_exec
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
export PAGER="bat --paging=always"
export PAGER="${bat_exec} --paging=always"
# Less syntax highlighting in interactive shells
alias less="bat --paging=always"
alias less="${bat_exec} --paging=always"
# Use bat instead of cat
alias cat="bat --paging=never"
alias pcat="bat -pp"
alias ncat="bat -pp --color=never"
alias cat="${bat_exec} --paging=never"
alias pcat="${bat_exec} -pp"
alias ncat="${bat_exec} -pp --color=never"
# Bat as man pager
export MANPAGER="zsh -c 'col -bx | bat -l man --paging=always --style=plain'"
if [[ "${bat_exec}" = (bat|*/bat) ]]; then
export MANPAGER="zsh -c 'col -bx | ${bat_exec} -l man --paging=always --style=plain'"
export MANROFFOPT="-c"
fi
fi
unset bat_exec
# 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"
fi
alias la="ls -a"
alias l="ls -l"
alias ll="ls -al"
fi
# Delta configuration
if cmd_exists delta; then
@ -196,7 +254,7 @@ function overwrite-mode {
zle -N overwrite-mode
# Fancy prompt (starship)
eval "$(starship init zsh)"
cmd_exists starship && eval "$(starship init zsh)"
# Change cursor shape for different vi modes.
function __zsh_vim_key_prompt_handler {
SPACESHIP_CHAR_SYMBOL=""
@ -247,23 +305,27 @@ if cmd_exists pyenv; then
export PYENV_ROOT="${HOME}/.pyenv"
[[ -d "${PYENV_ROOT/bin}" ]] && export PATH="${PYENV_ROOT}/bin:${PATH}"
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
# Bookmarks
[[ -v BM_CWD_LS ]] || BM_CWD_LS=1
if cmd_exists emacs; then
[[ -v BM_CWD_LS ]] || BM_CWD_LS=true
[[ -v BM_MODE ]] || BM_MODE=daemon
[[ -v BM_AUTO_RELOAD ]] || BM_AUTO_RELOAD=1
[[ -v BM_AUTO_RELOAD ]] || BM_AUTO_RELOAD=true
source "${ZSH_CONFIG_DIR}/emacs-bookmark.zsh"
fi
# Platform specific stuff
[ -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
load_plugin fzf-tab
# Disable sort when completing `git checkout`
@ -289,6 +351,12 @@ bindkey '^ ' autosuggest-accept
# Load user init file
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
# More completions
@ -321,12 +389,15 @@ if cmd_exists fortune && cmd_exists cowsay; then
fortune | cowsay -felephant-in-snake -n
fi
# [[ -v EAT_SHELL_INTEGRATION_DIR ]] && source "${EAT_SHELL_INTEGRATION_DIR}/zsh"
# Clean up internal functions
unfunction load_plugin
unfunction cmd_exists
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 {
printf 'Zsh initialization took: %05fms\n' "$(( ZSH_INIT_TIME * 1000 ))"
}

View File

@ -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