ratox-nuggets

useful ratox related scripts
git clone git://git.2f30.org/ratox-nuggets
Log | Files | Refs | LICENSE

commit 935b27035794e6bfc62a6a80c2f65ad6c2e609a7
parent 5daf6d61be064fe620376fc812bf462a6e9b12dc
Author: FRIGN <dev@frign.de>
Date:   Sun,  2 Nov 2014 12:18:45 +0100

Refactor rat-list

Get rid of the library (which is slow to load) and fix a small
bug so the \n's are removed before the cut is made. Else, the
output is squashed for long multiline statuses.

Diffstat:
Mrat-list | 53++++++++++++++++++++++++++++-------------------------
1 file changed, 28 insertions(+), 25 deletions(-)

diff --git a/rat-list b/rat-list @@ -1,40 +1,43 @@ #!/bin/sh # List friends -LIBRARY_LOCATION=`dirname $0` -. $LIBRARY_LOCATION/functions -export PATH=$LIBRARY_LOCATION:$PATH - set -e green() { printf "\033[1;32m$1\033[0;39;49m\n"; } red() { printf "\033[1;31m$1\033[0;39;49m\n"; } yellow() { printf "\033[1;33m$1\033[0;39;49m\n"; } +check() { + if ! test -e id; then + echo "ERROR: Is this a ratox directory?" >&2 + exit 1 + fi +} + set_state() { - if [ "$1" = 'none' ]; then - green "*" - elif [ "$1" = 'away' ]; then - yellow "*" - else - red "*" - fi + if [ "$1" = 'none' ]; then + green "*" + elif [ "$1" = 'away' ]; then + yellow "*" + else + red "*" + fi } print_output() { - IDS=$(ls |grep '[A-Z0-9]\{64\}') - for ID in $IDS; do - NAME=$(cat $ID/name | tr -d '\n' | cut -c-32) - STATUS=$(cat $ID/status | cut -c-40 |tr -d '\n') - STATE=$(cat $ID/state) - ONLINE=$(cat $ID/online) - if [ "$ONLINE" -ne 0 ]; then - ONLINE="$(set_state $STATE)" - else - ONLINE='o' - fi - printf "%-8s | %s | %-32s\t\t%-40s\n" $(echo $ID | cut -c-8) "$ONLINE" "$NAME" "$STATUS" - done + IDS=$(ls | grep '[A-Z0-9]\{64\}') + for ID in $IDS; do + NAME=$(cat $ID/name | tr -d '\n' | cut -c-32) + STATUS=$(cat $ID/status | tr -d '\n' | cut -c-40) + STATE=$(cat $ID/state) + ONLINE=$(cat $ID/online) + if [ "$ONLINE" -ne 0 ]; then + ONLINE="$(set_state $STATE)" + else + ONLINE='o' + fi + printf "%-8s | %s | %-32s\t\t%-40s\n" $(echo $ID | cut -c-8) "$ONLINE" "$NAME" "$STATUS" + done } -check_if_dir +check print_output