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

@ -19,8 +19,8 @@ zplug "junegunn/fzf", use:"shell/*.zsh"
if ! zplug check --verbose; then
printf "Install? [y/N]: "
if read -q; then
echo; zplug install
echo
zplug install
fi
fi
zplug load

61
zshrc
View File

@ -15,11 +15,11 @@ autoload -Uz add-zsh-hook
LAST_RETURN_VALUE=0
# Characters
if [[ -n $(echo '\u2603' 2>/dev/null) ]] then
if [[ -n $(echo '\u2603' 2>/dev/null) ]]; then
MULTIBYTE_SUPPORTED="\u2603"
fi
if [[ -n $MULTIBYTE_SUPPORTED ]] then
if [[ -n $MULTIBYTE_SUPPORTED ]]; then
UNSTAGED_CHARACTER="\ue168"
CHANGES_CHARACTER="\ue16b"
UNTRACKED_CHARACTER="\ue16c"
@ -55,23 +55,22 @@ else
SEGMENT_SEPARATOR_BACKWARD=""
fi
#---------------------------------- Helpers -----------------------------------
# Search file up in directory tree. Either print path to found file or nothing
find_up () {
find_up() {
path=$(pwd)
while [[ "$path" != "" ]]; do
if [[ -e "$path/$1" ]]; then
echo "$path/$1"
return;
return
fi
path=${path%/*}
done
}
command-exists () {
return $(command -v $1 >/dev/null);
command-exists() {
return $(command -v $1 >/dev/null)
}
NEWLINE=$'\n'
ZDOTDIR=${ZDOTDIR:-$HOME/.zsh}
@ -86,14 +85,14 @@ if command-exists exa; then
else
LSOPTS="-lAvF --color=auto" # long mode, show all, natural sort, type squiggles, friendly sizes
alias ls="ls $LSOPTS"
fi;
fi
#---------------------------------- Tab completion ----------------------------
# Force a reload of completion system if nothing matched; this fixes installing
# a program and then trying to tab-complete its name
_force_rehash() {
(( CURRENT == 1 )) && rehash
((CURRENT == 1)) && rehash
return 1 # Because we didn't really complete anything
}
@ -245,7 +244,7 @@ prompt_root() {
# Different username
prompt_user() {
local user=$USER
if command-exists whoami && [[ -z $user ]] then
if command-exists whoami && [[ -z $user ]]; then
user=$(whoami)
fi
if [[ "$user" != "$DEFAULT_USER" && $UID -ne 0 ]]; then
@ -267,7 +266,6 @@ prompt_makefile() {
fi
}
# Status:
# - was there an error
# - are there background jobs?
@ -364,12 +362,12 @@ function +vi-git-additional() {
local ahead behind
local -a branchstatus
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 )) && branchstatus+=( " $BEHIND_CHARACTER${behind}" )
(($behind)) && branchstatus+=(" $BEHIND_CHARACTER${behind}")
hook_com[misc]="${(j::)branchstatus}"
if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' && \
-n $(git status --porcelain | grep -E '^\?\?' 2> /dev/null | tail -n1) ]]; then
if [[ $(git rev-parse --is-inside-work-tree 2>/dev/null) == 'true' &&
-n $(git status --porcelain | grep -E '^\?\?' 2>/dev/null | tail -n1) ]]; then
hook_com[unstaged]+=" $UNTRACKED_CHARACTER"
fi
}
@ -393,7 +391,6 @@ function title {
print -n "\ek$prefix$1\e\\"
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
@ -518,15 +515,15 @@ alias bd=". bd -si"
#---------------------------------- VIM pager --------------------------------
vim_pager() {
local source_file;
local source_file
if [ ! -t 1 ]; then
echo "Cannot use vim pager with non-terminal output" 1>&2
return 1
fi
if [ $# -gt 0 ]; then
source_file="$@";
source_file="$@"
elif [ ! -t 0 ]; then
source_file="-";
source_file="-"
else
echo "Input stream or file name missing" 1>&2
return 2
@ -543,20 +540,20 @@ maven_read_project() {
location=$(find_up pom.xml)
if [[ ! -r "$location" || -z $commands[xmllint] ]]; then
MAVEN_PROJECT=""
return 1;
return 1
fi
# executing xmllint takes some time, so this does it in single execution
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()='parent']/*[local-name()='version']/text()\n" | \
xmllint --shell $location 2>/dev/null | \
sed '/^\/ >/d' | \
"cat /*[local-name()='project']/*[local-name()='parent']/*[local-name()='version']/text()\n" |
xmllint --shell $location 2>/dev/null |
sed '/^\/ >/d' |
sed '/^ -------/d'))
if [[ "${#parts}" > 1 ]]; then
MAVEN_PROJECT="${parts[1]}@${parts[2]}"
else
MAVEN_PROJECT="pom!"
fi;
fi
}
add-zsh-hook chpwd maven_read_project
@ -569,7 +566,7 @@ package_json_read_project() {
location=$(find_up package.json)
if [[ ! -r "$location" || -z $commands[jq] ]]; then
PACKAGE_JSON_PROJECT=""
return 1;
return 1
fi
PACKAGE_JSON_PROJECT=$(jq -r '.name + "@" + .version' $location)
}
@ -593,7 +590,7 @@ unsetopt auto_remove_slash # (dont) remove last slash when next character is del
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
WORDCHARS=${WORDCHARS//[&.;\/]}
WORDCHARS=${WORDCHARS//[&.;\/]/}
# Report time if command takes too long
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")
# 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"
done
# load zsh extended move
autoload -Uz zmv
@ -617,7 +615,7 @@ fi
# at last initialize completion
autoload -Uz compinit
if [[ -n ${ZDOTDIR}/.zcompdump(#qN.mh+24) ]]; then
if [[ -n "${ZDOTDIR}/.zcompdump(#qN.mh+24)" ]]; then
compinit
else
compinit -C
@ -634,19 +632,19 @@ precmd_functions=(store_last_return_value $precmd_functions)
# If kubectl is present, load completions from it.
# This must be done after compinit was called
if [[ $commands[kubectl] ]]; then
source <(kubectl completion zsh);
source <(kubectl completion zsh)
fi
# If k3s is present, load completions from it.
# This must be done after compinit was called
if [[ $commands[k3s] ]]; then
source <(k3s completion zsh);
source <(k3s completion zsh)
fi
# If minikube is present, load completions from it.
# This must be done after compinit was called
if [[ $commands[minikube] ]]; then
source <(minikube completion zsh);
source <(minikube completion zsh)
fi
zmodload zsh/complist
@ -671,4 +669,3 @@ function br {
return "$code"
fi
}