Un outil pour savoir si une commande est posix - retour accueil
git clone git://bebou.netlib.re/isposix
Log | Files | Refs | README |
isposix (1291B)
1 #! /bin/sh 2 set -e 3 4 red="\033[91m";green="\033[92m";blue="\033[94m";norm="\033[0m" 5 _die() { printf "$red$@$norm" >&2 ; } 6 _success() { printf "$green$@$norm" >&2; } 7 _inform() { printf "$blue$@$norm" >&2; } 8 _cmdnotposix() { 9 _die "$cmd not posix" 10 if command -V fzy 2>&1 > /dev/null;then 11 fzcmd=$(find bdd -name '*.html' | 12 xargs -I{} basename {} | sed 's/\.html$//' | 13 fzy -e "$cmd" | head -n3) 14 fi 15 [ -z "$fzcmd" ] \ 16 && _die "$cmd" \ 17 || _inform ", did you mean : $(echo "$fzcmd" | paste -s -d',') ?" 18 } 19 20 usage() { 21 <<-. cat 22 Check if command or its options are posix 23 24 isposix command [options] 25 26 exemple : 27 28 isposix ls 29 isposix ls -a 30 . 31 } 32 33 checkoption() { 34 cmd="$1";option="$2" 35 < bdd/$cmd.html grep -Eq "<dt><b>-$option[&<].*</dt>" \ 36 && { _success " -$option";return 0;} \ 37 || { _die " -$option"; return 1;} 38 } 39 40 scriptisposix=0 41 while read line;do 42 set -- $line 43 cmdisposix=0 44 cmd="$1";shift 45 if [ ! -f "bdd/$cmd.html" ];then 46 _cmdnotposix;cmdisposix=1 47 else 48 _success "$cmd" 49 while getopts "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" opt; do 50 case "$opt" in 51 ( * ) checkoption "$cmd" "$opt" || cmdisposix=1;; 52 esac 53 done 54 fi 55 [ $cmdisposix = "0" ] \ 56 && _success " | is posix\n" \ 57 || { _die " | not posix\n";scriptisposix=1; } 58 done 59 60 exit $scriptisposix 61