Skip to content

Commit

Permalink
Make shell colors work on both sh and bash
Browse files Browse the repository at this point in the history
  • Loading branch information
acquitelol committed Mar 11, 2024
1 parent 912b8a3 commit ffec23a
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions make.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
#!/bin/sh

type=$(ps -p $$ -o comm=)
yellow='\033[93m'
green='\033[92m'
red='\033[91m'
endc='\033[0m'

print() {
if [ "$type" = "bash" ]; then
echo -e "$1"
else
echo "$1"
fi
}

doing() {
echo -e "$yellow[*] $1...$endc"
print "$yellow[*] $1...$endc"
}

finished() {
lowercase=$(echo -e "$1" | tr '[:upper:]' '[:lower:]')
echo -e "$green[+] Done $lowercase!$endc"
lowercase=$(print "$1" | tr '[:upper:]' '[:lower:]')
print "$green[+] Done $lowercase!$endc"
}

failed() {
lowercase=$(echo -e "$1" | tr '[:upper:]' '[:lower:]')
echo -e "$red[-] Failed $lowercase!$endc"
lowercase=$(print "$1" | tr '[:upper:]' '[:lower:]')
print "$red[-] Failed $lowercase!$endc"
exit 1
}

Expand Down

0 comments on commit ffec23a

Please sign in to comment.