To use SHML you must have unix-like (Darwin/macOS, Linux, etc.) POSIX-compliant operating system that supports ANSI/VT100 Control Sequences. If you are using an up to date version of macOS or any Linux distribution you should be good to go. If you run into issues please report it here.
$ sudo bash -c 'curl -L https://raw.githubusercontent.com/odb/shml/1.1.0/shml.sh -o /usr/local/bin/shml && chmod +x /usr/local/bin/shml'
$ npm install -g shml
$ brew install shml
$ git clone git@github.com:odb/shml.git
$ wget https://github.com/odb/shml/archive/master.zip
In order to use SHML you must tell your shell environment where it is located. Lets assume that we are writing a BASH script and want to use SHML.
If you installed in using the 1-liner above you would do:
#!/usr/bin/env bash
source $(which shml)
If you downloaded SHML using git or wget you would do:
#!/usr/bin/env bash
source ./shml.sh
To set the foreground color of any string or object you need to call the fgcolor
method followed by an argument.
Fifteen different colors to choose from:
black
red
green
yellow
blue
magenta
cyan
gray
white
darkgray
lightgreen
lightyellow
lightblue
lightmagenta
lightcyan
Following a string or object you must terminate the fgcolor
method to ensure color doesnโt bleed. You can use any of the following termination arguments:
end
off
or reset
Here we will demonstrate how the fgcolor
method can be used on a single line.
echo $(fgcolor green "RZA GZA") $(fgcolor end)
Some times one-line is not enough.
echo "
$(fgcolor yellow)
Inspectah Deck
Ghostface Killah
$(fgcolor end)
"
You can also use fgc
as an alias for fgcolor
.
echo $(fgc red "Killa Beez on a swarm") $(fgc end)
Here is what the output should look like. Style may differ slightly depending on your terminal emulator settings.
To set the background color of any string or object you need to call the bgcolor
method followed by an argument.
Fifteen different colors to choose from:
black
red
green
yellow
blue
magenta
cyan
gray
white
darkgray
lightgreen
lightyellow
lightblue
lightmagenta
lightcyan
Following a string or object you must terminate the background
method to ensure color doesnโt bleed. You can use any of the following termination arguments:
end
off
reset
Here we will demonstrate how the background
method can be used on a single line.
echo $(bgcolor red "I'm the O-D-B") $(bgcolor end)
Some times one-line is not enough.
echo "
$(bgcolor cyan)
...as you can see
F.B.I. don't you be watching me
$(bgcolor end)
"
You can also use bgc
as an alias for bgcolor
echo "$(bgc green)NUH you know name, now give me my money!$(bgc end)"
Here is what the output should look like. Style may differ slightly depending on your terminal emulator settings.
The attribute
method lets you stylize your text in 5 different ways.
bold
dim
underline
invert
hidden
You can use any of the following termination arguments:
end
off
reset
Following a string or object you must terminate the attribute
method.
Typing $(attribute end)
turns off everything, including foreground
and background
color methods.
echo "$(attribute underline "So Underlined") $(attribute end)"
echo "$(attribute bold "Such Bold") $(attribute end)"
echo "$(attribute invert "Why this inverted?") $(attribute end)"
You can also use a
as an alias for attribute
echo "$(a bold "such BOLD shorter") $(a end)"
Here is what the output should look like. Style may differ slightly depending on your terminal emulator settings.
Elements are methods that work a lot like <hr>
& <br>
HTML element tags. There is also a tab
& indent
method that acts like a
character entity. They are empty which means that they have no termination ends like the foreground color
, background
and attribute
methods.
The only method that allows arguments is hr
:
~
#
*
+
and/or any number e.g. 50
echo "$(hr)"
echo "$(hr 40)"
echo "$(hr '~' 30)"
echo "$(hr '#' 20)"
echo "$(hr '*' 10)"
echo "$(hr '+' 5)"
Break Line
echo "Wu$(br)Wu Tang$(br)Wu Tang$(br)Killah Beez$(br)We on a swarm"
Indent
echo "W$(indent)U$(indent)T$(indent)A$(indent)N$(indent)G"
You can also use i
as an alias for indent
echo "F$(i)O$(i)R$(i)E$(i)V$(i)A"
Tab
echo "W$(tab)U$(tab)T$(tab)A$(tab)N$(tab)G"
Icons are flat ascii characters that are supported by most unix-like systems. If you run into compatibility issues please report it here.
checkmark
xmark
heart
sun
star
darkstar
umbrella
flag
snowflake
music
scissors
trademark
copyright
apple
smile
Peter, a software engineer likes to use the xmark
icon in his programs:
echo "$(icon xmark)TPS Reports $(icon xmark)Lumbergh $(icon xmark)Working"
When he is in a better mood, he tends to use the check
icon:
echo "$(icon check)Kung Fu $(icon check)Fishing $(icon check)Sleep"
Sometimes he even uses the foreground color
method to add some emphasis:
echo "$(color red)$(icon xmark)$(color end)TPS Reports $(color green)$(icon check)$(color end)Fishing"
To add an emoji you need to call the emoji
method followed by an argument. Each emoji added to SHML was approved as part of Unicodeยฎ 6.0.0 Standard in 2010.
Argument | Alias(es) | Result |
---|---|---|
smiley |
1F603 '=)' ':-)' ':)' |
๐ |
innocent |
1F607 halo |
๐ |
joy |
1F602 lol laughing |
๐ |
=p |
1F61B stuck_out_tongue =P |
๐ |
worried |
1F61F sadface sad |
๐ |
cry |
1F622 crying tear |
๐ข |
rage |
1F621 redface |
๐ก |
wave |
1F44B hello goodbye |
๐ |
ok_hand |
1F44C perfect okay nice |
๐ |
thumbsup |
1F44D +1 like |
๐ |
thumbsdown |
1F44E -1 no dislike |
๐ |
smiley_cat |
1F63A happycat |
๐บ |
cat |
1F431 kitten :3 kitty |
๐ฑ |
dog |
1F436 puppy |
๐ถ |
bee |
1F41D honeybee bumblebee |
๐ |
pig |
1F437 pighead |
๐ท |
monkey |
1F437 monkey_face |
๐ต |
cow |
1F42E happycow |
๐ฎ |
panda |
1F43C panda_face shpanda |
๐ผ |
sushi |
1F363 raw sashimi |
๐ฃ |
home |
1F3E0 house |
๐ |
eyeglases |
1F453 bifocals eyeglasses |
๐ |
smoke |
1F6AC smoking cigarette |
๐ฌ |
fire |
1F525 flame hot |
๐ฅ |
hankey |
1F4A9 poop shit |
๐ฉ |
beer |
1F37A homebrew brew |
๐บ |
cookie |
1F36A biscuit chocolate |
๐ช |
lock |
1F512 padlock secure |
๐ |
unlock |
1F513 openpadlock |
๐ |
star |
2B50 yellowstar |
โญ |
joker |
1F0CF black_joker wild |
๐ |
check |
2705 white_check_mark |
โ |
x |
274C cross xmark |
โ |
toilet |
1F6BD restroom loo |
๐ฝ |
bell |
1F514 ringer ring |
๐ |
search |
1F50E mag_right magnify |
๐ |
dart |
1F3AF bullseye darts |
๐ฏ |
cash |
1F4B5 dollar cream |
๐ต |
thinking |
1F4AD thought_balloon |
๐ญ |
luck |
1F340 four_leaf_clover |
๐ |
echo "Couldn't peep it with a pair of $(emoji bifocals)"
echo "I'm no $(emoji joker) play me as a $(emoji joker)"
echo "$(emoji bee) on you like a $(emoji house) on $(emoji fire), $(emoji smoke) ya"
To add a color bar you need to call the color-bar
method followed by an (optional) argument.
Fifteen different colors to choose from:
black
red
green
yellow
blue
magenta
cyan
gray
white
darkgray
lightgreen
lightyellow
lightblue
lightmagenta
lightcyan
echo "$(color-bar)"
echo "
$(color-bar red green yellow blue magenta \
cyan lightgray darkgray lightred \
lightmagenta lightcyan)
"
echo "Yeah ahuh, you know what it is $(color-bar black yellow black yellow)"
You can also use bar
as an alias for color-bar
echo "I put it down from the whip to my diamonds, I'm in $(bar black yellow black yellow)"
Confirm allows you to simply ask end-users questions.
confirm QUESTION [SUCCESS_FUNCTION] [FAILURE_FUNCTION]
on_human() {
dialog "What is your name?" "on_dialog"
}
on_dialog() {
echo "$(color green "Hello, $1! $(emoji beer)")"
}
on_not_human() {
confirm "$(color red "Do you come in peace?")" "on_friend" "on_enemy"
}
on_friend() {
echo "$(emoji '=)') $(emoji beer)"
}
on_enemy() {
echo "$(emoji rage) $(emoji poop)"
}
confirm "$(color blue "Are you human?")" "on_human" "on_not_human"
exit 0