Created
December 6, 2016 23:29
-
-
Save rejacobson/680e99625553ecd1725602dc1bd206fd to your computer and use it in GitHub Desktop.
bash color helper functions
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
| function color() { # auto complete helper, second argument is a grep against the function list | |
| if [[ '' == "$@" ]] | |
| then | |
| echo "Parse Namespaced Functions List" | |
| cat $BASH_SOURCE | grep "^function[^(]" | awk '{j=" USAGE:"; for (i=5; i<=NF; i++) j=j" "$i; print $2" "j}' | |
| else | |
| echo "Parse Functions Matching: $@" | |
| cat $BASH_SOURCE | grep "^function[^(]" | awk '{j=" USAGE:"; for (i=5; i<=NF; i++) j=j" "$i; print $2" "j}' | grep $@ | |
| fi | |
| } | |
| function color.test() { # colortest N - Output text with the passed in color number | |
| color.fg $1 | |
| echo "This is a test" | |
| color.reset | |
| } | |
| function color.fg { # Foreground color | |
| echo -ne "\e[38;5;$1m" | |
| } | |
| function color.bg { # Background color | |
| echo -ne "\e[48;5;$1m" | |
| } | |
| function color.reset () { # Reset the color in an echo call | |
| echo -ne '\e[0m' | |
| } | |
| function color.fg.prompt { # Foreground color in a prompt | |
| echo -ne "\[\e[38;5;$1m\]" | |
| } | |
| function color.bg.prompt { # Background color in a prompt | |
| echo -ne "\[\e[48;5;$1m\]" | |
| } | |
| function color.reset.prompt { # Reset the color in a prompt | |
| echo -ne '\[\e[0m\]' | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment