willpower232

willpower232 / bash.bashrc

Last active 1 month ago

Like 0

I am making my .bashrc portable as inspired by this https://www.cyberciti.biz/tips/bash-aliases-mac-centos-linux-unix.html

Revision fd88c201791a662c287da50858bafcfe373e831f

bash.bashrc Raw
1# git clone git@github.com:jimeh/git-aware-prompt ~/.bash/git-aware-prompt
2git_branch=
3git_dirty=
4if [ -d ~/.bash/git-aware-prompt ]; then
5 source ~/.bash/git-aware-prompt/prompt.sh
6fi
7
8# set variable identifying the chroot you work in (used in the prompt below)
9if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
10 debian_chroot=$(cat /etc/debian_chroot)
11fi
12
13# set a fancy prompt (non-color, unless we know we "want" color)
14case "$TERM" in
15 xterm-color) color_prompt=yes;;
16esac
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
21force_color_prompt=yes
22
23if [ -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
32fi
33
34if [ "$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\]"
45else
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
51fi
52unset 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
63if [ -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'
72fi
73
74alias nano='nano --nowrap --smooth -T 4'
75alias plz='sudo '
76alias dammit='sudo !!'
77
78# stop yourself from breaking the server by accident
79alias mv='mv -i'
80alias cp='cp -i'
81alias ln='ln -i'
82alias rm='rm -I --preserve-root'
83alias chown='chown --preserve-root'
84alias chmod='chmod --preserve-root'
85alias chgrp='chgrp --preserve-root'
86
87function findinfiles() { find ./ -type f -print0 | xargs -0 grep -i "$1"; }
88function findinphpfiles() { find ./ -type f -name "*.php" -print0 | xargs -0 grep -i "$1"; }
89
90complete -W "$(echo $(grep '^ssh ' ~/.bash_history | sort -u | sed 's/^ssh //'))" ssh
91
92if [ "$(uname)" == "Darwin" ]; then
93 # got pbcopy
94 :
95elif grep -q Microsoft /proc/version; then
96 # route error to /dev/null because thanks microsoft
97 alias pbcopy='clip.exe > /dev/null 2>&1'
98else
99 # install xclip through apt first
100 alias pbcopy='xclip -selection clipboard'
101 alias pbpaste='xclip -selection clipboard -o'
102fi
103
104# thanks @jamesdoc
105alias e-thumbsup="printf \"๐Ÿ‘\" | pbcopy && echo \"๐Ÿ‘ copied to the clipboard\""
106alias e-pointup="printf \"๐Ÿ‘†\" | pbcopy && echo \"๐Ÿ‘† copied to the clipboard\""
107alias e-pointdown="printf \"๐Ÿ‘‡\" | pbcopy && echo \"๐Ÿ‘‡ copied to the clipboard\""
108alias e-rocket="printf \"๐Ÿš€\" | pbcopy && echo \"๐Ÿš€ copied to the clipboard\""
109alias e-tada="printf \"๐ŸŽ‰\" | pbcopy && echo \"๐ŸŽ‰ copied to the clipboard\""
110alias e-lightning="printf \"โšก\" | pbcopy && echo \"โšก copied to the clipboard\""
111alias shruggie="printf \"ยฏ\_(ใƒ„)_/ยฏ\" | pbcopy && echo \"ยฏ\_(ใƒ„)_/ยฏ copied to clipboard\""
112
113# ref https://github.com/dannyfritz/commit-message-emoji
114alias gc-InitialCommit="printf \"๐ŸŽ‰\" | pbcopy && pbpaste && echo \"\""
115alias gc-VersionTag="printf \"๐Ÿ”–\" | pbcopy && pbpaste && echo \"\""
116alias gc-NewFeature="printf \"โœจ\" | pbcopy && pbpaste && echo \"\""
117alias gc-Bugfix="printf \"๐Ÿ›\" | pbcopy && pbpaste && echo \"\""
118alias gc-SecurityFix="printf \"๐Ÿ”’\" | pbcopy && pbpaste && echo \"\""
119alias gc-Metadata="printf \"๐Ÿ“‡\" | pbcopy && pbpaste && echo \"\""
120alias gc-Refactoring="printf \"โ™ป๏ธ\" | pbcopy && pbpaste && echo \"\""
121alias gc-Documentation="printf \"๐Ÿ“š\" | pbcopy && pbpaste && echo \"\""
122alias gc-Internationalization="printf \"๐ŸŒ\" | pbcopy && pbpaste && echo \"\""
123alias gc-Accessibility="printf \"โ™ฟ\" | pbcopy && pbpaste && echo \"\""
124alias gc-Performance="printf \"๐ŸŽ\" | pbcopy && pbpaste && echo \"\""
125alias gc-Cosmetic="printf \"๐ŸŽจ\" | pbcopy && pbpaste && echo \"\""
126alias gc-Tooling="printf \"๐Ÿ”ง\" | pbcopy && pbpaste && echo \"\""
127alias gc-Tests="printf \"๐Ÿšจ\" | pbcopy && pbpaste && echo \"\""
128alias gc-Deprecation="printf \"๐Ÿ’ฉ\" | pbcopy && pbpaste && echo \"\""
129alias gc-Removal="printf \"๐Ÿ—‘๏ธ\" | pbcopy && pbpaste && echo \"\""
130alias gc-WorkInProgress="printf \"๐Ÿšง\" | pbcopy && pbpaste && echo \"\""
131alias gc-Deforestation="printf \"๐ŸŒฒ\" | pbcopy && pbpaste && echo \"\""
132
133if [ -x /usr/bin/termsaver ]; then
134 alias tsm="termsaver matrix"
135fi
136
137if [ -x /usr/bin/cmatrix ]; then
138 alias etm="cmatrix -a -b -s -C cyan"
139fi
140
141# this is needed to enter the passphrase when attempting to gpg-sign git commits
142#export GPG_TTY=$(tty)
143
144# if you're on WSL you may want to see information from MOTD such as pending updates
145#sudo run-parts /etc/update-motd.d/
146
147# if you're on WSL and you want to mount network shares
148#sudo mount -a
149
150# if you want to hide commands from your bash history with space and don't include duplicates
151# you need this but it may already be set elsewhere
152#HISTCONTROL=ignoreboth
153
154# Debian doesn't have bash-completion by default so you need to apt install bash-completion and add the below
155#if [ -f /etc/bash_completion ]; then
156# . /etc/bash_completion
157#fi
my.bashrc Raw
1. /etc/bash.bashrc
2
3# https://askubuntu.com/a/22043
4alias sudo='sudo '
5
6# lol
7alias nano='vim'
8
9function 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
21function 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
37alias dc=docker-compose
38alias dcd="docker-compose down"
39alias dcu="docker-compose up"
40alias 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
44function 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
my.profile Raw
1# if running bash
2if [ -n "$BASH_VERSION" ]; then
3 # include .bashrc if it exists
4 if [ -f "$HOME/.bashrc" ]; then
5 . "$HOME/.bashrc"
6 fi
7fi
8