~ashn/setup

6fc47ecc972b135b277d1c4730fa63b64907a4ef — ashn 1 year, 3 months ago 8e2f93a
Spring cleaning - tidy up shell dotfiles
5 files changed, 77 insertions(+), 94 deletions(-)

M dotfiles/.bashrc
D dotfiles/.env
M dotfiles/.profile
D dotfiles/.shrc
M setup-dotfiles.sh
M dotfiles/.bashrc => dotfiles/.bashrc +75 -10
@@ 1,17 1,82 @@
# Exit if Bash was not invoked interactively.
[ -z "$PS1" ] && exit 0

# Make Bash conform more closely to the POSIX standard.
set -o posix

# Exit if Bash was not invoked interactively.
[ -z "$PS1" ] && exit 0
HISTCONTROL=ignorespace
HISTSIZE=4096
HISTFILESIZE=4096
shopt -s histappend

# Shell run commands.
[ -f ~/.shrc ] && source ~/.shrc
shopt -s checkwinsize

# Bash completion.
source /etc/bash_completion 2> /dev/null

# Append to the history file, don't overwrite it.
shopt -s histappend
# Check the window size after each command and, if necessary, update the values
# of LINES and COLUMNS.
shopt -s checkwinsize
## ALIASES
alias ll='ls -alF'
alias l1='ls -a1'
alias ccc='clear;clear;clear'
alias tree='tree -n' # The -n flag always disables color.

alias now='echo `date +%R` "/" `date +%r`'
alias clock='while true; do clear; now; sleep 1; done'

alias shelve='git stash'
alias unshelve='git stash apply'

alias valgrind-mc='valgrind \
    --leak-check=yes \
    --leak-check=full \
    --show-leak-kinds=all \
    --track-origins=yes'
alias gdbt='gdb --tui'

## CUSTOM PS1
git_ps1() {
    GIT_BRANCH=$(git branch 2> /dev/null | grep '^\* ' | sed -e 's/^\* //g')
    if [ -z "${GIT_BRANCH}" ]; then
        echo ''
        return
    fi

    GIT_STATUS=$(git status 2> /dev/null | tee)
    GIT_REN=$(echo "${GIT_STATUS}" | grep '^.*renamed:')
    GIT_MOD=$(echo "${GIT_STATUS}" | grep '^.*modified:')
    GIT_DEL=$(echo "${GIT_STATUS}" | grep '^.*deleted:')
    GIT_NEW=$(echo "${GIT_STATUS}" | grep '^.*new file:')
    GIT_UNT=$(echo "${GIT_STATUS}" | grep '^Untracked files')

    GIT_STATUS_SUMMARY=''
    if [ -n "${GIT_REN}" ]; then
        GIT_STATUS_SUMMARY="${GIT_STATUS_SUMMARY}>"
    fi
    if [ -n "${GIT_MOD}" ]; then
        GIT_STATUS_SUMMARY="${GIT_STATUS_SUMMARY}!"
    fi
    if [ -n "${GIT_DEL}" ]; then
        GIT_STATUS_SUMMARY="${GIT_STATUS_SUMMARY}x"
    fi
    if [ -n "${GIT_NEW}" ]; then
        GIT_STATUS_SUMMARY="${GIT_STATUS_SUMMARY}+"
    fi
    if [ -n "${GIT_UNT}" ]; then
        GIT_STATUS_SUMMARY="${GIT_STATUS_SUMMARY}?"
    fi

    if [ ! -z "${GIT_STATUS_SUMMARY}" ]; then
        echo "[${GIT_BRANCH} ${GIT_STATUS_SUMMARY}]"
    else
        echo "[${GIT_BRANCH}]"
    fi
}
ps1() {
    if [ -z "$BASH_VERSION" ]; then
        echo "$(pwd)$ "
        return 0
    fi
    echo "\w\[\e[33m\]\`git_ps1\`\[\e[m\]\\$ "
}

export git_ps1
export PS1="$(ps1)"

