Skip to content

Instantly share code, notes, and snippets.

@shadiabuhilal
Created February 2, 2024 09:58
Show Gist options
  • Save shadiabuhilal/e08d0b41441ddf54d5830d0de14cf3df to your computer and use it in GitHub Desktop.
Save shadiabuhilal/e08d0b41441ddf54d5830d0de14cf3df to your computer and use it in GitHub Desktop.

Revisions

  1. shadiabuhilal created this gist Feb 2, 2024.
    42 changes: 42 additions & 0 deletions text-formatting-in-bash.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    #!/bin/bash

    # Function to format text as bold
    boldText() {
    tput bold
    echo "$@"
    tput sgr0
    }

    # Function to default color text as white
    defaultText() {
    tput setaf 97
    echo "$@"
    tput sgr0
    }

    # Function to success color text with green
    successText() {
    tput setaf 2
    echo "$@"
    tput sgr0
    }

    # Function to info color text with blue
    infoText() {
    tput setaf 4
    echo "$@"
    tput sgr0
    }

    # Function to error color text with red
    errorText() {
    tput setaf 1
    echo "$@"
    tput sgr0
    }

    # Usage exmaple for bold text:
    echo $(boldText "Reading $ENV_FILE file.")

    # Usage exmaple for bold text and success color:
    echo $(boldText "$(successText "[DONE]:") Reading $ENV_FILE file.")