Skip to content

Commit

Permalink
fix for output trailing comments in a different color
Browse files Browse the repository at this point in the history
  • Loading branch information
doekman committed Jun 14, 2018
1 parent 3a22ae3 commit b16f0e1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ok
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
ok() {

# used for colored output
CYAN='\033[0;36m'
CYAN=$'\033[0;36m'
BLUE=$'\033[0;34m'
NC='\033[0m' # No Color
NC=$'\033[0m' # No Color

# if there is a file called .ok...
if [ -f .ok ]; then
re='^[0-9]+$'
# if the user provided a parameter, $1, which contains a number...
if [[ $1 =~ $re ]] ; then
# output the command first
cat .ok | echo -e "${CYAN}$ ${NC}$(sed $1'!d')" | sed "s/#/${BLUE}#/1"
cat .ok | echo -e "${CYAN}$ ${NC}$(sed $1'!d')" | sed -E "s/(#.*)\$/${BLUE}\1${NC}/1"
# execute that line from the file
# TODO: pass through any remaining parameters, i.e ${@:2}
eval $( cat .ok | sed $1'!d' )
else
# list the content of the file, with a number (1-based) before each line
cat .ok | awk -v z=$CYAN -v n=$NC '{print z "" ++i "." n " " $0 }' | sed "s/#/${BLUE}#/1"
cat .ok | awk -v z=$CYAN -v n=$NC '{print z "" ++i "." n " " $0 }' | sed -E "s/(#.*)\$/${BLUE}\1${NC}/1"
fi
fi
}

0 comments on commit b16f0e1

Please sign in to comment.