summaryrefslogtreecommitdiff
path: root/mkshrc
blob: d5280963faa406e5c4793681503a9f212544b32d (plain)
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
#!/bin/mksh
case $- in
    *i*) ;;
      *) return;;
esac

export VIMINIT="source ~/.config/vim/vimrc"
export NVIMINIT="source ~/.config/vim/vimrc"

HISTFILE="$HOME/.mksh_history"
HISTSIZE=5000

if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    alias dir='dir --color=auto'
    alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

[ -f ~/.sh_aliases ] && . ~/.sh_aliases

# parse the current branch and status of git to be added to the prompt
parse_git_branch() {
        BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
        if [ ! "${BRANCH}" == "" ]
        then
                STAT=`parse_git_dirty`
                echo " [${BRANCH}${STAT}]"
        else
                echo ""
        fi
}

parse_git_dirty() {
        status=`git status 2>&1 | tee`
        dirty=`echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?"`
        untracked=`echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?"`
        ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"`
        newfile=`echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?"`
        renamed=`echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?"`
        deleted=`echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?"`
        bits=''
        [ "${renamed}" == "0" ] && bits=">${bits}"
        [ "${ahead}" == "0" ] && bits="*${bits}"
        [ "${newfile}" == "0" ] && bits="+${bits}"
        [ "${untracked}" == "0" ] && bits="?${bits}"
        [ "${deleted}" == "0" ] && bits="x${bits}"
        [ "${dirty}" == "0" ] && bits="!${bits}"
        [ ! "${bits}" == "" ] && echo " ${bits}" || echo ""
}

bind '^L=clear-screen'

export PS1="\${PWD/#\$HOME/\~}\`parse_git_branch\` > "