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 822b926c5ccde28c46d534fffc72eeccb55abb41

my.bashrc Raw
1# set variable identifying the chroot you work in (used in the prompt below)
2if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
3 debian_chroot=$(cat /etc/debian_chroot)
4fi
5
6# set a fancy prompt (non-color, unless we know we "want" color)
7case "$TERM" in
8 xterm-color) color_prompt=yes;;
9esac
10
11# uncomment for a colored prompt, if the terminal has the capability; turned
12# off by default to not distract the user: the focus in a terminal window
13# should be on the output of commands, not on the prompt
14force_color_prompt=yes
15
16if [ -n "$force_color_prompt" ]; then
17 if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
18 # We have color support; assume it's compliant with Ecma-48
19 # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
20 # a case would tend to support setf rather than setaf.)
21 color_prompt=yes
22 else
23 color_prompt=
24 fi
25fi
26
27if [ "$color_prompt" = yes ]; then
28 if [ "$EUID" -ne 0 ]; then
29 PS1='${debian_chroot:+($debian_chroot)}($SHLVL) \u@\h {\A} \e[32m[\w]\e[0m\n$ '
30 else
31 PS1='${debian_chroot:+($debian_chroot)}($SHLVL) \u@\h {\A} \e[31m[\w]\e[0m\n# '
32 fi
33else
34 if [ "$EUID" -ne 0 ]; then
35 PS1='${debian_chroot:+($debian_chroot)}($SHLVL) u@h {A} [w]\n$ '
36 else
37 PS1='${debian_chroot:+($debian_chroot)}($SHLVL) u@h {A} [w]\n# '
38 fi
39fi
40unset color_prompt force_color_prompt
41
42case "$TERM" in
43 xterm*|rxvt*)
44 PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1";;
45 *)
46 ;;
47esac
48
49# enable color support of ls and also add handy aliases
50if [ -x /usr/bin/dircolors ]; then
51 test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
52 alias ls='ls --color=auto'
53 alias dir='dir --color=auto'
54 alias vdir='vdir --color=auto'
55
56 alias grep='grep --color=auto'
57 alias fgrep='fgrep --color=auto'
58 alias egrep='egrep --color=auto'
59fi
60
61alias nano='nano --nowrap --smooth -T 4'
62alias please='sudo'
63
64# stop yourself from breaking the server by accident
65alias mv='mv -i'
66alias cp='cp -i'
67alias ln='ln -i'
68alias rm='rm -I --preserve-root'
69alias chown='chown --preserve-root'
70alias chmod='chmod --preserve-root'
71alias chgrp='chgrp --preserve-root'
72
73function findinfiles() { find ./ -type f -print0 | xargs -0 grep -i "$1"; }
74function findinphpfiles() { find ./ -type f -name "*.php" -print0 | xargs -0 grep -i "$1"; }
75
76complete -W "$(echo $(grep '^ssh ' ~/.bash_history | sort -u | sed 's/^ssh //'))" ssh
77