refactor code and add fallback prompt to zsh

This commit is contained in:
2026-02-13 10:19:45 +01:00
parent 1cdc70eb70
commit 25a4a6076c
19 changed files with 150 additions and 189 deletions

View File

@@ -1,10 +1,10 @@
# Set PATH environment variable
typeset -U path PATH
path=("${HOME}/.local/bin" "/usr/local/sbin" "/usr/local/bin" "/usr/sbin" "/sbin" "${path[@]}")
path=("${HOME}/.local/bin" /usr/local/sbin /usr/local/bin /usr/sbin /sbin "${path[@]}")
export PATH
# Configure shell history behavior
HISTFILE="${HOME}/.zsh_history"
HISTFILE=${HOME}/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt appendhistory

View File

@@ -1,13 +0,0 @@
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-${HOME}/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-${HOME}/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# plugins
source "${HOME}/.zsh/plugins/powerlevel10k/powerlevel10k.zsh-theme"
source "${HOME}/.zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh"
# To customize prompt, run `p10k configure` or edit ~/.zsh/prompt/p10k.zsh.
[[ -f "${HOME}/.zsh/prompt/p10k.zsh" ]] && source "${HOME}/.zsh/prompt/p10k.zsh"

View File

@@ -14,19 +14,23 @@ bindkey '^U' backward-kill-line
# Change cursor shape for different vi modes
zle-keymap-select() {
if [[ ${KEYMAP} == vicmd ]] ||
[[ $1 = "block" ]]; then
[[ $1 == block ]]; then
echo -ne '\e[4 q'
psvar[1]="(cmd) "
elif [[ ${KEYMAP} == main ]] ||
[[ ${KEYMAP} == viins ]] ||
[[ ${KEYMAP} == "" ]] ||
[[ $1 == "beam" ]]; then
[[ -z ${KEYMAP} ]] ||
[[ $1 == beam ]]; then
echo -ne '\e[6 q'
psvar[1]="(ins) "
fi
zle reset-prompt
}
zle -N zle-keymap-select
zle-line-init() {
zle -K viins # Initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere)
echo -ne '\e[6 q'
psvar[1]="(ins) "
}
zle -N zle-line-init
echo -ne '\e[6 q' # Use beam shape cursor on startup

View File

@@ -0,0 +1,19 @@
if [[ -z ${TMUX} ]]; then
export REAL_TERM=${TERM}
fi
if [[ ${REAL_TERM} != "linux" ]]; then
# To customize prompt, run `p10k configure` or edit ~/.zsh/prompt/p10k.zsh.
. "${HOME}/.zsh/plugins/powerlevel10k/powerlevel10k.zsh-theme"
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-${HOME}/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
. "${XDG_CACHE_HOME:-${HOME}/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
[[ -f ${HOME}/.zsh/prompt/p10k.zsh ]] && . "${HOME}/.zsh/prompt/p10k.zsh"
else
. "${HOME}/.zsh/prompt/fallback.zsh"
fi

View File

@@ -1,14 +1,17 @@
## Plugins configuration
# Automatic suggestions
. "${HOME}/.zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh"
# Completions
fpath=("${HOME}/.zsh/plugins/zsh-completions/src" "${fpath[@]}")
autoload -U compinit promptinit
compinit
promptinit
[[ -f "/etc/gentoo-release" ]] && prompt gentoo
[[ -f /etc/gentoo-release ]] && prompt gentoo
# Enable cache for completions
zstyle ":completion::complete:*" use-cache 1
# Syntax highlighting in zsh prompt
source "${HOME}/.zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
. "${HOME}/.zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"

View File

@@ -1,3 +1,2 @@
# emacs specific stuff
[ -n "${EAT_SHELL_INTEGRATION_DIR}" ] && \
source "${EAT_SHELL_INTEGRATION_DIR}/zsh"
[[ ${EAT_SHELL_INTEGRATION_DIR} ]] && . "${EAT_SHELL_INTEGRATION_DIR}/zsh"

View File

@@ -1,5 +1,5 @@
# Set environment variables
if command -v nvim &> /dev/null; then
if command -v nvim >/dev/null 2>&1; then
export EDITOR="nvim"
else
export EDITOR="vim"
@@ -21,6 +21,6 @@ export GPGKEY="4A45503BBE575E3D4DAF28E27264AFFDC98D52BB"
# gpg-agent
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket 2>/dev/null)"
if [[ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]]; then
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket 2>/dev/null)
fi

View File

@@ -18,5 +18,5 @@ pty() {
}
ptyless() {
pty $@ | less
pty "$@" | less
}

View File

@@ -1,12 +1,12 @@
# HSTR configuration - add this to ~/.zshrc
if type "hstr" >/dev/null; then
if command -v hstr >/dev/null 2>&1; then
alias hh=hstr # hh to be alias for hstr
setopt histignorespace # skip cmds w/ leading space from history
export HSTR_CONFIG=hicolor # get more colors
hstr_no_tiocsti() {
zle -I
{ HSTR_OUT="$( { </dev/tty hstr ${BUFFER}; } 2>&1 1>&3 3>&- )"; } 3>&1;
BUFFER="${HSTR_OUT}"
BUFFER=${HSTR_OUT}
CURSOR=${#BUFFER}
zle redisplay
}
@@ -18,42 +18,22 @@ else
fi
# better ls
if command -v "eza" >/dev/null 2>&1; then
if command -v eza >/dev/null 2>&1; then
alias ll="eza -bghHlS"
else
alias ll="exa -bghHlS"
fi
# bat (debian)
if command -v "batcat" >/dev/null 2>&1; then
alias bat="batcat"
if command -v batcat >/dev/null 2>&1; then
alias bat=batcat
fi
# lf
lfwrapper() {
command lf "$@"
# cleanup
awk '$1 == "archivemount" { print $2 }' /etc/mtab | while read -r mntdir; do
sanitized_input="$(printf "${mntdir}")" # /etc/mtab uses octal representation of spaces (possible other symbols too), printf would convert octal representation, so that it can be used in the umount & rmdir commands.
umount "${sanitized_input}"
rmdir "${sanitized_input}"
done
}
lfcd() {
dir="$(lfwrapper -print-last-dir "$@")"
while ! cd "${dir}" 2>/dev/null; do
dir="$(dirname -- "${dir}")"
done
}
alias lf=lfcd
# ranger
ranger_cd() {
temp_file="$(mktemp -t "ranger_cd.XXXXXXXXXX")"
temp_file=$(mktemp -t "ranger_cd.XXXXXXXXXX")
ranger --choosedir="${temp_file}" -- "${@:-${PWD}}"
if chosen_dir="$(cat -- "${temp_file}")" && [ -n "${chosen_dir}" ] && [ "${chosen_dir}" != "${PWD}" ]; then
if chosen_dir=$(cat -- "${temp_file}") && [ -n ${chosen_dir} ] && [ ${chosen_dir} != "${PWD}" ]; then
cd -- "${chosen_dir}"
fi
rm -f -- "${temp_file}"
@@ -61,31 +41,31 @@ ranger_cd() {
alias ranger=ranger_cd
# mc
if [ -f "/usr/libexec/mc/mc.sh" ]; then
source "/usr/libexec/mc/mc.sh"
if [[ -f /usr/libexec/mc/mc.sh ]]; then
. /usr/libexec/mc/mc.sh
fi
# nix package manager
if [ -e "${HOME}/.nix-profile/etc/profile.d/nix.sh" ]; then
source "${HOME}/.nix-profile/etc/profile.d/nix.sh"
fi # added by Nix installer
if [[ -e "${HOME}/.nix-profile/etc/profile.d/nix.sh" ]]; then
. "${HOME}/.nix-profile/etc/profile.d/nix.sh"
fi
# nix shell
if command -v nix-your-shell >/dev/null 2>&1; then
nix-your-shell zsh | source /dev/stdin
nix-your-shell zsh | . /dev/stdin
fi
# node.js
export NVM_DIR="${HOME}/.nvm"
[ -s "${NVM_DIR}/nvm.sh" ] && source "${NVM_DIR}/nvm.sh" # This loads nvm
[ -s "${NVM_DIR}/bash_completion" ] && source "${NVM_DIR}/bash_completion" # This loads nvm bash_completion
[[ -s ${NVM_DIR}/nvm.sh ]] && . "${NVM_DIR}/nvm.sh" # This loads nvm
[[ -s ${NVM_DIR}/bash_completion ]] && . "${NVM_DIR}/bash_completion" # This loads nvm bash_completion
# rvm
[ -s "${HOME}/.rvm/scripts/rvm" ] && source "${HOME}/.rvm/scripts/rvm"
[[ -s ${HOME}/.rvm/scripts/rvm ]] && . "${HOME}/.rvm/scripts/rvm"
# pyenv
export PYENV_ROOT="${HOME}/.pyenv"
if [[ -d "${PYENV_ROOT}/bin" ]]; then
export PYENV_ROOT=${HOME}/.pyenv
if [[ -d ${PYENV_ROOT}/bin ]]; then
path=("${PYENV_ROOT}/bin" "${path[@]}")
export PATH
eval "$(pyenv init - zsh)"

View File

@@ -1,4 +1,4 @@
alias ncmpcpp="ncmpcpp -b ${HOME}/.config/ncmpcpp/bindings"
alias ncmpcpp="ncmpcpp -b ~/.config/ncmpcpp/bindings"
alias tb="nc termbin.com 9999"
alias mux="tmuxinator"
alias tm="tmuxinator start misc"

View File

@@ -1,5 +1,5 @@
take() {
local -r directory="$1"
local -r directory=$1
mkdir -p "${directory}"
cd "${directory}"
}