Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts

Tuesday, August 18, 2015

Customizing the Color of Your Terminal Prompt

I posted a quick tip a couple of weeks ago about on how to Change the Terminal Command Prompt.

I want to take it one step further and add custom color to the prompt and/or to a portion of the prompt.

 currentDirectory$   export PS1='\e[1;32m\W\e[m\$'                                                   
 currentDirectory$                                                                                                    

I found this link to be a good bash prompt overview of how to customize your terminal prompt and has a list of fore and background colors show below:

Foreground colors, Normal (non-bold) is the default, so the 0; prefix is optional.
\e[0;30m = Dark Gray
\e[1;30m = Bold Dark Gray
\e[0;31m = Red
\e[1;31m = Bold Red
\e[0;32m = Green
\e[1;32m = Bold Green
\e[0;33m = Yellow
\e[1;33m = Bold Yellow
\e[0;34m = Blue
\e[1;34m = Bold Blue
\e[0;35m = Purple
\e[1;35m = Bold Purple
\e[0;36m = Turquoise
\e[1;36m = Bold Turquoise
\e[0;37m = Light Gray
\e[1;37m = Bold Light Gray
Background colors:
\e[40m = Dark Gray
\e[41m = Red
\e[42m = Green
\e[43m = Yellow
\e[44m = Blue
\e[45m = Purple
\e[46m = Turquoise
\e[47m = Light Gray

Sunday, August 2, 2015

Set Command Line Path

export PATH="/USERS/joesmith/bin:$PATH"
  1. Put the following in you .bashrc or .bash_profile in you root/home directory:   export PATH="/USERS/joesmith/bin:$PATH"
  2. Restart Terminal


Create Alias Command in Bash

alias ll='ls -lahG'
  1. Put the following in you .bashrc or .bash_profile in you root/home directory:   alias ll='ls -lahG'
  2. Restart Terminal


Change the Terminal Command Prompt

export PS1="\w/\u$ "
  1. Put the following in you .bashrc or .bash_profile in you root/home directory:   export PS1= "\w/\u$ "
  2. Restart Terminal

Links
Bash Prompt Basics


Turn on GIT Autocompletion in Mac OSX



if [ -f ~/.git-completion.bash ]; then
   source ~/.git-completion.bash
fi
  1. Open up terminal and navigate to your root/home directory: cd ~
  2. Download git-completion.bash from github.com via the terminal by typing the following:          curl -Lo .git-completion.bash https://github.com/git/git/raw/master/contrib/completion/git-completion.bash 
  3. Put the following in you .bashrc or .bash_profile in you root/home directory:  
    if [ -f ~/.git-completion.bash ]; then
       source ~/.git-completion.bash
    fi
  4. Restart Terminal
  5. Navigate to you git repository
  6. Type "git a"+tab and you should see "git add" or try "git h"+tab and you should see "git help"

Links
Bash Scripting: How to
Bash Beginners Guide 
Advanced Bash Scripting

How to check if a file exists in Bash

In Unix, Mac, or Windows (Cygwin) you can check if a file exists when you load up the terminal window.  The script is as follows:

if [ -f ~/somefilename ]; then
   source ~/somefilename
fi

In this example the script checks to see if a file named "somefilename" exists in my home/root directory.  If it "somefilename" exists then it sources/executes the content of that file as a script.

When is this useful?  I'll show you in the following post: Turn on Git Autocompletion


Links
Bash Scripting: How to
Bash Beginners Guide 
Advanced Bash Scripting