about summary refs log blame commit diff stats
path: root/core/bash.html
blob: 353d7df0a3d876916fb6b8a93c481229854d7056 (plain) (tree)
1
2
3
4
5
6
7
8
9



                              
                                  

           
                                              
 
                                      
 
                                                           




              
                                                  















                                                                      
                                              



                                     





                                                                                   
                                             
 
                                    



























































                                                                                                  
                                                        
 
                                          












                                          
                                              
           
                                          
                          
                





                                                                                            
<!DOCTYPE html>
<html dir="ltr" lang="en">
    <head>
        <meta charset='utf-8'>
        <title>2.5.2. Bash</title>
    </head>
    <body>
        <a href="index.html">Core OS Index</a>

        <h1 id="bash">2.5.2. Bash</h1>

        <p>Just to be sure, setup bash as default login;<p>

        <pre>
        $ chsh
        </pre>

        <p>Description of configuration files;</p>

        <dl>
            <dt>~/.bash_profile</dt>
            <dd>Minimal file that just load .profile and then .bashrc,
            in this order.</dd>

            <dt>~/.profile<dt>
            <dd>Not specifically related to bash, such as
            environment variables (PATH). Only for login shells (sh)
            or graphical applications.</dd>

            <dt>~/.bashrc</dt>
            <dd>Related to interactive command line, such as bash
            alias, editor.</dd>
        </dl>

        <h2 id="profile">2.5.2.1. Profile</h2>

        <p>Example of ~/.profile;</p>

        <pre>
        PATH=~/.composer/vendor/bin:${PATH}

        export GPG_AGENT_INFO  # the env file does not contain the export statement
        export SSH_AUTH_SOCK   # enable gpg-agent for ssh
        </pre>

        <h2 id="bashrc">2.5.2.2. Bash RC</h2>

        <p>Example of ~/.bashrc;</p>

        <pre>
        # If not running interactively, don't do anything
        case $- in
                *i*) ;;
                *) return;;
        esac


        # check the window size after each command and, if necessary,
        # update the values of LINES and COLUMNS.
        shopt -s checkwinsize


        # don't put duplicate lines or lines starting with space in the history.
        # See bash(1) for more options
        HISTCONTROL=ignoreboth

        # append to the history file, don't overwrite it
        shopt -s histappend

        # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
        HISTSIZE=1000
        HISTFILESIZE=2000

        alias tmux="tmux -2"

        alias rm='rm -i'
        #alias cp='cp -i'
        alias mv='mv -i'
        # Prevents accidentally clobbering files.
        alias mkdir='mkdir -p'

        alias h='history'
        alias j='jobs -l'
        alias which='type -a'
        alias ..='cd ..'

        # Generate a password
        genpasswd () {
            local l=$1
            [ "$l" == "" ] && l=20
            tr -dc A-Za-z0-9_ &lt; /dev/urandom | head -c ${l} | xargs
        }

        # Git graph log
        glog () {
            git log --graph --abbrev-commit --decorate --date=relative --all
        }

        if [[ -z "$TMUX" ]] ;then
            ID="`tmux ls | grep -vm1 attached | cut -d: -f1`" # get the id of a deattached session
            if [[ -z "$ID" ]] ;then # if not available create a new one
                tmux new-session
            else
                tmux attach-session -t "$ID" # if available attach to it
            fi
        fi
        </pre>

        <h2 id="bash_profile">2.5.2.3. Bash profile</h2>

        <p>Example of ~/.bash_profile;</p>

        <pre>
                #!/bin/bash
                if [ -f ~/.profile ]; then
                   source ~/.profile
                fi

                if [ -f ~/.bashrc ]; then
                   source ~/.bashrc
                fi
        </pre>


        <a href="index.html">Core OS Index</a>
        <p>
        This is part of the c9-doc Manual.
        Copyright (C) 2016
        c9 team.
        See the file <a href="../fdl-1.3-standalone.html">Gnu Free Documentation License</a>
        for copying conditions.</p>


    </body>
</html>