+ Initial Bash Configuration
This commit is contained in:
parent
d1f9d7e0d9
commit
2e96a05b08
|
@ -0,0 +1,143 @@
|
||||||
|
###################################
|
||||||
|
# ___ __ __ __ #
|
||||||
|
# |__/ /\ | / \ |__) / ` #
|
||||||
|
# | \ /~~\ | \__/ | \ \__, #
|
||||||
|
###################################
|
||||||
|
|
||||||
|
# ----- [ Colors ] ----
|
||||||
|
|
||||||
|
# Add color in manpages for less
|
||||||
|
export LESS_TERMCAP_mb=$'\E[01;31m'
|
||||||
|
export LESS_TERMCAP_md=$'\E[01;31m'
|
||||||
|
export LESS_TERMCAP_me=$'\E[0m'
|
||||||
|
export LESS_TERMCAP_se=$'\E[0m'
|
||||||
|
export LESS_TERMCAP_so=$'\E[01;44;33m'
|
||||||
|
export LESS_TERMCAP_ue=$'\E[0m'
|
||||||
|
export LESS_TERMCAP_us=$'\E[01;32m'
|
||||||
|
|
||||||
|
YELLOW='\033[1;33m'
|
||||||
|
GRAY='\033[1;30m'
|
||||||
|
WHITE='\033[1;37m'
|
||||||
|
RESET='\033[0m'
|
||||||
|
|
||||||
|
# ----- [ Functions ] -----
|
||||||
|
|
||||||
|
# Fetch the current folder's git branch and tag
|
||||||
|
git_branch_tag() {
|
||||||
|
# Call the original __git_ps1 function to get the branch name
|
||||||
|
local branch=$(__git_ps1 "%s")
|
||||||
|
|
||||||
|
# Get the latest tag
|
||||||
|
local tag=$(git describe --tags --abbrev=0 2>/dev/null)
|
||||||
|
|
||||||
|
# If we are in a git repository and there is a tag
|
||||||
|
if [[ -n $branch && -n $tag ]]; then
|
||||||
|
echo -n "$branch:$tag"
|
||||||
|
elif [[ -n $branch ]]; then
|
||||||
|
echo -n "$branch"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Extracts any archive(s) (if unp isn't installed)
|
||||||
|
extract () {
|
||||||
|
for archive in $*; do
|
||||||
|
if [ -f $archive ] ; then
|
||||||
|
case $archive in
|
||||||
|
*.tar.bz2) tar xvjf $archive ;;
|
||||||
|
*.tar.gz) tar xvzf $archive ;;
|
||||||
|
*.bz2) bunzip2 $archive ;;
|
||||||
|
*.rar) rar x $archive ;;
|
||||||
|
*.gz) gunzip $archive ;;
|
||||||
|
*.tar) tar xvf $archive ;;
|
||||||
|
*.tbz2) tar xvjf $archive ;;
|
||||||
|
*.tgz) tar xvzf $archive ;;
|
||||||
|
*.zip) unzip $archive ;;
|
||||||
|
*.Z) uncompress $archive ;;
|
||||||
|
*.7z) 7z x $archive ;;
|
||||||
|
*) echo "don't know how to extract '$archive'..." ;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
echo "'$archive' is not a valid file!"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Searches for text in all files in the current folder
|
||||||
|
ftext ()
|
||||||
|
{
|
||||||
|
# -i case-insensitive
|
||||||
|
# -I ignore binary files
|
||||||
|
# -H causes filename to be printed
|
||||||
|
# -r recursive search
|
||||||
|
# -n causes line number to be printed
|
||||||
|
# optional: -F treat search term as a literal, not a regular expression
|
||||||
|
# optional: -l only print filenames and not the matching lines ex. grep -irl "$1" *
|
||||||
|
grep -iIHrn --color=always "$1" . | less -r
|
||||||
|
}
|
||||||
|
|
||||||
|
# Copy file with a progress bar
|
||||||
|
cpp()
|
||||||
|
{
|
||||||
|
set -e
|
||||||
|
strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \
|
||||||
|
| awk '{
|
||||||
|
count += $NF
|
||||||
|
if (count % 10 == 0) {
|
||||||
|
percent = count / total_size * 100
|
||||||
|
printf "%3d%% [", percent
|
||||||
|
for (i=0;i<=percent;i++)
|
||||||
|
printf "="
|
||||||
|
printf ">"
|
||||||
|
for (i=percent;i<100;i++)
|
||||||
|
printf " "
|
||||||
|
printf "]\r"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
END { print "" }' total_size=$(stat -c '%s' "${1}") count=0
|
||||||
|
}
|
||||||
|
|
||||||
|
# IP address lookup
|
||||||
|
alias whatismyip="whatsmyip"
|
||||||
|
function whatsmyip ()
|
||||||
|
{
|
||||||
|
# Dumps a list of all IP addresses for every device
|
||||||
|
# /sbin/ifconfig |grep -B1 "inet addr" |awk '{ if ( $1 == "inet" ) { print $2 } else if ( $2 == "Link" ) { printf "%s:" ,$1 } }' |awk -F: '{ print $1 ": " $3 }';
|
||||||
|
|
||||||
|
# Internal IP Lookup
|
||||||
|
echo -n "Internal IP: " ; /sbin/ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'
|
||||||
|
|
||||||
|
# External IP Lookup
|
||||||
|
echo -n "External IP: " ; curl ipconfig.sh; echo "";
|
||||||
|
}
|
||||||
|
|
||||||
|
# ----- [ Aliases ] -----
|
||||||
|
|
||||||
|
## Exa
|
||||||
|
if command -v exa &> /dev/null; then
|
||||||
|
alias ls='exa --icons'
|
||||||
|
alias ll='exa --icons --long'
|
||||||
|
else
|
||||||
|
echo -e "${YELLOW}[${GRAY}Warn${YELLOW}]:${GRAY} Exa missing, recommended to install for full experience.${WHITE}${RESET}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## Custom
|
||||||
|
alias tfthis="xprop WM_CLASS" # Find out what is the programm that this window comes from called
|
||||||
|
|
||||||
|
|
||||||
|
#Generate a random strong password
|
||||||
|
alias genpasswd="strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 30 | tr -d '\n'; echo"
|
||||||
|
|
||||||
|
#Expand current directory structure in tree form
|
||||||
|
alias treed="ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'"
|
||||||
|
|
||||||
|
#Show active ports
|
||||||
|
alias n_ports='netstat -tulanp'
|
||||||
|
|
||||||
|
# ----- [ Looks ] -----
|
||||||
|
|
||||||
|
|
||||||
|
# PS1
|
||||||
|
# export PS1=" \[\033[38;5;220m\]кπ \[\033[38;5;192m\]\w\[\e[0m\]$ " # Old
|
||||||
|
export PS1=" \[\033[38;5;220m\]кπ \[\033[38;5;192m\]\w\[\e[0m\]\$(__git_ps1 ' \[\e[38;5;87m\]%s\[\e[0m\]')\$ "
|
||||||
|
export PS1=" \[\033[38;5;220m\]кπ \[\033[38;5;192m\]\w\[\e[0m\]\$(if [[ \$(git rev-parse --is-inside-work-tree 2>/dev/null) == 'true' ]]; then echo -n ' \[\e[38;5;87m\]'; git_branch_tag; echo -n '\[\e[0m\]'; fi)\$ "
|
Loading…
Reference in New Issue