Skip to main content
added 768 characters in body
Source Link
Michael Durrant
  • 43.7k
  • 73
  • 176
  • 238

The purpose of a .bashrc file is to provide a place where you can set up variables, functions and aliases, define your (PS1) prompt and define other settings that you want to use every starttime you open a new terminal window.

YouA super minimal one might have the following:

export CLICOLOR=1 export LANG="en_US.UTF-8" alias cp="cp -i" alias ls="ls --color=auto" export PS1="\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ " export EDITOR="vim" 

That's all you really know to get started


Here's the "overkill" version, useful for experienced developers:

An experienced developer will often have a lot more.
You can see mine here (pic with syntax highlighting):

This also makes it easier to use the entire file immediately on a new machine without having issues that affect opening a new terminal window.

REMINDER - if you change your .bashrc, be sure to start a new terminal window to make sure it works BEFORE rebooting (best practice - do it immediately after the change). If you ever mess up your .bashrc and reboot YOU MAY NOT BE ABLE TO LOGIN! Personally I also create a second 'admin' user on personal machines so that, in such an emergency (broken login), I can log into that and use then use sudo to fix my other login .bashrc file.

The purpose of a .bashrc file is to provide a place where you can set up variables, functions and aliases, define your (PS1) prompt and define other settings that you want to use every start you open a new terminal window.

You can see mine here (pic with syntax highlighting):

This also makes it easier to use the entire file immediately on a new machine without having issues that affect opening a new terminal window.

The purpose of a .bashrc file is to provide a place where you can set up variables, functions and aliases, define your (PS1) prompt and define other settings that you want to use every time you open a new terminal window.

A super minimal one might have the following:

export CLICOLOR=1 export LANG="en_US.UTF-8" alias cp="cp -i" alias ls="ls --color=auto" export PS1="\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ " export EDITOR="vim" 

That's all you really know to get started


Here's the "overkill" version, useful for experienced developers:

An experienced developer will often have a lot more.
You can see mine here (pic with syntax highlighting):

This also makes it easier to use the entire file immediately on a new machine without having issues that affect opening a new terminal window.

REMINDER - if you change your .bashrc, be sure to start a new terminal window to make sure it works BEFORE rebooting (best practice - do it immediately after the change). If you ever mess up your .bashrc and reboot YOU MAY NOT BE ABLE TO LOGIN! Personally I also create a second 'admin' user on personal machines so that, in such an emergency (broken login), I can log into that and use then use sudo to fix my other login .bashrc file.

improve accessibility by making code code instead of a pic.
Source Link

You can see mine here (pic with syntax highlighting):![enter image description here][1]

HISTCONTROL=ignoreboth:erasedups HISTSIZE=100000 HISTFILESIZE=200000 ls --color=al > /dev/null 2>&1 && alias ls='ls -F --color=al' || alias ls='ls -G' md () { [ $# = 1 ] && mkdir -p "$@" && cd "$@" || echo "Error - no directory passed!"; } git_branch () { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'; } HOST='\033[02;36m\]\h'; HOST=' '$HOST TIME='\033[01;31m\]\t \033[01;32m\]' LOCATION=' \033[01;34m\]`pwd | sed "s#\(/[^/]\{1,\}/[^/]\{1,\}/[^/]\{1,\}/\).*\(/[^/]\{1,\}/[^/]\{1,\}\)/\{0,1\}#\1_\2#g"`' BRANCH=' \033[00;33m\]$(git_branch)\[\033[00m\]\n\$ ' PS1=$TIME$USER$HOST$LOCATION$BRANCH PS2='\[\033[01;36m\]>' set -o vi # vi at command line export EDITOR=vim test -f ~/.bash_aliases && . $_ test -f ~/.git-completion.bash && . $_ test -s ~/.autojump/etc/profile.d/autojump && . $_ [ ${BASH_VERSINFO[0]} -ge 4 ] && shopt -s autocd [ -f /etc/bash_completion ] && ! shopt -oq posix && . /etc/bash_completion [ -z $TMUX ] && export TERM=xterm-256color && exec tmux export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$home/.rvm/scripts/rvm" 

-1. Set up my history file to ignore duplicates and be much larger than the default.
-2. Color option for ls depending on if you are using linux or OSX
-3. Function "md" to make and cd into a directory with one command
-4. Find the current git branch if in a git repo and...
-5. -9. Define an awesome PS1 prompt, as in ![enter image description here][2]20:00:43 durrantm Castle2012 /hom/durrantm/Dropnot/_/rails_apps/linker master \n $ _
-10. Improved PS2 prompt
-11. Set vi as the editor at the command line
-12. Set vi as the default editor
-13. execute my .bash_aliases file if it exists
-14. Execute my git tab completion script (for remotes and branches) if it exists.
-15. Execute autojump if it exists
-16. Allow cd'ing without typing the cd part if the bash version >= 4
-17. Execute a bash completion script if it exists
-18. Use TMUX if it is present
-19. Add rvm to my PATH
-20. Use rvm if it exists.

I've made this portable so that it works on any of my linux or OSX machines without customization - hence a number of tests for presence are done before using certain functions and other scripts. This

This also makes it easier to use the entire file immediately on a new machine without having issues that affect opening a new terminal window. [1]: https://i.sstatic.net/DQnGN.png [2]: https://i.sstatic.net/slR41.png

You can see mine here:![enter image description here][1]

-1. Set up my history file to ignore duplicates and be much larger than the default.
-2. Color option for ls depending on if you are using linux or OSX
-3. Function "md" to make and cd into a directory with one command
-4. Find the current git branch if in a git repo and...
-5. -9. Define an awesome PS1 prompt, as in ![enter image description here][2]
-10. Improved PS2 prompt
-11. Set vi as the editor at the command line
-12. Set vi as the default editor
-13. execute my .bash_aliases file if it exists
-14. Execute my git tab completion script (for remotes and branches) if it exists.
-15. Execute autojump if it exists
-16. Allow cd'ing without typing the cd part if the bash version >= 4
-17. Execute a bash completion script if it exists
-18. Use TMUX if it is present
-19. Add rvm to my PATH
-20. Use rvm if it exists.

I've made this portable so that it works on any of my linux or OSX machines without customization - hence a number of tests for presence are done before using certain functions and other scripts. This also makes it easier to use the entire file immediately on a new machine without having issues that affect opening a new terminal window. [1]: https://i.sstatic.net/DQnGN.png [2]: https://i.sstatic.net/slR41.png

You can see mine here (pic with syntax highlighting):

HISTCONTROL=ignoreboth:erasedups HISTSIZE=100000 HISTFILESIZE=200000 ls --color=al > /dev/null 2>&1 && alias ls='ls -F --color=al' || alias ls='ls -G' md () { [ $# = 1 ] && mkdir -p "$@" && cd "$@" || echo "Error - no directory passed!"; } git_branch () { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'; } HOST='\033[02;36m\]\h'; HOST=' '$HOST TIME='\033[01;31m\]\t \033[01;32m\]' LOCATION=' \033[01;34m\]`pwd | sed "s#\(/[^/]\{1,\}/[^/]\{1,\}/[^/]\{1,\}/\).*\(/[^/]\{1,\}/[^/]\{1,\}\)/\{0,1\}#\1_\2#g"`' BRANCH=' \033[00;33m\]$(git_branch)\[\033[00m\]\n\$ ' PS1=$TIME$USER$HOST$LOCATION$BRANCH PS2='\[\033[01;36m\]>' set -o vi # vi at command line export EDITOR=vim test -f ~/.bash_aliases && . $_ test -f ~/.git-completion.bash && . $_ test -s ~/.autojump/etc/profile.d/autojump && . $_ [ ${BASH_VERSINFO[0]} -ge 4 ] && shopt -s autocd [ -f /etc/bash_completion ] && ! shopt -oq posix && . /etc/bash_completion [ -z $TMUX ] && export TERM=xterm-256color && exec tmux export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$home/.rvm/scripts/rvm" 

-1. Set up my history file to ignore duplicates and be much larger than the default.
-2. Color option for ls depending on if you are using linux or OSX
-3. Function "md" to make and cd into a directory with one command
-4. Find the current git branch if in a git repo and...
-5. -9. Define an awesome PS1 prompt, as in 20:00:43 durrantm Castle2012 /hom/durrantm/Dropnot/_/rails_apps/linker master \n $ _
-10. Improved PS2 prompt
-11. Set vi as the editor at the command line
-12. Set vi as the default editor
-13. execute my .bash_aliases file if it exists
-14. Execute my git tab completion script (for remotes and branches) if it exists.
-15. Execute autojump if it exists
-16. Allow cd'ing without typing the cd part if the bash version >= 4
-17. Execute a bash completion script if it exists
-18. Use TMUX if it is present
-19. Add rvm to my PATH
-20. Use rvm if it exists.

I've made this portable so that it works on any of my linux or OSX machines without customization - hence a number of tests for presence are done before using certain functions and other scripts.

This also makes it easier to use the entire file immediately on a new machine without having issues that affect opening a new terminal window.

added 5 characters in body
Source Link
Michael Durrant
  • 43.7k
  • 73
  • 176
  • 238

The purpose of a .bashrc file is to provide a place where you can set up variables, functions and aliases, define your (PS1) prompt and define other settings that you want to use every start you open a new terminal window.

It works by being run each time you open up a new terminal, window or pane.

You can see mine here:![enter image description here][1]

Explanation:

-1. Set up my history file to ignore duplicates and be much larger than the default.
-2. Color option for ls depending on if you are using linux or OSX
-3. Function "md" to make and cd into a directory with one command
-4. Find the current git branch if in a git repo and...
-5. -9. Define an awesome PS1 prompt, as in ![enter image description here][2]
-10. Improved PS2 prompt
-11. Set vi as the editor at the command line
-12. Set vi as the default editor
-13. execute my 1.bash_aliases1.bash_aliases file if it exists
-14. Execute my git tab completion script (for remotes and branches) if it exists.
-15. Execute autojump if it exists
-16. Allow cd'ing without typing the cd part if the bash version >= 4
-17. Execute a bash completion script if it exists
-18. Use TMUX if it is present
-19. Add rvm to my PATH
-20. Use rvm if it exists.

I've made this portable so that it works on any of my linux or OSX machines without customization - hence a number of tests for presence are done before using certain functions and other scripts. This also makes it easier to use the entire file immediately on a new machine without having issues that affect opening a new terminal window. [1]: https://i.sstatic.net/DQnGN.png [2]: https://i.sstatic.net/slR41.png

The purpose of a .bashrc file is to provide a place where you can set up variables, functions and aliases, define your (PS1) prompt and define other settings that you want to use every start you open a new terminal window.

It works by being run each time you open up a new terminal, window or pane.

You can see mine here:![enter image description here][1]

Explanation:

-1. Set up my history file to ignore duplicates and be much larger than the default.
-2. Color option for ls depending on if you are using linux or OSX
-3. Function "md" to make and cd into a directory with one command
-4. Find the current git branch if in a git repo and...
-5. -9. Define an awesome PS1 prompt, as in ![enter image description here][2]
-10. Improved PS2 prompt
-11. Set vi as the editor at the command line
-12. Set vi as the default editor
-13. execute my 1.bash_aliases1 if it exists
-14. Execute my git tab completion script (for remotes and branches) if it exists.
-15. Execute autojump if it exists
-16. Allow cd'ing without typing the cd part if the bash version >= 4
-17. Execute a bash completion script if it exists
-18. Use TMUX if it is present
-19. Add rvm to my PATH
-20. Use rvm if it exists.

I've made this portable so that it works on any of my linux or OSX machines without customization - hence a number of tests for presence are done before using certain functions and other scripts. This also makes it easier to use the entire file immediately on a new machine without having issues that affect opening a new terminal window. [1]: https://i.sstatic.net/DQnGN.png [2]: https://i.sstatic.net/slR41.png

The purpose of a .bashrc file is to provide a place where you can set up variables, functions and aliases, define your (PS1) prompt and define other settings that you want to use every start you open a new terminal window.

It works by being run each time you open up a new terminal, window or pane.

You can see mine here:![enter image description here][1]

Explanation:

-1. Set up my history file to ignore duplicates and be much larger than the default.
-2. Color option for ls depending on if you are using linux or OSX
-3. Function "md" to make and cd into a directory with one command
-4. Find the current git branch if in a git repo and...
-5. -9. Define an awesome PS1 prompt, as in ![enter image description here][2]
-10. Improved PS2 prompt
-11. Set vi as the editor at the command line
-12. Set vi as the default editor
-13. execute my .bash_aliases file if it exists
-14. Execute my git tab completion script (for remotes and branches) if it exists.
-15. Execute autojump if it exists
-16. Allow cd'ing without typing the cd part if the bash version >= 4
-17. Execute a bash completion script if it exists
-18. Use TMUX if it is present
-19. Add rvm to my PATH
-20. Use rvm if it exists.

I've made this portable so that it works on any of my linux or OSX machines without customization - hence a number of tests for presence are done before using certain functions and other scripts. This also makes it easier to use the entire file immediately on a new machine without having issues that affect opening a new terminal window. [1]: https://i.sstatic.net/DQnGN.png [2]: https://i.sstatic.net/slR41.png

added 48 characters in body
Source Link
Michael Durrant
  • 43.7k
  • 73
  • 176
  • 238
Loading
added 888 characters in body
Source Link
Michael Durrant
  • 43.7k
  • 73
  • 176
  • 238
Loading
added 888 characters in body
Source Link
Michael Durrant
  • 43.7k
  • 73
  • 176
  • 238
Loading
Source Link
Michael Durrant
  • 43.7k
  • 73
  • 176
  • 238
Loading