1
0
Fork 0
mirror of https://github.com/zdharma-continuum/zinit-configs.git synced 2025-01-31 04:08:16 +01:00
zinit-configs/psprint/functions/pslist
2019-06-27 12:47:09 +02:00

46 lines
1.6 KiB
Bash

# DESC: Lists ~/functions/* with their embedded descriptions
setopt localoptions extendedglob
local -a pfxs lines desc files
pfxs=( ps t1 f1 g1 n1 x1 ) # grouped commands
pfxs+=( "*~$HOME/functions/(${(j:|:)pfxs}|lps)" ) # ungrouped commands
pfxs+=( lps ) # local, uncommited commands
integer pass longest=0 longest2=0
local p file header="# DESC: "
for (( pass = 1; pass <= 2; ++ pass )); do
for p in "${pfxs[@]}"; do
files=( $HOME/functions/${~p}*(N) )
if (( pass == 2 )); then
if (( ${#files[@]} )); then
if [[ "$p" = "lps" ]]; then
print -r -- ${(l:(longest+longest2)/2-4::-:):-} LOCAL ${(l:longest+longest2-(longest+longest2)/2-3::-:):-}
else
print -r -- ${(l:longest+longest2::-:):-}
fi
fi
fi
for file in "${files[@]}"; do
lines=( ${(f)"$(<$file)"} )
desc=( "${(M)lines[@]:#${header}*}" )
desc[1]="${desc[1]#$header}"
file="${file:t}"
[[ "$file" = (LICENSE|README.md) ]] && continue
if (( pass == 1 )); then
(( longest < ${#file} + 3 )) && longest=$(( ${#file} + 3 ))
(( longest2 < ${#desc[1]} )) && longest2=$(( ${#desc[1]} ))
else
echo "${file}${(l:longest-${#file}:: :):- }${desc[1]}"
fi
done
done
if (( pass == 2 )); then
print -r -- ${(l:longest+longest2::-:):-}
fi
done
# vim:ft=zsh:et