Tips à appliquer pour diractions
Antigen, globalement trop bien foutu!!! :)
- appel de commande avec chaine de caractère et substitution de variable
- functions pour tester si variable est la bonne
- see what he does for private functions
- unfunctions?
- extrait les argument tout au début avec des local
- chainage de commande pour filtrer
- définition de fonction de setup (et éventuel appel à la fin)
- opération sr les chaines avec simples évaluation de var:
${op}
$()
ou sed operation
- documentation en dessous fonction
- local var definie sans fonction
if (( $+functions[pmodload] )); then
{
# pipe block
} >
# A syntax sugar to avoid the `-` when calling antigen commands. With this
# function, you can write `antigen-bundle` as `antigen bundle` and so on.
antigen () {
local cmd="$1"
if [[ -z "$cmd" ]]; then
echo 'Antigen: Please give a command to run.' >&2
return 1
fi
shift
if functions "antigen-$cmd" > /dev/null; then
"antigen-$cmd" "$@"
else
echo "Antigen: Unknown command: $cmd" >&2
fi
}
compdef _antigen antigen
# Setup antigen's autocompletion
_antigen () {
compadd \
bundle \
bundles
# ....
}
# The snapshot content lines are pairs of repo-url and git version hash, in
# the form:
# <version-hash> <repo-url>
local snapshot_content="$(-antigen-echo-record |
grep 'true$' |
sed 's/ .*$//' |
sort -u |
while read url; do
local dir="$(-antigen-get-clone-dir "$url")"
local version_hash="$(cd "$dir" && git rev-parse HEAD)"
echo "$version_hash $url"
done)"
Utiliser un grep pour filtrer les lignes
antigen-bundles () {
# Bulk add many bundles at one go. Empty lines and lines starting with a `#`
# are ignored. Everything else is given to `antigen-bundle` as is, no
# quoting rules applied.
local line
grep '^[[:space:]]*[^[:space:]#]' | while read line; do
# Using `eval` so that we can use the shell-style quoting in each line
# piped to `antigen-bundles`.
eval "antigen-bundle $line"
done
}
if [[ ! -f "$1" ]];then
echo "File-check-dir: need a file as argument : ${1:-no argument}" >&2
return 2
fi
Voir la différence entre les deux.
chksum() { (md5sum; test $? = 127 && md5) 2>/dev/null | cut -d' ' -f1 }
local checksum="$(echo "$snapshot_content" | chksum)"
unset -f chksum;
Factorisation
# def....
--add-var "${name//-/_}" "$value"
# ....
unfunction -- --add-var
analyser super foncion -antigen-parse-args
--add-var () {
test -z "$code" || code="$code\n"
code="${code}local $1='$2'"
}
if [[ $arg != *=* ]]; then
local name="$arg"
local value=''
else
local name="${arg%\=*}"
local value="${arg#*=}"
fi
-set-default () {
local arg_name="$1"
local arg_value="$2"
eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'"
}