Created
July 22, 2018 04:33
-
-
Save pegasuspect/fe93a58c967617f7f390c5ca7d9ac334 to your computer and use it in GitHub Desktop.
My Bash Profile file, for Mac Terminal
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
# If not running interactively, don't do anything | |
case $- in | |
*i*) ;; | |
*) return;; | |
esac | |
print_greeting() | |
{ | |
if [[ -f ~/.shell.greeting ]]; then | |
# Credits to: | |
# http://patorjk.com/software/taag/#p=display&h=0&v=0&f=Fraktur&t=Developer | |
cat ~/.shell.greeting | |
fi | |
return | |
} | |
print_greeting | |
backup_terminal_configuration() | |
{ | |
if [[ -d ~/.yandex.disk ]]; then | |
if [[ ! -d ~/yandexDir ]]; then | |
echo "Error: Create link to your yandex shared folder as ~/yandexDir" && return | |
elif [[ ! -d ~/yandexDir/Downloads/mac_bash_scripts ]]; then | |
echo "Error: Create a folder to yandex disk as ~/yandexDir/Downloads/mac_bash_scripts" && return | |
fi | |
cp ~/.bash_profile ~/yandexDir/Downloads/mac_bash_scripts/.bash_profile | |
cp ~/.bash_history ~/yandexDir/Downloads/mac_bash_scripts/.bash_history | |
cp ~/.bash_aliases ~/yandexDir/Downloads/mac_bash_scripts/.bash_aliases | |
cp ~/.shell.greeting ~/yandexDir/Downloads/mac_bash_scripts/.shell.greeting | |
cp ~/.short.pwd.py ~/yandexDir/Downloads/mac_bash_scripts/.short.pwd.py | |
else | |
echo "Yandex Disk is not supported on this mac." | |
fi | |
return | |
} | |
backup_terminal_configuration | |
# this was meeant to be an alias but since it has to run depending; | |
# on the current directory, it has to be a function. | |
commitsOnGitHub(){ | |
if [[ ! -d '.git' ]]; then | |
echo Not a git repository. | |
elif type xdg-open &> /dev/null; then | |
# ubuntu | |
xdg-open $(git config -l | grep url | cut -d= -f2 | cut -d. -f1,2)/commits/$(git branch | grep \* | cut -d' ' -f2) | |
elif type open &> /dev/null; then | |
# mac | |
open $(git config -l | grep url | cut -d= -f2 | cut -d. -f1,2)/commits/$(git branch | grep \* | cut -d' ' -f2) | |
fi | |
} | |
stash(){ | |
stash_cut(){ | |
git stash list | cut -d: -f2,3 | |
} | |
if [[ ! -d '.git' ]]; then | |
echo Not a git repository. | |
elif [[ $1 = "+=" && ! -z $2 && ! -z $3 ]]; then | |
git stash push -m $2 $3 | |
elif [[ $1 = "+=" && ! -z $2 ]]; then | |
git stash push -m "$2" | |
elif [[ $1 = "-=" && ! -z $2 ]]; then | |
git stash pop $(stash_cut | grep $2 | head -1 | cut -d: -f1 | tr -d ' ') | |
elif [[ $1 = "list" && ! -z $2 ]]; then | |
stash_index=$(stash_cut | grep "$2" | head -1 | cut -d: -f1 | tr -d ' ') | |
if [[ -z $stash_index ]]; then | |
return 0 | |
fi | |
stash_cut | grep "$2" --color=auto | |
stash_cut | grep "$2" --color=auto | tr -C "*" "-" | |
echo | |
git stash show $stash_index | |
elif [[ $1 = "list" ]]; then | |
stash_cut | |
else | |
echo " | |
Git Stash with Keywords | |
Description: Using git-stash with keywords instead of indexes. | |
Usage: $0 [+= <keyword> [-p <path/to/file>]] [-= <keyword>] [list [<part-of-the-keyword>]] | |
$0 += <keyword> | |
To stash your all of your changes. | |
$0 += <keyword> [-p <path/to/file>] | |
To stash spesific file(s) with stash. | |
$0 -= <keyword> | |
Extract a stash and remove it from the list. | |
$0 list | |
List the stash. | |
$0 list <part-of-the-keyword> | |
List what changes extracting a stash will make. | |
" | |
fi | |
unset -f stash_cut | |
} | |
# set histfile for mac, and disable session histories | |
SHELL_SESSION_HISTORY=0 | |
HISTFILE="$HOME/.bash_history" | |
HISTSIZE=1000000 | |
HISTFILESIZE=1000000000 | |
# set a fancy prompt (non-color, unless we know we "want" color) | |
case "$TERM" in | |
xterm-color|*-256color) 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 | |
force_color_prompt=yes | |
if [ -n "$force_color_prompt" ]; then | |
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then | |
# We have color support; assume it's compliant with Ecma-48 | |
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such | |
# a case would tend to support setf rather than setaf.) | |
color_prompt=yes | |
else | |
color_prompt= | |
fi | |
fi | |
if [ "$color_prompt" = yes ]; then | |
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' | |
else | |
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' | |
fi | |
unset color_prompt force_color_prompt | |
# enable color support of ls and also add handy aliases | |
# Run the following installations on MAC: | |
# brew install coreutils | |
# mkdir ~/.dircolors | |
# git clone https://github.com/gibbling666/dircolors.git ~/.dircolors | |
# mkdir ~/.dircolorsSolarized | |
# git clone https://github.com/seebi/dircolors-solarized.git ~/.dircolorsSolarized | |
if [ -x /usr/local/Cellar/coreutils/8.29/libexec/gnubin/dircolors ] || [ -x /usr/local/bin/gdircolors ]; then | |
test -r ~/.dircolors && eval "$(gdircolors -b ~/.dircolorsSolarized/dircolors.256dark)" || | |
eval "$(gdircolors -b ~/.dircolors/dircolors.256dark)" || eval "$(gdircolors -b)" | |
alias ls='gls --color=auto' | |
alias dls='command ls' | |
alias grep='grep --color=auto' | |
alias fgrep='fgrep --color=auto' | |
alias egrep='egrep --color=auto' | |
fi | |
# colored GCC warnings and errors | |
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' | |
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). | |
# | |
# Install completions on MAC: | |
# brew install bash-completion | |
if ! shopt -oq posix; then | |
if [ -f /usr/share/bash-completion/bash_completion ]; then | |
. /usr/share/bash-completion/bash_completion | |
elif [ -f /etc/bash_completion ]; then | |
. /etc/bash_completion | |
elif [ -f /usr/local/etc/bash_completion ]; then | |
. /usr/local/etc/bash_completion | |
fi | |
fi | |
# brew install git | |
if [ -f `brew --prefix`/etc/bash_completion.d/git-completion.bash ]; then | |
. `brew --prefix`/etc/bash_completion.d/git-completion.bash | |
fi | |
export PROMPT_COMMAND='PS1="$(python ~/.short.pwd.py)"' | |
# to use simple arithmatic operations in bash install rbenv | |
# $ brew install rbenv | |
# $ = 5*6 | |
# 30 | |
# uncommet following lines | |
export PATH="$HOME/.rbenv/bin:$PATH" | |
eval "$(rbenv init -)" | |
=() { | |
echo "$(($@))" | |
} | |
# add mysql to path | |
export PATH="/usr/local/mysql/bin:$PATH" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment