Better Bash Configs

From TheBeard Science Project Wiki
Jump to: navigation, search

These are just some things I add to my bashrc for enhancing the features of Bash.

# Because sometimes I manipulate $IFS and forget what to change it back to
export SAVEIFS=$IFS

# Set your default editor for systemd (like when using systemctl edit thing.service)
export SYSTEMD_EDITOR="/usr/bin/vim"

# Stop putting quotes around files/folders that have spaces
export QUOTING_STYLE=literal

# Make it so the screen doesn't blank out after a period of time
setterm -blank 0 >&/dev/null

# Set a nice font
setfont /usr/share/consolefonts/Lat15-TerminusBold22x11.psf.gz >&/dev/null

# For better tab completion on symlink directories
# Normal behavior: With folder symlink "Documents", Type "Doc", Tab once auto-completes
#                  to "Documents", Tab again it completes to "Documents/".
# New behavior:    With folder symlink "Documents", Type "Doc", Tab once auto-completes
#                  to "Documents/". Nice.
if ! [ -f "~/.inputrc" ];then
        if [ -r "/etc/inputrc" ];then
                cp /etc/inputrc ~/.inputrc
        elif [ -r "/etc/inputrc.default" ];then
                cp /etc/inputrc.default ~/.inputrc
        fi
fi
if [ -z "$(grep -o 'set mark-symlinked-directories on' ~/.inputrc 2>/dev/null)" ];then
        echo -e "\nset mark-symlinked-directories on" >>~/.inputrc
fi

# For on-the-fly $IFS manipulation
alias ifs='IFS=$(echo -en "\x0a\x08")'
alias unifs='IFS=$(echo -en "\x20\x09\x0a")'

# I use this all the time to find what's taking up the most drive space.
# From your working directory, list the total size of every file/folder
# (only 1 level deep). Also highlights anything 1 Gig or bigger in red
# (plus a "*" in case your terminal doesn't support colors).
fsize(){
        s=$IFS
        IFS=`echo -en "\n\b"`
        for x in *;do
                echo -en "\e[0;36m$x|\e[0m"
                size=`du -ch "$x" 2>/dev/null|tail -1|sed 's/\x09/ /g'`
                if echo "$size"|grep -q "G";then
                        color="\e[0;31m"
                        mark="*"
                elif echo "$size"|grep -q "T";then
                        color="\e[0;31m"
                        mark="*"
                else
                        color=""
                        mark=""
                fi
                echo -e "$color$size $mark\e[0m"
        done|column -t -s'|' 2>/dev/null
        IFS=$s
        echo -en "\e[0m"
}