checkium.sh (1345B)
1 #!/usr/bin/env bash 2 3 checkium_color() { 4 # set color depending on if the last command succeed or not 5 if [[ $? -eq 0 ]]; then 6 echo -ne "\033[0;32m" 7 return 0 8 else 9 echo -ne "\033[0;31m" 10 # need to return a value so that the other functions here will 11 # know if last command ran OK or not, the previous code will return 0 12 return 1 13 fi 14 } 15 16 checkium_color_simple() { 17 if [[ $? -eq 0 ]]; then 18 return 0 19 else 20 echo -ne "\033[0;31m" 21 return 1 22 fi 23 } 24 25 checkium_custom() { 26 if [[ $? -eq 0 ]]; then 27 local char=$1 28 else 29 local char=$2 30 fi 31 echo $char 32 } 33 34 checkium_check() { 35 if [[ $? -eq 0 ]]; then 36 local char="✓" 37 else 38 local char="✗ " 39 fi 40 echo $char 41 } 42 43 checkium_face() { 44 if [[ $? -eq 0 ]]; then 45 local face=":)" 46 else 47 local face=":(" 48 fi 49 echo $face 50 } 51 52 checkium_random_face() { 53 # set arrays for different faces to randomly choose from 54 if [[ $? -eq 0 ]]; then 55 local faces=(":)" ":D") 56 else 57 local faces=(":P" ":(" ":(" ":O" ":\\" ":|" ":(" ":(") 58 fi 59 60 local facels=${#faces[*]} # get how many elements are in each array 61 local randfacels=${faces[$((RANDOM % facels))]} # randomly choose an array element 62 echo $randfacels # print that face 63 64 } 65