rat-list (838B)
1 #!/bin/sh 2 # List friends 3 4 set -e 5 green() { printf "\033[1;32m$1\033[0;39;49m\n"; } 6 red() { printf "\033[1;31m$1\033[0;39;49m\n"; } 7 yellow() { printf "\033[1;33m$1\033[0;39;49m\n"; } 8 9 check() { 10 if ! test -e id; then 11 echo "ERROR: Is this a ratox directory?" >&2 12 exit 1 13 fi 14 } 15 16 set_state() { 17 if [ "$1" = 'none' ]; then 18 green "*" 19 elif [ "$1" = 'away' ]; then 20 yellow "*" 21 else 22 red "*" 23 fi 24 } 25 26 print_output() { 27 IDS=$(ls | grep '[A-Z0-9]\{64\}') 28 for ID in $IDS; do 29 NAME=$(cat $ID/name | tr -d '\n' | cut -c-32) 30 STATUS=$(cat $ID/status | tr -d '\n' | cut -c-40) 31 STATE=$(cat $ID/state) 32 ONLINE=$(cat $ID/online) 33 if [ "$ONLINE" -ne 0 ]; then 34 ONLINE="$(set_state $STATE)" 35 else 36 ONLINE='o' 37 fi 38 printf "%-8s | %s | %-32s\t\t%-40s\n" $(echo $ID | cut -c-8) "$ONLINE" "$NAME" "$STATUS" 39 done 40 } 41 42 check 43 print_output