Created
August 2, 2012 20:07
-
-
Save garu/3240220 to your computer and use it in GitHub Desktop.
pure-shell version of "perl -MDDP -e 'p %ENV'"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin/env bash | |
names=(); | |
values=(); | |
biggest=0; | |
# first we separate ENV in keys and values, | |
# and fetch the size of the biggest key | |
for ITEM in `env` | |
do | |
name=${ITEM%%=*}; | |
if [ ${#name} -gt $biggest ] | |
then | |
biggest=${#name}; | |
fi | |
names[${#names[*]}]=$name | |
values[${#values[*]}]=${ITEM#*=} | |
done | |
# now we print our output in a nicely formatted way :) | |
for (( i = 0; i < ${#names[*]}; i++ )) | |
do | |
printf '\E[35;40m%-*s\E[0m \E[33;40m"%s"\E[0m\n' $biggest ${names[$i]} ${values[$i]}; | |
done | |
# ANSI screen colours cheat-sheet: | |
# | |
# \E[FORECOLOUR;BGCOLOURm Text goes here \E[0m | |
# | |
# * FORECOLOUR is the text colour | |
# * BGCOLOUR is the background colour | |
# * don't forget the tiny 'm' after the bgcolours | |
# * \E[0m resets the colours | |
# | |
# Note: fg and bg colour codes do not overlap, so the actual order doesn't matter. | |
# | |
# Colour Foreground Background | |
# black 30 40 | |
# red 31 41 | |
# green 32 42 | |
# yellow 33 43 | |
# blue 34 44 | |
# magenta 35 45 | |
# cyan 36 46 | |
# white 37 47 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment