Skip to content
Patrick Motard edited this page Jan 9, 2019 · 12 revisions

Quickly Creating New Scripts

Create new bash scripts automatically using Dotfiles shortcuts!

Examples

Create a new script called 'my-script' in current directory:
ns my-script

$PWD/my-script is created, executable, and opened in vim.

Create a new Tool (a bash script located in $TOOLS and in $PATH)
nt my-script

$TOOLS/my-script is created, executable, and opened in vim.

Create a new bash script in a specific directory
new_script -n my-script -p ~/Downloads/

~/Downloads/my-script is created, executable, and opened in vim.

Quickly Edit Existing Tools

Opening a script in your editor is easy enough. However, if you want to quickly edit a Tool (bash script in the $TOOLS directory) even if you aren't in the tools directory, use the same shortcut you used to create the script!

nt dot-update
Error: dot-update already exists in /home/han/.local/bin/tools
Edit dot-update? y/n

Press enter and your script will open in vim!

Colorized Output

colorized-output

You can output colorized lines in your bash scripts easily by using the dot-color Tool.

Setup

Your scripts need to know where colorized is located. In order to do this, I add the following to my ~/.profile:

Location: ~/.profile

export TOOLS="$HOME/.local/bin/tools"

Usage

In your bash script:

# import dot-color
source $TOOLS/dot-color

# use dot-color

# entire line colored green
color $Green "This message will be green!\n"

# entire line colored red
color $Red "And this one will be red!\n"

# a few words in sentence colored red
echo "hello this is the color " $(color $Red "red!") " This is awesome!"

List Available Colors

In your terminal:

dot-color -h 
    # Reset
    Nocolor='\033[0m'       # Text Reset

    # Regular Colors
    Black='\033[0;30m'        # Black
    Red='\033[0;31m'          # Red
    Green='\033[0;32m'        # Green
    Yellow='\033[0;33m'       # Yellow
    Blue='\033[0;34m'         # Blue
    Purple='\033[0;35m'       # Purple
    Cyan='\033[0;36m'         # Cyan
    White='\033[0;37m'        # White

    # Bold
    BBlack='\033[1;30m'       # Black
    BRed='\033[1;31m'         # Red
    BGreen='\033[1;32m'       # Green
    BYellow='\033[1;33m'      # Yellow
    BBlue='\033[1;34m'        # Blue
    BPurple='\033[1;35m'      # Purple
    BCyan='\033[1;36m'        # Cyan
    BWhite='\033[1;37m'       # White

    # Underline
    UBlack='\033[4;30m'       # Black
    URed='\033[4;31m'         # Red
    UGreen='\033[4;32m'       # Green
    UYellow='\033[4;33m'      # Yellow
    UBlue='\033[4;34m'        # Blue
    UPurple='\033[4;35m'      # Purple
    UCyan='\033[4;36m'        # Cyan
    UWhite='\033[4;37m'       # White

    # Background
    On_Black='\033[40m'       # Black

Examples: