Skip to content

Instantly share code, notes, and snippets.

@Ashkanph
Last active February 19, 2020 09:20
Show Gist options
  • Save Ashkanph/65bd84ad4a82ec822206ecc08ad09b9e to your computer and use it in GitHub Desktop.
Save Ashkanph/65bd84ad4a82ec822206ecc08ad09b9e to your computer and use it in GitHub Desktop.
My .bashrc (Ubuntu)
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the pac[[ -s /home/ashkan/.autojump/etc/profile.d/autojump.sh ]] && source /home/ashkan/.autojump/etc/profile.d/autojump.sh
# BASE16_SHELL=$HOME/.config/base16-shell/
# [ -n "$PS1" ] && [ -s $BASE16_SHELL/profile_helper.sh ] && eval "$($BASE16_SHELL/profile_helper.sh)"
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
export PS1="\[\e[33m\]\u\[\e[m\]\[\e[34m\]@\[\e[m\]\[\e[36m\]\h\[\e[m\]\[\e[34m\]:\[\e[m\]\[\e[35m\]\W\[\e[m\]\[\e[34m\]\\$\[\e[m\]\[\e[34m\]>\[\e[m\] "
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
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
# some more ls aliases
alias ll='ls -alF --time-style=iso'
alias la='ls -A'
alias l='ls -CF'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
. /etc/bash_completion
fi
PATH=$PATH:/opt/bin:~/opt
#export PATH=${PATH}:/Development/android-sdk/platform-tools:/Development/android-sdk/tools
export PATH
##################
### MY ALIASES ###
##################
function mkcd() {
mkdir -p "$1"
cd "$1"
}
alias ..='cd ..'
alias ...='cd ../..'
alias cdl="cd ~/Downloads"
alias cdw="cd ~/workspace"
alias cdoc="cd ~/Documents"
alias cls="clear"
#alias usmb="amsmb.py -u"
#alias m10="amsmb.py 10"
alias tmux="TERM=xterm-256color tmux"
alias tmuxk="TERM=konsole-256-color tmux"
# alias j="jobs"
alias lsps='ps aux | grep'
alias reload='source ~/.bashrc'
# git command autocompletion script
# https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
test -f ~/.git-completion.bash && . $_
#test -f ~/.git-prompt.sh && . $_
#export PATH=$PATH:$HOME/.git-radar
# git commamands simplified
alias glg='git log --date-order --graph --format="%C(green)%h%Creset %C(blue bold)%ar%Creset %C(red bold)%d%Creset%s"'
alias glgd='git log --date-order --graph --date=short --format="%C(green)%h%Creset %C(blue bold)%cd%Creset %C(red bold)%d%Creset%s"'
alias glga='git log --date-order --graph --format="%C(green)%h%Creset
%C(yellow)%an %ae %Creset %C(blue bold)%ar%Creset %C(red bold)%d%Creset%s"'
alias glg2='git log --date-order --all --graph --format="%C(green)%h%Creset %C(blue bold)%aD%Creset %C(red bold)%d%Creset%s"'
alias glb='glg --branches'
alias gs='git status'
alias ga='git add'
alias gb='git branch'
alias gchk='git checkout'
alias gremotes='git remote -v'
alias gbranches='git branch -a'
alias gcomm='git commit'
alias gdiff='git diff'
alias gdiffs='git diff --staged'
alias gpush='git push'
alias gfetch='git fetch'
alias gmerge='git merge'
alias gsub='git submodule'
# git alias autocompletion
__git_complete gchk _git_checkout
__git_complete ga _git_add
__git_complete gb _git_branch
__git_complete gpush _git_push
__git_complete gfetch _git_fetch
__git_complete gmerge _git_merge
__git_complete gcomm _git_commit
# Aliases added by Ashkan -------------------------------
alias acal="echo '';echo '';jcal -3 -e; cal -3;echo '';echo '';tput setaf 213;date '+%A %Y/%B/%d %H:%M:%S%n';tput setaf 202;jdate '+%A %Y/%B/%d %H:%M:%S%n';"
# End of aliases added by Ashkan ------------------------
# proxy tunnel
alias ajvpn='ssh -ND 9999 -p 8022 -v support@ajserver'
alias pA='sshuttle --dns -vr ajserver -X ~/.config/sshuttle.exclude.txt 0/0'
alias rsyncCopy='/usr/local/bin/rsync -rvih --checksum --info=progress2'
alias rsyncSync='/usr/local/bin/rsync -rvih --checksum --delete --info=progress2'
alias rsyncSimulate='/usr/local/bin/rsync -rvih --checksum --delete --dry-run'
alias isodate='date +%Y%m%d-%H%M%S'
#alias chexdump=$'hexdump -v -e \'8/1 "0x%02x, " "\\n"\''
alias myip="dig +short myip.opendns.com @resolver1.opendns.com"
# jump (fuzzy dir autojump), Linux / OSX
[[ -s /etc/profile.d/autojump.sh ]] && . /etc/profile.d/autojump.sh
# eval "$(autojump shell bash)"
## Set the number of commands to remember in the command history ##
#HISTFILESIZE=1000000
#HISTSIZE=2000
## Append it ##
#shopt -s histappend
######
# Controlling how commands are saved on the history file ##
# ignoreboth means: ##
# a) Command which begin with a space character are not saved in the history list ##
# b) Command matching the previous history entry to not be saved (avoid duplicate commands) ##
######
HISTCONTROL=ignoreboth
## set vi editing mode
set editing-mode vi
set keymap vi-command
## coloring
# Base16 Shell
BASE16_SHELL="$HOME/.config/base16-shell/scripts/base16-default.dark.sh"
# [[ -s $BASE16_SHELL ]] && source $BASE16_SHELL
function colo() {
BASE='~/.config/base16-gnome-terminal/base16'
if [[ $2 == light ]]; then
BASE16_SHELL="$BASE-$1.light.sh"
else
BASE16_SHELL="$BASE-$1.dark.sh"
fi
eval $BASE16_SHELL
}
function use_system_clang() {
export CC=/usr/bin/clang-3.8
export CXX=/usr/bin/clang++-3.8
}
alias vboxls="VBoxManage list vms"
alias vboxlr="VBoxManage list runningvms"
alias vboxctl="VBoxManage controlvm"
function vboxstart() {
VBoxManage startvm $1 --type headless
}
function vboxstop() {
VBoxManage controlvm $1 poweroff
}
#Ashkan added this for node permission problem
#export NVM_DIR="$HOME/.nvm"
#[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
#[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
### Ashkan added - prompt coloring
# get current branch in git repo
function 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
}
# get current status of git repo
function 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=''
if [ "${renamed}" == "0" ]; then
bits=">${bits}"
fi
if [ "${ahead}" == "0" ]; then
bits="*${bits}"
fi
if [ "${newfile}" == "0" ]; then
bits="+${bits}"
fi
if [ "${untracked}" == "0" ]; then
bits="?${bits}"
fi
if [ "${deleted}" == "0" ]; then
bits="x${bits}"
fi
if [ "${dirty}" == "0" ]; then
bits="!${bits}"
fi
if [ ! "${bits}" == "" ]; then
echo " ${bits}"
else
echo ""
fi
}
# prompt coloring
export PS1="\[\e[33m\]\t\[\e[m\]-\[\e[31m\]\\$\[\e[m\]\[\e[36m\]\W\[\e[m\]\[\e[35m\]\`parse_git_branch\`\[\e[m\] "
### Ashkan added - end of prompt coloring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment