#! /usr/local/bin/zsh # # this file: # https://dataswamp.org/~incal/sth/scripts/senior local passwdf=/etc/passwd local ignore=\(nologin\|root\) local delim=':' acn_pos () { local pos=$1 if [[ $pos ]]; then local usr=$(egrep -v $ignore $passwdf | sed '$d' | head -n $pos | tail -n 1 | cut -d $delim -f 1) if [[ $usr != '' ]]; then echo "$usr[1].$usr[2,-1]" fi fi } acn_usr () { local usr=$1 local jun="junior" local dotjun="$jun[1].$jun[2,-1]" local joe="joehckr" local dotjoe="$joe[1].$joe[2,-1]" if [[ $usr = $jun || $usr = $dotjun ]]; then zsh /home/incal/public_html/bot/scripts/junior elif [[ $usr[2] != '.' ]]; then echo "use $joe for $dotjoe" else local rusr="$usr[1]$usr[3,-1]" egrep -v $ignore $passwdf | sed '$d' | egrep -n "^$rusr" - | cut -d $delim -f 1 fi } local pos=1 if [[ $1 != '' ]]; then local arg=$1 if [[ "$arg" =~ "^[0-9]+$" ]]; then pos=$arg if [[ $pos == 0 ]]; then # secret echo "error: failed to unhash non-empty entry" return fi else acn_usr $arg return fi fi acn_pos $pos