Skip to content

Instantly share code, notes, and snippets.

@willpower232 willpower232/bash.bashrc
Last active Aug 14, 2019

Embed
What would you like to do?
Inspired by this https://www.cyberciti.biz/tips/bash-aliases-mac-centos-linux-unix.html I am making my .bashrc portable.
# git clone git@github.com:jimeh/git-aware-prompt ~/.bash/git-aware-prompt
git_branch=
git_dirty=
if [ -d ~/.bash/git-aware-prompt ]; then
source ~/.bash/git-aware-prompt/prompt.sh
fi
# 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
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
if [ "$EUID" -ne 0 ]; then
PS1='${debian_chroot:+($debian_chroot)}($SHLVL) \u@\h {\A} \e[32m[\w] \e[1;34m$git_branch\e[31m$git_dirty\e[0m\n$ '
else
PS1='${debian_chroot:+($debian_chroot)}($SHLVL) \u@\h {\A} \e[31m[\w]\e[0m\n# '
fi
# some terminals need to know the previous non-printing (colour changing) characters have finished
# otherwise backspace can delete a prompt because it doesn't know where to start
# ref https://unix.stackexchange.com/a/150493
#PS1="$PS1\]"
else
if [ "$EUID" -ne 0 ]; then
PS1='${debian_chroot:+($debian_chroot)}($SHLVL) u@h {A} [w] $git_branch$git_dirty\n$ '
else
PS1='${debian_chroot:+($debian_chroot)}($SHLVL) u@h {A} [w]\n# '
fi
fi
unset color_prompt force_color_prompt
# not sure what this bit does
#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
alias nano='nano --nowrap --smooth -T 4'
alias plz='sudo '
alias dammit='sudo !!'
# stop yourself from breaking the server by accident
alias mv='mv -i'
alias cp='cp -i'
alias ln='ln -i'
alias rm='rm -I --preserve-root'
alias chown='chown --preserve-root'
alias chmod='chmod --preserve-root'
alias chgrp='chgrp --preserve-root'
function findinfiles() { find ./ -type f -print0 | xargs -0 grep -i "$1"; }
function findinphpfiles() { find ./ -type f -name "*.php" -print0 | xargs -0 grep -i "$1"; }
complete -W "$(echo $(grep '^ssh ' ~/.bash_history | sort -u | sed 's/^ssh //'))" ssh
if [ "$(uname)" == "Darwin" ]; then
# got pbcopy
:
elif grep -q Microsoft /proc/version; then
# route error to /dev/null because thanks microsoft
alias pbcopy='clip.exe > /dev/null 2>&1'
else
# install xclip through apt first
alias pbcopy='xclip -selection clipboard'
alias pbpaste='xclip -selection clipboard -o'
fi
# thanks @jamesdoc
alias e-thumbsup="printf \"πŸ‘\" | pbcopy && echo \"πŸ‘ copied to the clipboard\""
alias e-pointup="printf \"πŸ‘†\" | pbcopy && echo \"πŸ‘† copied to the clipboard\""
alias e-pointdown="printf \"πŸ‘‡\" | pbcopy && echo \"πŸ‘‡ copied to the clipboard\""
alias e-rocket="printf \"πŸš€\" | pbcopy && echo \"πŸš€ copied to the clipboard\""
alias e-tada="printf \"πŸŽ‰\" | pbcopy && echo \"πŸŽ‰ copied to the clipboard\""
alias e-lightning="printf \"⚑\" | pbcopy && echo \"⚑ copied to the clipboard\""
alias shruggie="printf \"Β―\_(ツ)_/Β―\" | pbcopy && echo \"Β―\_(ツ)_/Β― copied to clipboard\""
# ref https://github.com/dannyfritz/commit-message-emoji
alias gc-InitialCommit="printf \"πŸŽ‰\" | pbcopy && pbpaste && echo \"\""
alias gc-VersionTag="printf \"πŸ”–\" | pbcopy && pbpaste && echo \"\""
alias gc-NewFeature="printf \"✨\" | pbcopy && pbpaste && echo \"\""
alias gc-Bugfix="printf \"πŸ›\" | pbcopy && pbpaste && echo \"\""
alias gc-SecurityFix="printf \"πŸ”’\" | pbcopy && pbpaste && echo \"\""
alias gc-Metadata="printf \"πŸ“‡\" | pbcopy && pbpaste && echo \"\""
alias gc-Refactoring="printf \"♻️\" | pbcopy && pbpaste && echo \"\""
alias gc-Documentation="printf \"πŸ“š\" | pbcopy && pbpaste && echo \"\""
alias gc-Internationalization="printf \"🌐\" | pbcopy && pbpaste && echo \"\""
alias gc-Accessibility="printf \"β™Ώ\" | pbcopy && pbpaste && echo \"\""
alias gc-Performance="printf \"🐎\" | pbcopy && pbpaste && echo \"\""
alias gc-Cosmetic="printf \"🎨\" | pbcopy && pbpaste && echo \"\""
alias gc-Tooling="printf \"πŸ”§\" | pbcopy && pbpaste && echo \"\""
alias gc-Tests="printf \"🚨\" | pbcopy && pbpaste && echo \"\""
alias gc-Deprecation="printf \"πŸ’©\" | pbcopy && pbpaste && echo \"\""
alias gc-Removal="printf \"πŸ—‘οΈ\" | pbcopy && pbpaste && echo \"\""
alias gc-WorkInProgress="printf \"🚧\" | pbcopy && pbpaste && echo \"\""
alias gc-Deforestation="printf \"🌲\" | pbcopy && pbpaste && echo \"\""
if [ -x /usr/bin/termsaver ]; then
alias tsm="termsaver matrix"
fi
if [ -x /usr/bin/cmatrix ]; then
alias etm="cmatrix -a -b -s -C cyan"
fi
# this is needed to enter the passphrase when attempting to gpg-sign git commits
#export GPG_TTY=$(tty)
# if you're on WSL you may want to see information from MOTD such as pending updates
#sudo run-parts /etc/update-motd.d/
# if you're on WSL and you want to mount network shares
#sudo mount -a
# if you want to hide commands from your bash history with space and don't include duplicates
# you need this but it may already be set elsewhere
#HISTCONTROL=ignoreboth
# Debian doesn't have bash-completion by default so you need to apt install bash-completion and add the below
#if [ -f /etc/bash_completion ]; then
# . /etc/bash_completion
#fi
. /etc/bash.bashrc
# https://askubuntu.com/a/22043
alias sudo='sudo '
# lol
alias nano='vim'
function git {
if [[ "$1" == "clone" && "$@" != *"--help"* ]]; then
shift 1
command git clone --config core.filemode=false "$@"
elif [[ "$1" == "branch" && "$@" != *"--help"* ]]; then
shift 1
command git checkout -b "$@"
else
command git "$@"
fi
}
function docker {
if [[ "$1" == "stop-and-rm" ]]; then
shift 1
command docker stop "$@"
command docker rm "$@"
else
command docker "$@"
fi
}
# aliases let you put things after the command if you want
# i.e. get familiar with the flags but type way fewer characters
# e.g. dc build --no-cache -> rebuild the images without cache
# e.g. dcu -d -> dc up and detach/background it
# e.g. dce app bash -> dc exec bash in the service
# e.g. dcd -v -> dc down and clear volumes too
alias dc=docker-compose
alias dcd="docker-compose down"
alias dcu="docker-compose up"
alias dce="docker-compose exec"
# persisting the changes you've made to your container
# is a terrible idea and yet here it is
function dcc {
if [ "$#" -ne "1" ]; then
echo "Precisely one argument required"
return 1
fi
CONTAINER=$(dc images | grep "_$1 " | awk '{print $1;}')
TAGNAME=$(dc images | grep "_app " | awk '{print $2;}')
TAGVERSION=$(dc images | grep "_app " | awk '{print $3;}')
if [ "$CONTAINER" = "" ] || [ "$TAGNAME" = "" ] || [ "$TAGVERSION" = "" ]; then
echo "Unable to figure out what to do"
return 1
fi
COMMAND="docker commit $CONTAINER $TAGNAME:$TAGVERSION"
echo $COMMAND
eval $COMMAND
}
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
@willpower232

This comment has been minimized.

Copy link
Owner Author

commented Dec 11, 2016

Ideally you would include this as part of your main .bashrc but it is possible to include it for your session so as to not disrupt other people using the same login using either of the following:

  • local copy $ . <(cat my.bashrc)
  • remote copy $ . <(curl -Ss https://onlinecopysomewhere.com)
  • remote copy with shortcut domain $ . <(curl -LSs https://handyshortcutdomain.com)

Easy install system-wide (you may want to back up the original file as it will get overwritten)
$ curl -LSs https://handyshortcutdomain.com | sudo tee /etc/bash.bashrc > /dev/null

Don't forget your ~/.profile if you SSH into your system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.