Reformat using shfmt

This commit is contained in:
Paweł Płazieński 2024-02-27 20:37:29 +01:00
parent 09324bb670
commit e1ba38a16d
2 changed files with 253 additions and 256 deletions

View File

@ -3,7 +3,7 @@
export ZPLUG_ROOT=${ZPLUG_ROOT:-/usr/share/zplug} export ZPLUG_ROOT=${ZPLUG_ROOT:-/usr/share/zplug}
if [[ ! -f "${ZPLUG_ROOT}/init.zsh" ]]; then if [[ ! -f "${ZPLUG_ROOT}/init.zsh" ]]; then
return return
fi fi
source ${ZPLUG_ROOT}/init.zsh source ${ZPLUG_ROOT}/init.zsh
@ -17,10 +17,10 @@ zplug "zsh-users/zsh-completions"
zplug "junegunn/fzf", use:"shell/*.zsh" zplug "junegunn/fzf", use:"shell/*.zsh"
if ! zplug check --verbose; then if ! zplug check --verbose; then
printf "Install? [y/N]: " printf "Install? [y/N]: "
if read -q; then if read -q; then
echo; zplug install echo
fi zplug install
fi
fi fi
zplug load zplug load

497
zshrc
View File

@ -15,63 +15,62 @@ autoload -Uz add-zsh-hook
LAST_RETURN_VALUE=0 LAST_RETURN_VALUE=0
# Characters # Characters
if [[ -n $(echo '\u2603' 2>/dev/null) ]] then if [[ -n $(echo '\u2603' 2>/dev/null) ]]; then
MULTIBYTE_SUPPORTED="\u2603" MULTIBYTE_SUPPORTED="\u2603"
fi fi
if [[ -n $MULTIBYTE_SUPPORTED ]] then if [[ -n $MULTIBYTE_SUPPORTED ]]; then
UNSTAGED_CHARACTER="\ue168" UNSTAGED_CHARACTER="\ue168"
CHANGES_CHARACTER="\ue16b" CHANGES_CHARACTER="\ue16b"
UNTRACKED_CHARACTER="\ue16c" UNTRACKED_CHARACTER="\ue16c"
BRANCH_CHARACTER="\ue822" BRANCH_CHARACTER="\ue822"
DETACHED_CHARACTER="\ue899" DETACHED_CHARACTER="\ue899"
REVISION_CHARACTER="\ue821" REVISION_CHARACTER="\ue821"
FAILED_CHARACTER="\ue125" FAILED_CHARACTER="\ue125"
SUCCESS_CHARACTER="\ue124" SUCCESS_CHARACTER="\ue124"
SUPERUSER_CHARACTER="\ue22b" SUPERUSER_CHARACTER="\ue22b"
JOBS_CHARACTER="\ue12a" JOBS_CHARACTER="\ue12a"
NO_JOBS_CHARACTER="\u2022" NO_JOBS_CHARACTER="\u2022"
AHEAD_CHARACTER="\ue174 " AHEAD_CHARACTER="\ue174 "
BEHIND_CHARACTER="\ue175 " BEHIND_CHARACTER="\ue175 "
ACTIONS_CHARACTER="\ue831" ACTIONS_CHARACTER="\ue831"
SEGMENT_SEPARATOR_FORWARD="\ue0b0" SEGMENT_SEPARATOR_FORWARD="\ue0b0"
SEGMENT_SEPARATOR_BACKWARD="\ue0b2" SEGMENT_SEPARATOR_BACKWARD="\ue0b2"
else else
UNSTAGED_CHARACTER="!" UNSTAGED_CHARACTER="!"
CHANGES_CHARACTER="*" CHANGES_CHARACTER="*"
UNTRACKED_CHARACTER="?" UNTRACKED_CHARACTER="?"
BRANCH_CHARACTER="~" BRANCH_CHARACTER="~"
DETACHED_CHARACTER="%" DETACHED_CHARACTER="%"
REVISION_CHARACTER="r" REVISION_CHARACTER="r"
FAILED_CHARACTER="X" FAILED_CHARACTER="X"
SUCCESS_CHARACTER="V" SUCCESS_CHARACTER="V"
SUPERUSER_CHARACTER="#" SUPERUSER_CHARACTER="#"
JOBS_CHARACTER="O" JOBS_CHARACTER="O"
NO_JOBS_CHARACTER="." NO_JOBS_CHARACTER="."
AHEAD_CHARACTER="+" AHEAD_CHARACTER="+"
BEHIND_CHARACTER="-" BEHIND_CHARACTER="-"
ACTIONS_CHARACTER="!" ACTIONS_CHARACTER="!"
SEGMENT_SEPARATOR_FORWARD="" SEGMENT_SEPARATOR_FORWARD=""
SEGMENT_SEPARATOR_BACKWARD="" SEGMENT_SEPARATOR_BACKWARD=""
fi fi
#---------------------------------- Helpers ----------------------------------- #---------------------------------- Helpers -----------------------------------
# Search file up in directory tree. Either print path to found file or nothing # Search file up in directory tree. Either print path to found file or nothing
find_up () { find_up() {
path=$(pwd) path=$(pwd)
while [[ "$path" != "" ]]; do while [[ "$path" != "" ]]; do
if [[ -e "$path/$1" ]]; then if [[ -e "$path/$1" ]]; then
echo "$path/$1" echo "$path/$1"
return; return
fi fi
path=${path%/*} path=${path%/*}
done done
} }
command-exists () { command-exists() {
return $(command -v $1 >/dev/null); return $(command -v $1 >/dev/null)
} }
NEWLINE=$'\n' NEWLINE=$'\n'
ZDOTDIR=${ZDOTDIR:-$HOME/.zsh} ZDOTDIR=${ZDOTDIR:-$HOME/.zsh}
@ -79,22 +78,22 @@ ZDOTDIR=${ZDOTDIR:-$HOME/.zsh}
#---------------------------------- Listings ---------------------------------- #---------------------------------- Listings ----------------------------------
if command-exists dircolors; then if command-exists dircolors; then
eval "$(dircolors -b)" eval "$(dircolors -b)"
fi fi
if command-exists exa; then if command-exists exa; then
alias ls='exa --git --long --all --time-style long-iso' alias ls='exa --git --long --all --time-style long-iso'
else else
LSOPTS="-lAvF --color=auto" # long mode, show all, natural sort, type squiggles, friendly sizes LSOPTS="-lAvF --color=auto" # long mode, show all, natural sort, type squiggles, friendly sizes
alias ls="ls $LSOPTS" alias ls="ls $LSOPTS"
fi; fi
#---------------------------------- Tab completion ---------------------------- #---------------------------------- Tab completion ----------------------------
# Force a reload of completion system if nothing matched; this fixes installing # Force a reload of completion system if nothing matched; this fixes installing
# a program and then trying to tab-complete its name # a program and then trying to tab-complete its name
_force_rehash() { _force_rehash() {
(( CURRENT == 1 )) && rehash ((CURRENT == 1)) && rehash
return 1 # Because we didn't really complete anything return 1 # Because we didn't really complete anything
} }
# Always use menu completion, and make the colors pretty! # Always use menu completion, and make the colors pretty!
@ -171,21 +170,21 @@ autoload predict-off
zle -N predict-on zle -N predict-on
zle -N predict-off zle -N predict-off
bindkey "^Z" predict-on # C-z bindkey "^Z" predict-on # C-z
bindkey "^X^Z" predict-off # C-x C-z bindkey "^X^Z" predict-off # C-x C-z
#---------------------------------- History ----------------------------------- #---------------------------------- History -----------------------------------
setopt append_history # Allow multiple terminal sessions to all append to one zsh command history setopt append_history # Allow multiple terminal sessions to all append to one zsh command history
setopt extended_history # save timestamp of command and duration setopt extended_history # save timestamp of command and duration
setopt inc_append_history # Add comamnds as they are typed, don't wait until shell exit setopt inc_append_history # Add comamnds as they are typed, don't wait until shell exit
setopt hist_expire_dups_first # when trimming history, lose oldest duplicates first setopt hist_expire_dups_first # when trimming history, lose oldest duplicates first
setopt hist_ignore_dups # Do not write events to history that are duplicates of previous events setopt hist_ignore_dups # Do not write events to history that are duplicates of previous events
setopt hist_ignore_space # remove command line from history list when first character on the line is a space setopt hist_ignore_space # remove command line from history list when first character on the line is a space
setopt hist_find_no_dups # When searching history don't display results already cycled through twice setopt hist_find_no_dups # When searching history don't display results already cycled through twice
setopt hist_reduce_blanks # Remove extra blanks from each command line being added to history setopt hist_reduce_blanks # Remove extra blanks from each command line being added to history
setopt hist_verify # don't execute, just expand history setopt hist_verify # don't execute, just expand history
setopt share_history # imports new commands and appends typed commands to history setopt share_history # imports new commands and appends typed commands to history
setopt hist_no_store # remove the history (fc -l) command from the history when invoked. setopt hist_no_store # remove the history (fc -l) command from the history when invoked.
export HISTFILE=~/.zsh_history export HISTFILE=~/.zsh_history
export HISTSIZE=1000000 export HISTSIZE=1000000
@ -198,38 +197,38 @@ export SAVEHIST=1000000
CURRENT_BG='NONE' CURRENT_BG='NONE'
prompt_segment() { prompt_segment() {
local direction newbg newfg text local direction newbg newfg text
direction="$1" direction="$1"
newbg="$2" newbg="$2"
newfg="$3" newfg="$3"
text="$4" text="$4"
if [[ -z $text ]]; then return; fi if [[ -z $text ]]; then return; fi
if [[ $newbg != $CURRENT_BG ]]; then if [[ $newbg != $CURRENT_BG ]]; then
if [[ "$direction" == 'forward' ]]; then if [[ "$direction" == 'forward' ]]; then
if [[ $CURRENT_BG != 'NONE' ]]; then if [[ $CURRENT_BG != 'NONE' ]]; then
print -n "%{%K{$newbg}%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR_FORWARD%{%F{$newfg}%}" print -n "%{%K{$newbg}%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR_FORWARD%{%F{$newfg}%}"
else else
print -n "%{%K{$newbg}%F{$newfg}%}" print -n "%{%K{$newbg}%F{$newfg}%}"
fi
else
print -n "%{%F{$newbg}%}$SEGMENT_SEPARATOR_BACKWARD%{%F{$newfg}%K{$newbg}%}"
fi fi
else
print -n "%{%F{$newbg}%}$SEGMENT_SEPARATOR_BACKWARD%{%F{$newfg}%K{$newbg}%}"
fi fi
fi print -n " $text "
print -n " $text " CURRENT_BG=$newbg
CURRENT_BG=$newbg
} }
# End the prompt, closing any open segments # End the prompt, closing any open segments
prompt_end() { prompt_end() {
if [[ -n $CURRENT_BG ]]; then if [[ -n $CURRENT_BG ]]; then
print -n "%{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR_FORWARD" print -n "%{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR_FORWARD"
fi fi
CURRENT_BG='' CURRENT_BG=''
} }
prompt_clear() { prompt_clear() {
print -n "%{%k%f%}" print -n "%{%k%f%}"
CURRENT_BG='' CURRENT_BG=''
} }
### Prompt components ### Prompt components
@ -237,99 +236,98 @@ prompt_clear() {
# Root privileges # Root privileges
prompt_root() { prompt_root() {
if [[ $UID -eq 0 ]]; then if [[ $UID -eq 0 ]]; then
print -n $SUPERUSER_CHARACTER print -n $SUPERUSER_CHARACTER
fi fi
} }
# Different username # Different username
prompt_user() { prompt_user() {
local user=$USER local user=$USER
if command-exists whoami && [[ -z $user ]] then if command-exists whoami && [[ -z $user ]]; then
user=$(whoami) user=$(whoami)
fi fi
if [[ "$user" != "$DEFAULT_USER" && $UID -ne 0 ]]; then if [[ "$user" != "$DEFAULT_USER" && $UID -ne 0 ]]; then
print -n $user print -n $user
fi fi
} }
# Different host # Different host
prompt_host() { prompt_host() {
if [[ -n "$SSH_CONNECTION" ]]; then if [[ -n "$SSH_CONNECTION" ]]; then
print -n "%m" print -n "%m"
fi fi
} }
# Makefile exists # Makefile exists
prompt_makefile() { prompt_makefile() {
if [[ -f Makefile ]]; then if [[ -f Makefile ]]; then
print -n "make" print -n "make"
fi fi
} }
# Status: # Status:
# - was there an error # - was there an error
# - are there background jobs? # - are there background jobs?
prompt_status() { prompt_status() {
local symbols local symbols
symbols=() symbols=()
if [[ $LAST_RETURN_VALUE -ne 0 ]]; then if [[ $LAST_RETURN_VALUE -ne 0 ]]; then
symbols+="%{%F{red}%}$FAILED_CHARACTER%{%f%}" symbols+="%{%F{red}%}$FAILED_CHARACTER%{%f%}"
else else
symbols+="%{%F{green}%}$SUCCESS_CHARACTER%{%f%}" symbols+="%{%F{green}%}$SUCCESS_CHARACTER%{%f%}"
fi fi
if [[ $(jobs -l) ]]; then if [[ $(jobs -l) ]]; then
symbols+="%{%F{cyan}%}$JOBS_CHARACTER%{%f%}" symbols+="%{%F{cyan}%}$JOBS_CHARACTER%{%f%}"
else else
symbols+="%{%F{white}%}$NO_JOBS_CHARACTER%{%f%}" symbols+="%{%F{white}%}$NO_JOBS_CHARACTER%{%f%}"
fi fi
echo "$symbols" echo "$symbols"
} }
## Main prompt ## Main prompt
prompt_forward() { prompt_forward() {
CURRENT_BG='NONE' CURRENT_BG='NONE'
prompt_segment forward black default "$(prompt_status)" prompt_segment forward black default "$(prompt_status)"
prompt_segment forward red yellow "$(prompt_root)" prompt_segment forward red yellow "$(prompt_root)"
prompt_segment forward magenta black "$(prompt_user)" prompt_segment forward magenta black "$(prompt_user)"
prompt_segment forward cyan black "$(prompt_host)" prompt_segment forward cyan black "$(prompt_host)"
prompt_segment forward blue black '%~' # prompt directory prompt_segment forward blue black '%~' # prompt directory
prompt_end prompt_end
prompt_clear prompt_clear
} }
## Reverse prompt ## Reverse prompt
prompt_backward() { prompt_backward() {
CURRENT_BG='NONE' CURRENT_BG='NONE'
prompt_segment backward magenta black "$MAVEN_PROJECT" # prompt maven project prompt_segment backward magenta black "$MAVEN_PROJECT" # prompt maven project
prompt_segment backward cyan black "$PACKAGE_JSON_PROJECT" # prompt package.json project prompt_segment backward cyan black "$PACKAGE_JSON_PROJECT" # prompt package.json project
prompt_segment backward cyan black "$(prompt_makefile)" prompt_segment backward cyan black "$(prompt_makefile)"
prompt_segment backward yellow black "$vcs_info_msg_0_" # prompt vcs prompt_segment backward yellow black "$vcs_info_msg_0_" # prompt vcs
prompt_segment backward green black "%T" # prompt time prompt_segment backward green black "%T" # prompt time
prompt_clear prompt_clear
} }
prompt2_forward() { prompt2_forward() {
CURRENT_BG='NONE' CURRENT_BG='NONE'
prompt_segment forward black default "$(prompt_status)" prompt_segment forward black default "$(prompt_status)"
prompt_segment forward red yellow "$(prompt_root)" prompt_segment forward red yellow "$(prompt_root)"
prompt_segment forward magenta black "$(prompt_user)" prompt_segment forward magenta black "$(prompt_user)"
prompt_segment forward cyan black "$(prompt_host)" prompt_segment forward cyan black "$(prompt_host)"
prompt_segment forward blue black '%~' # prompt directory prompt_segment forward blue black '%~' # prompt directory
prompt_segment forward red black '%_' # unmatched quote prompt_segment forward red black '%_' # unmatched quote
prompt_end prompt_end
prompt_clear prompt_clear
} }
prompt_precmd() { prompt_precmd() {
vcs_info vcs_info
PROMPT="%{%f%b%k%}$(prompt_forward) " PROMPT="%{%f%b%k%}$(prompt_forward) "
PS="$PROMPT" PS="$PROMPT"
PS2="%{%f%b%k%}$(prompt2_forward) " PS2="%{%f%b%k%}$(prompt2_forward) "
RPROMPT="%{%f%b%k%}$(prompt_backward)" RPROMPT="%{%f%b%k%}$(prompt_backward)"
PRS="$RPROMPT" PRS="$RPROMPT"
SPROMPT="Correct %{%F{red}%}%R%{%f%} to %{%F{green}%}%r%f? [%Uy%ues|%Un%uo|%Ua%ubort|%Ue%udit] " SPROMPT="Correct %{%F{red}%}%R%{%f%} to %{%F{green}%}%r%f? [%Uy%ues|%Un%uo|%Ua%ubort|%Ue%udit] "
} }
ZLE_RPROMPT_INDENT=1 ZLE_RPROMPT_INDENT=1
@ -361,70 +359,69 @@ zstyle ':vcs_info:git*' stagedstr " $CHANGES_CHARACTER"
zstyle ':vcs_info:git*+set-message:*' hooks git-additional zstyle ':vcs_info:git*+set-message:*' hooks git-additional
function +vi-git-additional() { function +vi-git-additional() {
local ahead behind local ahead behind
local -a branchstatus local -a branchstatus
ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l) ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l)
(( $ahead )) && branchstatus+=( " $AHEAD_CHARACTER${ahead}" ) (($ahead)) && branchstatus+=(" $AHEAD_CHARACTER${ahead}")
behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l) behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l)
(( $behind )) && branchstatus+=( " $BEHIND_CHARACTER${behind}" ) (($behind)) && branchstatus+=(" $BEHIND_CHARACTER${behind}")
hook_com[misc]="${(j::)branchstatus}" hook_com[misc]="${(j::)branchstatus}"
if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' && \ if [[ $(git rev-parse --is-inside-work-tree 2>/dev/null) == 'true' &&
-n $(git status --porcelain | grep -E '^\?\?' 2> /dev/null | tail -n1) ]]; then -n $(git status --porcelain | grep -E '^\?\?' 2>/dev/null | tail -n1) ]]; then
hook_com[unstaged]+=" $UNTRACKED_CHARACTER" hook_com[unstaged]+=" $UNTRACKED_CHARACTER"
fi fi
} }
#---------------------------------- Screen ------------------------------------ #---------------------------------- Screen ------------------------------------
function title { function title {
# param: title to use # param: title to use
local prefix='' local prefix=''
# If I'm in a screen, all the windows are probably on the same machine, so # If I'm in a screen, all the windows are probably on the same machine, so
# I don't really need to title every single one with the machine name. # I don't really need to title every single one with the machine name.
# On the other hand, if I'm not logged in as me (but, e.g., root), I'd # On the other hand, if I'm not logged in as me (but, e.g., root), I'd
# certainly like to know that! # certainly like to know that!
if [[ $USER != "$DEFAULT_USER" ]]; then if [[ $USER != "$DEFAULT_USER" ]]; then
prefix="[$USER] " prefix="[$USER] "
fi fi
# Set screen window title # Set screen window title
if [[ $TERM == "screen"* ]]; then if [[ $TERM == "screen"* ]]; then
print -n "\ek$prefix$1\e\\" print -n "\ek$prefix$1\e\\"
fi fi
# Prefix the xterm title with the current machine name, but only if I'm not
# on a local machine. This is tricky, because screen won't reliably know
# whether I'm using SSH right now! So just assume I'm local iff I'm not
# running over SSH *and* not using screen. Local screens are fairly rare.
prefix=$HOST
if [[ $SSH_CONNECTION == '' && $TERM != "screen"* ]]; then
prefix=''
fi
# If we're showing host and not default user prepend it
if [[ $prefix != '' && $USER != "$DEFAULT_USER" ]]; then
prefix="$USER@$prefix"
fi
# Wrap it in brackets
if [[ $prefix != '' ]]; then
prefix="[$prefix] "
fi
# Prefix the xterm title with the current machine name, but only if I'm not # Set xterm window title
# on a local machine. This is tricky, because screen won't reliably know if [[ $TERM == "xterm"* || $TERM == "screen"* ]]; then
# whether I'm using SSH right now! So just assume I'm local iff I'm not print -n "\e]2;$prefix$1\a"
# running over SSH *and* not using screen. Local screens are fairly rare. fi
prefix=$HOST
if [[ $SSH_CONNECTION == '' && $TERM != "screen"* ]]; then
prefix=''
fi
# If we're showing host and not default user prepend it
if [[ $prefix != '' && $USER != "$DEFAULT_USER" ]]; then
prefix="$USER@$prefix"
fi
# Wrap it in brackets
if [[ $prefix != '' ]]; then
prefix="[$prefix] "
fi
# Set xterm window title
if [[ $TERM == "xterm"* || $TERM == "screen"* ]]; then
print -n "\e]2;$prefix$1\a"
fi
} }
function title_precmd { function title_precmd {
# Shorten homedir back to '~' # Shorten homedir back to '~'
local shortpwd=${PWD/$HOME/\~} local shortpwd=${PWD/$HOME/\~}
title "zsh $shortpwd" title "zsh $shortpwd"
} }
function title_preexec { function title_preexec {
title $* title $*
} }
add-zsh-hook preexec title_preexec add-zsh-hook preexec title_preexec
@ -470,21 +467,21 @@ zle -N expand-or-complete-with-indicator
bindkey "^I" expand-or-complete-with-indicator bindkey "^I" expand-or-complete-with-indicator
bindkey "^r" history-incremental-search-backward bindkey "^r" history-incremental-search-backward
bindkey "\e[Z" reverse-menu-complete # shift-tab to reverse menu bindkey "\e[Z" reverse-menu-complete # shift-tab to reverse menu
# Up/down arrow. # Up/down arrow.
# I want shared history for ^R, but I don't want another shell's activity to # I want shared history for ^R, but I don't want another shell's activity to
# mess with up/down. This does that. # mess with up/down. This does that.
down-line-or-local-history() { down-line-or-local-history() {
zle set-local-history 1 zle set-local-history 1
zle down-line-or-history zle down-line-or-history
zle set-local-history 0 zle set-local-history 0
} }
zle -N down-line-or-local-history zle -N down-line-or-local-history
up-line-or-local-history() { up-line-or-local-history() {
zle set-local-history 1 zle set-local-history 1
zle up-line-or-history zle up-line-or-history
zle set-local-history 0 zle set-local-history 0
} }
zle -N up-line-or-local-history zle -N up-line-or-local-history
@ -518,15 +515,15 @@ alias bd=". bd -si"
#---------------------------------- VIM pager -------------------------------- #---------------------------------- VIM pager --------------------------------
vim_pager() { vim_pager() {
local source_file; local source_file
if [ ! -t 1 ]; then if [ ! -t 1 ]; then
echo "Cannot use vim pager with non-terminal output" 1>&2 echo "Cannot use vim pager with non-terminal output" 1>&2
return 1 return 1
fi fi
if [ $# -gt 0 ]; then if [ $# -gt 0 ]; then
source_file="$@"; source_file="$@"
elif [ ! -t 0 ]; then elif [ ! -t 0 ]; then
source_file="-"; source_file="-"
else else
echo "Input stream or file name missing" 1>&2 echo "Input stream or file name missing" 1>&2
return 2 return 2
@ -543,20 +540,20 @@ maven_read_project() {
location=$(find_up pom.xml) location=$(find_up pom.xml)
if [[ ! -r "$location" || -z $commands[xmllint] ]]; then if [[ ! -r "$location" || -z $commands[xmllint] ]]; then
MAVEN_PROJECT="" MAVEN_PROJECT=""
return 1; return 1
fi fi
# executing xmllint takes some time, so this does it in single execution # executing xmllint takes some time, so this does it in single execution
parts=($(echo "cat /*[local-name()='project']/*[local-name()='artifactId']/text()\n" \ parts=($(echo "cat /*[local-name()='project']/*[local-name()='artifactId']/text()\n" \
"cat /*[local-name()='project']/*[local-name()='version']/text()\n" \ "cat /*[local-name()='project']/*[local-name()='version']/text()\n" \
"cat /*[local-name()='project']/*[local-name()='parent']/*[local-name()='version']/text()\n" | \ "cat /*[local-name()='project']/*[local-name()='parent']/*[local-name()='version']/text()\n" |
xmllint --shell $location 2>/dev/null | \ xmllint --shell $location 2>/dev/null |
sed '/^\/ >/d' | \ sed '/^\/ >/d' |
sed '/^ -------/d')) sed '/^ -------/d'))
if [[ "${#parts}" > 1 ]]; then if [[ "${#parts}" > 1 ]]; then
MAVEN_PROJECT="${parts[1]}@${parts[2]}" MAVEN_PROJECT="${parts[1]}@${parts[2]}"
else else
MAVEN_PROJECT="pom!" MAVEN_PROJECT="pom!"
fi; fi
} }
add-zsh-hook chpwd maven_read_project add-zsh-hook chpwd maven_read_project
@ -569,31 +566,31 @@ package_json_read_project() {
location=$(find_up package.json) location=$(find_up package.json)
if [[ ! -r "$location" || -z $commands[jq] ]]; then if [[ ! -r "$location" || -z $commands[jq] ]]; then
PACKAGE_JSON_PROJECT="" PACKAGE_JSON_PROJECT=""
return 1; return 1
fi fi
PACKAGE_JSON_PROJECT=$(jq -r '.name + "@" + .version' $location) PACKAGE_JSON_PROJECT=$(jq -r '.name + "@" + .version' $location)
} }
add-zsh-hook chpwd package_json_read_project add-zsh-hook chpwd package_json_read_project
#---------------------------------- Miscellaneous ---------------------------- #---------------------------------- Miscellaneous ----------------------------
setopt extended_glob setopt extended_glob
setopt correct # try to correct the spelling of commands. setopt correct # try to correct the spelling of commands.
setopt correct_all # try to correct the spelling of all arguments in a line. setopt correct_all # try to correct the spelling of all arguments in a line.
setopt numeric_glob_sort # if numeric filenames are matched by a filename generation pattern, sort the filenames numerically rather than lexicographically. setopt numeric_glob_sort # if numeric filenames are matched by a filename generation pattern, sort the filenames numerically rather than lexicographically.
setopt nomatch # if there is match on file pattern, dont run command (instead of running command with unchanged parameters) setopt nomatch # if there is match on file pattern, dont run command (instead of running command with unchanged parameters)
setopt interactive_comments # allow comments in command line setopt interactive_comments # allow comments in command line
setopt multios # enable multiple input/output redirections that work as expected setopt multios # enable multiple input/output redirections that work as expected
unsetopt beep # (dont) beep on errors unsetopt beep # (dont) beep on errors
unsetopt notify # (dont) report the status of background jobs immediately, rather than waiting until just before printing a prompt. unsetopt notify # (dont) report the status of background jobs immediately, rather than waiting until just before printing a prompt.
unsetopt auto_cd # (dont) enter the directory that was inputed as command unsetopt auto_cd # (dont) enter the directory that was inputed as command
unsetopt auto_remove_slash # (dont) remove last slash when next character is delimiter unsetopt auto_remove_slash # (dont) remove last slash when next character is delimiter
unsetopt csh_junkie_quotes # (dont) complain if a quoted expression runs off the end of a line; prevent quoted expressions from containing un-escaped newlines. unsetopt csh_junkie_quotes # (dont) complain if a quoted expression runs off the end of a line; prevent quoted expressions from containing un-escaped newlines.
# Don't count common path separators as word characters # Don't count common path separators as word characters
WORDCHARS=${WORDCHARS//[&.;\/]} WORDCHARS=${WORDCHARS//[&.;\/]/}
# Report time if command takes too long # Report time if command takes too long
REPORTTIME=5 REPORTTIME=5
@ -601,8 +598,9 @@ REPORTTIME=5
TIMEFMT=$(echo "$fg[green]${SEGMENT_SEPARATOR_BACKWARD}$bg[green]$fg[black] %*Es $fg[yellow]$SEGMENT_SEPARATOR_BACKWARD$bg[yellow]$fg[black] %P $reset_color") TIMEFMT=$(echo "$fg[green]${SEGMENT_SEPARATOR_BACKWARD}$bg[green]$fg[black] %*Es $fg[yellow]$SEGMENT_SEPARATOR_BACKWARD$bg[yellow]$fg[black] %P $reset_color")
# Don't glob with commands that expects glob patterns # Don't glob with commands that expects glob patterns
for command in find wget git; \ for command in find wget git; do
alias $command="noglob $command" alias $command="noglob $command"
done
# load zsh extended move # load zsh extended move
autoload -Uz zmv autoload -Uz zmv
@ -610,17 +608,17 @@ autoload -Uz zmv
#---------------------------------- Machine specific -------------------------- #---------------------------------- Machine specific --------------------------
if [[ -r $HOME/.zlocal ]]; then if [[ -r $HOME/.zlocal ]]; then
source $HOME/.zlocal source $HOME/.zlocal
fi fi
#---------------------------------- Post Setup -------------------------------- #---------------------------------- Post Setup --------------------------------
# at last initialize completion # at last initialize completion
autoload -Uz compinit autoload -Uz compinit
if [[ -n ${ZDOTDIR}/.zcompdump(#qN.mh+24) ]]; then if [[ -n "${ZDOTDIR}/.zcompdump(#qN.mh+24)" ]]; then
compinit compinit
else else
compinit -C compinit -C
fi fi
store_last_return_value() { store_last_return_value() {
@ -634,19 +632,19 @@ precmd_functions=(store_last_return_value $precmd_functions)
# If kubectl is present, load completions from it. # If kubectl is present, load completions from it.
# This must be done after compinit was called # This must be done after compinit was called
if [[ $commands[kubectl] ]]; then if [[ $commands[kubectl] ]]; then
source <(kubectl completion zsh); source <(kubectl completion zsh)
fi fi
# If k3s is present, load completions from it. # If k3s is present, load completions from it.
# This must be done after compinit was called # This must be done after compinit was called
if [[ $commands[k3s] ]]; then if [[ $commands[k3s] ]]; then
source <(k3s completion zsh); source <(k3s completion zsh)
fi fi
# If minikube is present, load completions from it. # If minikube is present, load completions from it.
# This must be done after compinit was called # This must be done after compinit was called
if [[ $commands[minikube] ]]; then if [[ $commands[minikube] ]]; then
source <(minikube completion zsh); source <(minikube completion zsh)
fi fi
zmodload zsh/complist zmodload zsh/complist
@ -654,21 +652,20 @@ zmodload zsh/complist
#---------------------------------- Partials ------------------------------------ #---------------------------------- Partials ------------------------------------
for partial in ${ZDOTDIR}/zsh.d/*.zsh; do for partial in ${ZDOTDIR}/zsh.d/*.zsh; do
source $partial source $partial
done done
#---------------------------------- Broot ------------------------------------ #---------------------------------- Broot ------------------------------------
function br { function br {
local cmd cmd_file code local cmd cmd_file code
cmd_file=$(mktemp) cmd_file=$(mktemp)
if broot --outcmd "$cmd_file" "$@"; then if broot --outcmd "$cmd_file" "$@"; then
cmd=$(<"$cmd_file") cmd=$(<"$cmd_file")
command rm -f "$cmd_file" command rm -f "$cmd_file"
eval "$cmd" eval "$cmd"
else else
code=$? code=$?
command rm -f "$cmd_file" command rm -f "$cmd_file"
return "$code" return "$code"
fi fi
} }