Created
December 28, 2018 07:55
-
-
Save stephan-buckmaster/3b1a3f5eb99926e988e6ca20b0b56510 to your computer and use it in GitHub Desktop.
Bash extensions history/git/misc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Couple of bash extensions. Place at end of ~/.bashrc | |
# If not running interactively, don't do anything | |
[ -z "$PS1" ] && return | |
# don't put duplicate lines in the history. | |
export HISTCONTROL=ignoredups | |
# ... and ignore same sucessive entries. | |
export HISTSIZE=5000 | |
export HISTTIMEFORMAT='%Y:%m:%d %H:%M ' | |
# check the window size after each command and, if necessary, | |
# update the values of LINES and COLUMNS. | |
shopt -s checkwinsize | |
alias more='less ' | |
unset color_prompt force_color_prompt | |
function get_git_branch() { | |
git_branch=`git branch 2>/dev/null|grep '^*' | colrm 1 2` | |
if [ "$git_branch" != "" ] ; then | |
commit=`git rev-parse --short HEAD 2>/dev/null` | |
echo "(GIT $git_branch@$commit)" | |
fi | |
} | |
export PS1="\u@\h \w \[\e[1;35m\]\$(get_git_branch)\[\e[0m\]\$ " | |
case "$TERM" in | |
xterm*|rxvt*|screen*) | |
PROMPT_COMMAND='(echo -n `pwd` ; echo -n `get_git_branch`; echo -n " @" ; history 1) >> /${HOME}/.bash-combined-historic; echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"' | |
;; | |
*) | |
;; | |
esac | |
function hist_all() { | |
grep -a "$1" ~/.bash-combined-historic | |
} | |
function hist() { | |
hist_all "$1" | tail -10 | |
} | |
function hist_today() { | |
hist_all | grep `date +%Y:%m:%d` | |
} | |
function lh() { | |
ls -l -t "$@" | head | |
} | |
alias rm='rm -i' | |
alias mv='mv -i' | |
alias cp='cp -i' | |
alias j='jobs' | |
alias hs='history | tail -20 ' | |
export EDITOR=vi | |
function random_s() { | |
keylength=$1 | |
if [ "$keylength" = "" ] ; then | |
keylength=15 | |
fi | |
ruby -e "require 'openssl'; keylength=$keylength; puts [OpenSSL::Random::random_bytes(keylength)].pack('m')[0,keylength].tr( '/+', '_~' )" | |
} | |
# Clipboard | |
alias xc='xclip -i -selection clipboard ' | |
alias xp='xclip -o -selection clipboard ' | |
alias xpn=' ( xclip -o -selection clipboard ; echo )' | |
# More git, see git in bash-history above as well. | |
alias gst='git status ' | |
alias gd='git diff ' | |
alias gst='git status -s' | |
alias gsl='git status ' | |
alias gdl="gsl | ag -A 15 'Changes not staged for commit:'" | |
function glh() { | |
git log --pretty=oneline $* | head | |
} | |
function gll() { | |
git log --pretty=oneline $* | |
} | |
function glld() { | |
if [ -z "$arg" ] | |
echo "Using $arg ..." | |
git log --date=iso --pretty=format:'%<(19,trunc)%ad %<(12,trunc)%aN %h %<(120,trunc)%s' | |
then | |
git log --follow --date=iso --pretty=format:'%<(19,trunc)%ad %<(12,trunc)%aN %h %<(120,trunc)%s' $arg | |
fi | |
} | |
function glld1() { | |
glld $* | head -1 | |
echo | |
} | |
function glld2() { | |
glld $* | head -2 | |
echo | |
} | |
function glld5() { | |
glld $* | head -5 | |
echo | |
} | |
function glld10() { | |
glld $* | head -10 | |
echo | |
} | |
function glld20() { | |
glld $* | head -20 | |
echo | |
} | |
function glld30() { | |
glld $* | head -30 | |
echo | |
} | |
function glld40() { | |
glld $* | head -40 | |
echo | |
} | |
function glld50() { | |
glld $* | head -50 | |
echo | |
} | |
function glldf() { | |
glld | grep "$@" | |
} | |
alias gdc='git diff --cached ' | |
echo "Loaded bashrc V 1.1 ...." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment