dotfiles

config files for my linux setup
git clone git://edryd.org/dotfiles
Log | Files | Refs | README

echk (1068B)


      1 #!/usr/bin/env bash
      2 
      3 # echk: functions to display shell error code
      4 
      5 echk_color() {
      6     # set color depending on if the last command succeed or not
      7     if [[ $? -eq 0 ]]; then
      8         echo -ne "\033[0;32m"
      9         return 0
     10     else
     11         echo -ne "\033[0;31m"
     12         # need to return a value so that the other functions here will
     13         # know if last command ran OK or not, the previous code will return 0
     14         return 1 # TODO $?
     15     fi
     16 }
     17 
     18 echk_color_simple() {
     19     if [[ $? -eq 0 ]]; then
     20         return 0
     21     else
     22         echo -ne "\033[0;31m"
     23         return 1
     24     fi
     25 }
     26 
     27 echk_char() {
     28     if [[ $? -eq 0 ]]; then
     29         echo "$1"
     30     else
     31         echo "$2"
     32     fi
     33 }
     34 
     35 echk_check() {
     36     echk_char "✓" "✗ "
     37 }
     38 
     39 echk_face() {
     40     echk_char ":)" ":("
     41 }
     42 
     43 echk_random_face() {
     44     # set arrays for different faces to randomly choose from
     45     if [[ $? -eq 0 ]]; then
     46         local faces=(":)" ":D")
     47     else
     48         local faces=(":P" ":(" ":/" ":O" ":\\" ":|" ":(" ":(")
     49     fi
     50 
     51     echo ${faces[$((RANDOM % ${#faces[*]}))]} # randomly choose an array element
     52 }