| 1 | # git clone git@github.com:jimeh/git-aware-prompt ~/.bash/git-aware-prompt |
| 2 | git_branch= |
| 3 | git_dirty= |
| 4 | if [ -d ~/.bash/git-aware-prompt ]; then |
| 5 | source ~/.bash/git-aware-prompt/prompt.sh |
| 6 | fi |
| 7 | |
| 8 | # set variable identifying the chroot you work in (used in the prompt below) |
| 9 | if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then |
| 10 | debian_chroot=$(cat /etc/debian_chroot) |
| 11 | fi |
| 12 | |
| 13 | # set a fancy prompt (non-color, unless we know we "want" color) |
| 14 | case "$TERM" in |
| 15 | xterm-color) color_prompt=yes;; |
| 16 | esac |
| 17 | |
| 18 | # uncomment for a colored prompt, if the terminal has the capability; turned |
| 19 | # off by default to not distract the user: the focus in a terminal window |
| 20 | # should be on the output of commands, not on the prompt |
| 21 | force_color_prompt=yes |
| 22 | |
| 23 | if [ -n "$force_color_prompt" ]; then |
| 24 | if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then |
| 25 | # We have color support; assume it's compliant with Ecma-48 |
| 26 | # (ISO/IEC-6429). (Lack of such support is extremely rare, and such |
| 27 | # a case would tend to support setf rather than setaf.) |
| 28 | color_prompt=yes |
| 29 | else |
| 30 | color_prompt= |
| 31 | fi |
| 32 | fi |
| 33 | |
| 34 | if [ "$color_prompt" = yes ]; then |
| 35 | if [ "$EUID" -ne 0 ]; then |
| 36 | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) \u@\h {\A} \e[32m[\w] \e[1;34m$git_branch\e[31m$git_dirty\e[0m\n$ ' |
| 37 | else |
| 38 | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) \u@\h {\A} \e[31m[\w]\e[0m\n# ' |
| 39 | fi |
| 40 | |
| 41 | # some terminals need to know the previous non-printing (colour changing) characters have finished |
| 42 | # otherwise backspace can delete a prompt because it doesn't know where to start |
| 43 | # ref https://unix.stackexchange.com/a/150493 |
| 44 | #PS1="$PS1\]" |
| 45 | else |
| 46 | if [ "$EUID" -ne 0 ]; then |
| 47 | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) u@h {A} [w] $git_branch$git_dirty\n$ ' |
| 48 | else |
| 49 | PS1='${debian_chroot:+($debian_chroot)}($SHLVL) u@h {A} [w]\n# ' |
| 50 | fi |
| 51 | fi |
| 52 | unset color_prompt force_color_prompt |
| 53 | |
| 54 | # not sure what this bit does |
| 55 | #case "$TERM" in |
| 56 | # xterm*|rxvt*) |
| 57 | # PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1";; |
| 58 | # *) |
| 59 | # ;; |
| 60 | #esac |
| 61 | |
| 62 | # enable color support of ls and also add handy aliases |
| 63 | if [ -x /usr/bin/dircolors ]; then |
| 64 | test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" |
| 65 | alias ls='ls --color=auto' |
| 66 | alias dir='dir --color=auto' |
| 67 | alias vdir='vdir --color=auto' |
| 68 | |
| 69 | alias grep='grep --color=auto' |
| 70 | alias fgrep='fgrep --color=auto' |
| 71 | alias egrep='egrep --color=auto' |
| 72 | |
| 73 | # may be --color=auto in some versions... |
| 74 | alias ip='ip -c' |
| 75 | fi |
| 76 | |
| 77 | alias nano='nano --nowrap --smooth -T 4' |
| 78 | alias plz='sudo ' |
| 79 | alias dammit='sudo !!' |
| 80 | |
| 81 | # stop yourself from breaking the server by accident |
| 82 | alias mv='mv -i' |
| 83 | alias cp='cp -i' |
| 84 | alias ln='ln -i' |
| 85 | alias rm='rm -I --preserve-root' |
| 86 | alias chown='chown --preserve-root' |
| 87 | alias chmod='chmod --preserve-root' |
| 88 | alias chgrp='chgrp --preserve-root' |
| 89 | |
| 90 | function findinfiles() { find ./ -type f -print0 | xargs -0 grep -i "$1"; } |
| 91 | function findinphpfiles() { find ./ -type f -name "*.php" -print0 | xargs -0 grep -i "$1"; } |
| 92 | |
| 93 | complete -W "$(echo $(grep '^ssh ' ~/.bash_history | sort -u | sed 's/^ssh //'))" ssh |
| 94 | |
| 95 | if [ "$(uname)" == "Darwin" ]; then |
| 96 | # got pbcopy |
| 97 | : |
| 98 | elif grep -q Microsoft /proc/version; then |
| 99 | # route error to /dev/null because thanks microsoft |
| 100 | alias pbcopy='clip.exe > /dev/null 2>&1' |
| 101 | else |
| 102 | # install xclip through apt first |
| 103 | alias pbcopy='xclip -selection clipboard' |
| 104 | alias pbpaste='xclip -selection clipboard -o' |
| 105 | fi |
| 106 | |
| 107 | # thanks @jamesdoc |
| 108 | alias e-thumbsup="printf \"๐\" | pbcopy && echo \"๐ copied to the clipboard\"" |
| 109 | alias e-pointup="printf \"๐\" | pbcopy && echo \"๐ copied to the clipboard\"" |
| 110 | alias e-pointdown="printf \"๐\" | pbcopy && echo \"๐ copied to the clipboard\"" |
| 111 | alias e-rocket="printf \"๐\" | pbcopy && echo \"๐ copied to the clipboard\"" |
| 112 | alias e-tada="printf \"๐\" | pbcopy && echo \"๐ copied to the clipboard\"" |
| 113 | alias e-lightning="printf \"โก\" | pbcopy && echo \"โก copied to the clipboard\"" |
| 114 | alias shruggie="printf \"ยฏ\_(ใ)_/ยฏ\" | pbcopy && echo \"ยฏ\_(ใ)_/ยฏ copied to clipboard\"" |
| 115 | |
| 116 | # ref https://github.com/dannyfritz/commit-message-emoji |
| 117 | alias gc-InitialCommit="printf \"๐\" | pbcopy && pbpaste && echo \"\"" |
| 118 | alias gc-VersionTag="printf \"๐\" | pbcopy && pbpaste && echo \"\"" |
| 119 | alias gc-NewFeature="printf \"โจ\" | pbcopy && pbpaste && echo \"\"" |
| 120 | alias gc-Bugfix="printf \"๐\" | pbcopy && pbpaste && echo \"\"" |
| 121 | alias gc-SecurityFix="printf \"๐\" | pbcopy && pbpaste && echo \"\"" |
| 122 | alias gc-Metadata="printf \"๐\" | pbcopy && pbpaste && echo \"\"" |
| 123 | alias gc-Refactoring="printf \"โป๏ธ\" | pbcopy && pbpaste && echo \"\"" |
| 124 | alias gc-Documentation="printf \"๐\" | pbcopy && pbpaste && echo \"\"" |
| 125 | alias gc-Internationalization="printf \"๐\" | pbcopy && pbpaste && echo \"\"" |
| 126 | alias gc-Accessibility="printf \"โฟ\" | pbcopy && pbpaste && echo \"\"" |
| 127 | alias gc-Performance="printf \"๐\" | pbcopy && pbpaste && echo \"\"" |
| 128 | alias gc-Cosmetic="printf \"๐จ\" | pbcopy && pbpaste && echo \"\"" |
| 129 | alias gc-Tooling="printf \"๐ง\" | pbcopy && pbpaste && echo \"\"" |
| 130 | alias gc-Tests="printf \"๐จ\" | pbcopy && pbpaste && echo \"\"" |
| 131 | alias gc-Deprecation="printf \"๐ฉ\" | pbcopy && pbpaste && echo \"\"" |
| 132 | alias gc-Removal="printf \"๐๏ธ\" | pbcopy && pbpaste && echo \"\"" |
| 133 | alias gc-WorkInProgress="printf \"๐ง\" | pbcopy && pbpaste && echo \"\"" |
| 134 | alias gc-Deforestation="printf \"๐ฒ\" | pbcopy && pbpaste && echo \"\"" |
| 135 | |
| 136 | if [ -x /usr/bin/termsaver ]; then |
| 137 | alias tsm="termsaver matrix" |
| 138 | fi |
| 139 | |
| 140 | if [ -x /usr/bin/cmatrix ]; then |
| 141 | alias etm="cmatrix -a -b -s -C cyan" |
| 142 | fi |
| 143 | |
| 144 | # this is needed to enter the passphrase when attempting to gpg-sign git commits |
| 145 | #export GPG_TTY=$(tty) |
| 146 | |
| 147 | # if you're on WSL you may want to see information from MOTD such as pending updates |
| 148 | #sudo run-parts /etc/update-motd.d/ |
| 149 | |
| 150 | # if you're on WSL and you want to mount network shares |
| 151 | #sudo mount -a |
| 152 | |
| 153 | # if you want to hide commands from your bash history with space and don't include duplicates |
| 154 | # you need this but it may already be set elsewhere |
| 155 | #HISTCONTROL=ignoreboth |
| 156 | |
| 157 | # Debian doesn't have bash-completion by default so you need to apt install bash-completion and add the below |
| 158 | #if [ -f /etc/bash_completion ]; then |
| 159 | # . /etc/bash_completion |
| 160 | #fi |
willpower232 / bash.bashrc
Last active 1 month ago
I am making my .bashrc portable as inspired by this https://www.cyberciti.biz/tips/bash-aliases-mac-centos-linux-unix.html
Revision 39fae949dc1bac9579e603e2987ef5efd3522ac1
| 1 | . /etc/bash.bashrc |
| 2 | |
| 3 | # https://askubuntu.com/a/22043 |
| 4 | alias sudo='sudo ' |
| 5 | |
| 6 | # lol |
| 7 | alias nano='vim' |
| 8 | |
| 9 | function git { |
| 10 | if [[ "$1" == "clone" && "$@" != *"--help"* ]]; then |
| 11 | shift 1 |
| 12 | command git clone --config core.filemode=false "$@" |
| 13 | elif [[ "$1" == "branch" && "$@" != *"--help"* ]]; then |
| 14 | shift 1 |
| 15 | command git checkout -b "$@" |
| 16 | else |
| 17 | command git "$@" |
| 18 | fi |
| 19 | } |
| 20 | |
| 21 | function docker { |
| 22 | if [[ "$1" == "stop-and-rm" ]]; then |
| 23 | shift 1 |
| 24 | command docker stop "$@" |
| 25 | command docker rm "$@" |
| 26 | else |
| 27 | command docker "$@" |
| 28 | fi |
| 29 | } |
| 30 | |
| 31 | # aliases let you put things after the command if you want |
| 32 | # i.e. get familiar with the flags but type way fewer characters |
| 33 | # e.g. dc build --no-cache -> rebuild the images without cache |
| 34 | # e.g. dcu -d -> dc up and detach/background it |
| 35 | # e.g. dce app bash -> dc exec bash in the service |
| 36 | # e.g. dcd -v -> dc down and clear volumes too |
| 37 | alias dc=docker-compose |
| 38 | alias dcd="docker-compose down" |
| 39 | alias dcu="docker-compose up" |
| 40 | alias dce="docker-compose exec" |
| 41 | |
| 42 | # persisting the changes you've made to your container |
| 43 | # is a terrible idea and yet here it is |
| 44 | function dcc { |
| 45 | if [ "$#" -ne "1" ]; then |
| 46 | echo "Precisely one argument required" |
| 47 | return 1 |
| 48 | fi |
| 49 | |
| 50 | CONTAINER=$(dc images | grep "_$1 " | awk '{print $1;}') |
| 51 | TAGNAME=$(dc images | grep "_app " | awk '{print $2;}') |
| 52 | TAGVERSION=$(dc images | grep "_app " | awk '{print $3;}') |
| 53 | |
| 54 | if [ "$CONTAINER" = "" ] || [ "$TAGNAME" = "" ] || [ "$TAGVERSION" = "" ]; then |
| 55 | echo "Unable to figure out what to do" |
| 56 | return 1 |
| 57 | fi |
| 58 | |
| 59 | COMMAND="docker commit $CONTAINER $TAGNAME:$TAGVERSION" |
| 60 | echo $COMMAND |
| 61 | eval $COMMAND |
| 62 | } |
| 63 |
| 1 | # if running bash |
| 2 | if [ -n "$BASH_VERSION" ]; then |
| 3 | # include .bashrc if it exists |
| 4 | if [ -f "$HOME/.bashrc" ]; then |
| 5 | . "$HOME/.bashrc" |
| 6 | fi |
| 7 | fi |
| 8 |