about summary refs log tree commit diff stats
path: root/core/bash.html
blob: f49d27ec1b86e89baaa675f1587d6a9bd3a598de (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<!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>
	export GPG_AGENT_INFO  # the env file does not contain the export statement
	export SSH_AUTH_SOCK   # enable gpg-agent for ssh

	export GPGKEY=XXXXXXXX

	# ssh-agent to ask only ounce for password
	SSH_ENV="$HOME/.ssh/environment"
	function start_agent {
	    echo "Initialising new SSH agent..."
	    /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
	    echo succeeded
	    chmod 600 "${SSH_ENV}"
	    . "${SSH_ENV}" > /dev/null
	    /usr/bin/ssh-add;
	}

	# Source SSH settings, if applicable
	if [ -f "${SSH_ENV}" ]; then
	    . "${SSH_ENV}" > /dev/null
	    #ps ${SSH_AGENT_PID} doesn't work under cywgin
	    ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
		start_agent;
	    }
	else
	    start_agent;
	fi

	# Weston
	if test -z "${XDG_RUNTIME_DIR}"; then
	    export XDG_RUNTIME_DIR=/tmp/${UID}-runtime-dir
	    if ! test -d "${XDG_RUNTIME_DIR}"; then
		mkdir "${XDG_RUNTIME_DIR}"
		chmod 0700 "${XDG_RUNTIME_DIR}"
	    fi
fi        </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 Tribu System Documentation.
        Copyright (C) 2020
        Tribu Team.
        See the file <a href="../fdl-1.3-standalone.html">Gnu Free Documentation License</a>
        for copying conditions.</p>


    </body>
</html>