D dotfiles/.env => dotfiles/.env +0 -1
@@ 1,1 0,0 @@
PATH="$PATH:$HOME/bin"

M dotfiles/.profile => dotfiles/.profile +2 -8
@@ 1,14 1,8 @@
#!/bin/sh
# .profile : Commands executed by a login using ksh or sh.
export ENV="$HOME/.shrc"
PATH="$PATH:$HOME/bin"
export PATH

if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
else
    if [ -f "$HOME/.shrc" ]; then
        . "$HOME/.shrc"
    fi
fi

D dotfiles/.shrc => dotfiles/.shrc +0 -73
@@ 1,73 0,0 @@
#!/bin/sh
# .shrc : Common sh-compatible run commands.

[ -f "$HOME/.env" ] && . "$HOME/.env"


## ALIASES
alias ll='ls -alF'
alias l1='ls -a1'
alias ccc='clear;clear;clear'
alias tree='tree -n'
alias now='echo `date +%R` "/" `date +%r`'
alias clock='while true; do clear; now; sleep 1; done'

alias shelve='git stash'
alias unshelve='git stash apply'

alias valgrind-mc='valgrind \
    --leak-check=yes \
    --leak-check=full \
    --show-leak-kinds=all \
    --track-origins=yes'
alias gdbt='gdb --tui'


## CUSTOM PS1
git_ps1() {
    GIT_BRANCH=$(git branch 2> /dev/null | grep '^\* ' | sed -e 's/^\* //g')
    if [ -z "${GIT_BRANCH}" ]; then
        echo ''
        return
    fi

    GIT_STATUS=$(git status 2> /dev/null | tee)
    GIT_REN=$(echo "${GIT_STATUS}" | grep '^.*renamed:')
    GIT_MOD=$(echo "${GIT_STATUS}" | grep '^.*modified:')
    GIT_DEL=$(echo "${GIT_STATUS}" | grep '^.*deleted:')
    GIT_NEW=$(echo "${GIT_STATUS}" | grep '^.*new file:')
    GIT_UNT=$(echo "${GIT_STATUS}" | grep '^Untracked files')

    GIT_STATUS_SUMMARY=''
    if [ -n "${GIT_REN}" ]; then
        GIT_STATUS_SUMMARY="${GIT_STATUS_SUMMARY}>"
    fi
    if [ -n "${GIT_MOD}" ]; then
        GIT_STATUS_SUMMARY="${GIT_STATUS_SUMMARY}!"
    fi
    if [ -n "${GIT_DEL}" ]; then
        GIT_STATUS_SUMMARY="${GIT_STATUS_SUMMARY}x"
    fi
    if [ -n "${GIT_NEW}" ]; then
        GIT_STATUS_SUMMARY="${GIT_STATUS_SUMMARY}+"
    fi
    if [ -n "${GIT_UNT}" ]; then
        GIT_STATUS_SUMMARY="${GIT_STATUS_SUMMARY}?"
    fi

    if [ ! -z "${GIT_STATUS_SUMMARY}" ]; then
        echo "[${GIT_BRANCH} ${GIT_STATUS_SUMMARY}]"
    else
        echo "[${GIT_BRANCH}]"
    fi
}
ps1() {
    if [ -z "$BASH_VERSION" ]; then
        echo "$(pwd)$ "
        return 0
    fi
    echo "\w\[\e[33m\]\`git_ps1\`\[\e[m\]\\$ "
}

export git_ps1
export PS1="$(ps1)"

M setup-dotfiles.sh => setup-dotfiles.sh +0 -2
@@ 3,10 3,8 @@ set -e
set -x

cp dotfiles/.bashrc ~/
cp dotfiles/.env ~/
cp dotfiles/.gitconfig ~/
cp dotfiles/.gitignore ~/
cp dotfiles/.gitmessage ~/
cp dotfiles/.profile ~/
cp dotfiles/.shrc ~/
cp dotfiles/.vimrc ~/