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 30725d005ccdc8e86637c0b5244c01cfc11c2a77

my.bashrc Raw
1git_branch=
2git_dirty=
3if [ -d ~/.bash/git-aware-prompt ]; then
4 source ~/.bash/git-aware-prompt/prompt.sh
5fi
6
7# set variable identifying the chroot you work in (used in the prompt below)
8if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
9 debian_chroot=$(cat /etc/debian_chroot)
10fi
11
12# set a fancy prompt (non-color, unless we know we "want" color)
13case "$TERM" in
14 xterm-color) color_prompt=yes;;
15esac
16
17# uncomment for a colored prompt, if the terminal has the capability; turned
18# off by default to not distract the user: the focus in a terminal window
19# should be on the output of commands, not on the prompt
20force_color_prompt=yes
21
22if [ -n "$force_color_prompt" ]; then
23 if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
24 # We have color support; assume it's compliant with Ecma-48
25 # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
26 # a case would tend to support setf rather than setaf.)
27 color_prompt=yes
28 else
29 color_prompt=
30 fi
31fi
32
33if [ "$color_prompt" = yes ]; then
34 if [ "$EUID" -ne 0 ]; then
35 PS1='${debian_chroot:+($debian_chroot)}($SHLVL) \u@\h {\A} \e[32m[\w] \e[1;34m$git_branch\e[31m$git_dirty\e[0m\n$ '
36 else
37 PS1='${debian_chroot:+($debian_chroot)}($SHLVL) \u@\h {\A} \e[31m[\w]\e[0m\n# '
38 fi
39else
40 if [ "$EUID" -ne 0 ]; then
41 PS1='${debian_chroot:+($debian_chroot)}($SHLVL) u@h {A} [w] $git_branch$git_dirty\n$ '
42 else
43 PS1='${debian_chroot:+($debian_chroot)}($SHLVL) u@h {A} [w]\n# '
44 fi
45fi
46unset color_prompt force_color_prompt
47
48case "$TERM" in
49 xterm*|rxvt*)
50 PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1";;
51 *)
52 ;;
53esac
54
55# enable color support of ls and also add handy aliases
56if [ -x /usr/bin/dircolors ]; then
57 test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
58 alias ls='ls --color=auto'
59 alias dir='dir --color=auto'
60 alias vdir='vdir --color=auto'
61
62 alias grep='grep --color=auto'
63 alias fgrep='fgrep --color=auto'
64 alias egrep='egrep --color=auto'
65fi
66
67alias nano='nano --nowrap --smooth -T 4'
68alias plz='sudo'
69alias dammit='sudo !!'
70
71# stop yourself from breaking the server by accident
72alias mv='mv -i'
73alias cp='cp -i'
74alias ln='ln -i'
75alias rm='rm -I --preserve-root'
76alias chown='chown --preserve-root'
77alias chmod='chmod --preserve-root'
78alias chgrp='chgrp --preserve-root'
79
80function findinfiles() { find ./ -type f -print0 | xargs -0 grep -i "$1"; }
81function findinphpfiles() { find ./ -type f -name "*.php" -print0 | xargs -0 grep -i "$1"; }
82
83complete -W "$(echo $(grep '^ssh ' ~/.bash_history | sort -u | sed 's/^ssh //'))" ssh
84
85if [ "$(uname)" == "Darwin" ]; then
86 # got pbcopy
87 :
88elif grep -q Microsoft /proc/version; then
89 # route error to /dev/null because thanks microsoft
90 alias pbcopy='clip.exe > /dev/null 2>&1'
91else
92 # install xclip through apt first
93 alias pbcopy='xclip -selection clipboard'
94fi
95
96# thanks @jamesdoc
97alias e-thumbsup="printf \"๐Ÿ‘\" | pbcopy && echo \"๐Ÿ‘ copied to the clipboard\""
98alias e-pointup="printf \"๐Ÿ‘†\" | pbcopy && echo \"๐Ÿ‘† copied to the clipboard\""
99alias e-pointdown="printf \"๐Ÿ‘‡\" | pbcopy && echo \"๐Ÿ‘‡ copied to the clipboard\""
100alias e-rocket="printf \"๐Ÿš€\" | pbcopy && echo \"๐Ÿš€ copied to the clipboard\""
101alias e-tada="printf \"๐ŸŽ‰\" | pbcopy && echo \"๐ŸŽ‰ copied to the clipboard\""
102alias e-lightning="printf \"โšก\" | pbcopy && echo \"โšก copied to the clipboard\""
103alias shruggie="printf \"ยฏ\_(ใƒ„)_/ยฏ\" | pbcopy && echo \"ยฏ\_(ใƒ„)_/ยฏ copied to clipboard\""
104
105if [ -x /usr/bin/termsaver ]; then
106 alias tsm="termsaver matrix"
107fi
108
109if [ -x /usr/bin/cmatrix ]; then
110 alias etm="cmatrix -a -b -s -C cyan"
111fi
112
113# on WSL this is needed to enter the passphrase when attempting to gpg-sign git commits
114#export GPG_TTY=$(tty)
115
116# if you're on WSL you may want to see information from MOTD such as pending updates
117#sudo run-parts /etc/update-motd.d/
118
119# if you're on WSL and you want to mount network shares
120#sudo mount -a
121
122# if you want to hide commands from your bash history with space and don't include duplicates
123# you need this but it may already be set elsewhere
124#HISTCONTROL=ignoreboth
125
126# Debian doesn't have bash-completion by default so you need to apt install bash-completion and add the below
127#if [ -f /etc/bash_completion ]; then
128# . /etc/bash_completion
129#fi