Un outil pour savoir si une commande est posix - retour accueil
git clone git://bebou.netlib.re/isposix
Log | Files | Refs | README |
commit ff50db0c2aace3513afc94aa2b4d267f67e089d2 parent d9987d0ac85bbfac7ad5d81377976de2c641c087 Auteurice: Arthur Pons <arthur.pons@unistra.fr> Date: Mon, 25 Nov 2024 10:50:48 +0100 Ajout makefile pour "compiler"/installer Diffstat:
M | .gitignore | | | 2 | ++ |
A | isposix.sh | | | 61 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | makefile | | | 8 | ++++++++ |
A | posix.sh | | | 3 | +++ |
4 files changed, 74 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore @@ -1 +1,3 @@ .*.sw? +posix +isposix diff --git a/isposix.sh b/isposix.sh @@ -0,0 +1,61 @@ +#! /bin/sh +set -e + +red="\033[91m";green="\033[92m";blue="\033[94m";norm="\033[0m" +_die() { printf "$red$@$norm" >&2 ; } +_success() { printf "$green$@$norm" >&2; } +_inform() { printf "$blue$@$norm" >&2; } +_cmdnotposix() { + _die "$cmd not posix" + if command -V fzy 2>&1 > /dev/null;then + fzcmd=$(find bdd -name '*.html' | + xargs -I{} basename {} | sed 's/\.html$//' | + fzy -e "$cmd" | head -n3) + fi + [ -z "$fzcmd" ] \ + && _die "$cmd" \ + || _inform ", did you mean : $(echo "$fzcmd" | paste -s -d',') ?" +} + +usage() { + <<-. cat + Check if command or its options are posix + + isposix command [options] + + exemple : + + isposix ls + isposix ls -a + . +} + +checkoption() { + cmd="$1";option="$2" + < bdd/$cmd.html grep -Eq "<dt><b>-$option[&<].*</dt>" \ + && { _success " -$option";return 0;} \ + || { _die " -$option"; return 1;} +} + +scriptisposix=0 +while read line;do + set -- $line + cmdisposix=0 + cmd="$1";shift + if [ ! -f "bdd/$cmd.html" ];then + _cmdnotposix;cmdisposix=1 + else + _success "$cmd" + while getopts "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" opt; do + case "$opt" in + ( * ) checkoption "$cmd" "$opt" || cmdisposix=1;; + esac + done + fi + [ $cmdisposix = "0" ] \ + && _success " | is posix\n" \ + || { _die " | not posix\n";scriptisposix=1; } +done + +exit $scriptisposix + diff --git a/makefile b/makefile @@ -0,0 +1,8 @@ +PREFIX = /usr/local + +all: posix isposix + +install: + mkdir -p "${DESTDIR}${PREFIX}/bin" + cp isposix "${DESTDIR}${PREFIX}/bin" + cp posix "${DESTDIR}${PREFIX}/bin" diff --git a/posix.sh b/posix.sh @@ -0,0 +1,3 @@ +#! /bin/sh + +${BROWSER:-w3m} bdd/${1:?need command}.html