Skip to content

Instantly share code, notes, and snippets.

@Ham5ter
Last active December 8, 2016 14:52
Show Gist options
  • Save Ham5ter/2210b3188aa85d777de66a285f6bad0a to your computer and use it in GitHub Desktop.
Save Ham5ter/2210b3188aa85d777de66a285f6bad0a to your computer and use it in GitHub Desktop.
Ham5ter's personal .profile file
#!/bin/bash
#
# Ham5ter's personal .bash_profile file
#
# Author: ham5ter@ham5ter.de
#
### helper functions ###
helpers() {
echo "genpasswd <LENGTH>"
echo "calc \"<CALCULATION>\""
echo "nocomment <FILE>"
echo "numperms <FILES>"
}
# Generate a Password with easy to type Characters
# Usage: genpasswd <LENGTH>
genpasswd() {
local l=$1
[ "$l" == "" ] && l=16
tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs
}
# Calculate on the Shell via bc
# Usage: calc "3 * 3 / 2"
calc() {
echo "scale=8; $@" | bc
}
# Strip comments and empty lines from Configuration Files
# Usage: nocomment "/path/to/config.file"
nocomment() {
[ $# -lt 1 ] && return; egrep -v "^[[:cntrl:] ]*[#;]|^$" $1;
}
# Show Numeric Permmisions of a File
# Info: https://askubuntu.com/questions/152001/how-can-i-get-octal-file-permissions-from-command-line#152003
# Usage: numperms <FILES>
numperms(){
stat -c "%a %n" "$@"
}
# add the personal /bin directory to the PATH variable
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
### Aliases ###
alias ..="cd .."
alias ...="cd ../.."
alias cd..="cd .."
### ls customization ###
export LS_COLORS='di=34:ln=36:so=0:pi=0:ex=32:bd=0:cd=0:su=0:sg=0:tw=34:ow=34:'
alias ls="ls --color"
alias l="ls -lh"
alias ll="ls -lah"
### colorized Bash Prompt ###
export CLICOLOR=1
if [[ $EUID -eq 0 ]]; then
# root Prompt
export PS1="\[\033[35m\]\t\[\033[m\]-\[\033[31m\]\u\[\033[m\]@\[\033[33m\]\h:\[\033[33;1m\]\w\[\033[m\]# "
else
# normal user Prompt
export PS1="\[\033[35m\]\t\[\033[m\]-\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ "
fi
### grep customization ###
alias grep="GREP_COLOR='1;31' grep --color -Hn"
### History ###
export HISTCONTROL=ignoredups
export HISTFILESIZE=30000
export HISTIGNORE="ls:cd:cd..:[bf]g:exit:..:...:l:ll"
export HISTTIMEFORMAT="%d/%m/%y %T "
### Autocompletion ###
# make Bash tab complete case insensitively
bind "set completion-ignore-case on"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment