commit aa016545802ee6d91ad88f5d615ce797ea7b2b32 parent f08ebb90655d4f3dcd40666fc466386a71261aa3 Author: Kill Your TV <killyourtv@i2pmail.org> Date: Wed, 8 Oct 2014 23:43:02 +0000 coloured statuses, limit toxid to 8 chars, nick to 32 Diffstat:
M | rat-list | | | 30 | ++++++++++++++++++------------ |
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/rat-list b/rat-list @@ -1,12 +1,18 @@ #!/bin/sh -set -e # List friends -online() { - if [ $1 -eq 1 ]; then - echo "Online" +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"; } + +set_state() { + if [ "$1" = 'none' ]; then + green "*" + elif [ "$1" = 'away' ]; then + yellow "*" else - echo "Offline" + red "*" fi } @@ -23,16 +29,16 @@ check_if_dir(){ print_output() { IDS=$(ls |grep '[A-Z0-9]\{64\}') for ID in $IDS; do - NAME=$(cat $ID/name | tr -d '\n') - STATUS=$(cat $ID/status | cut -c-30 |tr -d '\n') - STATE=$(cat $ID/state | sed 's/.*/\u&/') + 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 [ $STATE != 'None' ] && [ "$ONLINE" -ne 0 ]; then - ONLINE=$STATE + if [ "$ONLINE" -ne 0 ]; then + ONLINE="$(set_state $STATE)" else - ONLINE=$(online $ONLINE) + ONLINE='o' fi - printf "%-12s\t%-8s\t%-30s\t%-20s\n" $(echo $ID | cut -c-12) "$ONLINE" "$NAME" "$STATUS" + printf "%-8s | %s | %-32s\t\t%-40s\n" $(echo $ID | cut -c-8) "$ONLINE" "$NAME" "$STATUS" done }