Last active
September 13, 2019 12:20
-
-
Save iboard/d6e6d17aa92058dc0b05abfc5d8dcb4f to your computer and use it in GitHub Desktop.
My bash functions loaded from top of bashrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Andreas Altendorfer's Shell Function Library | |
# (c) 2000-2019 <[email protected]> | |
# License: MIT | |
# | |
# ANSI COLORS SEQUENCES | |
# Output a given text in color | |
# Usage: See function print_colors below | |
# \e[0;31m[\u@\h \W]\$ \e[m | |
export RED="\e[0;31m" | |
export GREEN="\e[0;32m" | |
export YELLOW="\e[0;33m" | |
export BLUE="\e[0;34m" | |
export MAGENTA="\e[0;35m" | |
export CYAN="\e[0;36m" | |
export BLACKBG="\e[0;40m" | |
export REDBG="\e[0;41m" | |
export GREENBG="\e[0;42m" | |
export YELLOWBG="\e[0;43m" | |
export BLUEBG="\e[0;44m" | |
export MAGENTABG="\e[0;45m" | |
export BOLD="\e[1m" | |
export UNDERLINE="\e[4m" | |
export REVERSE="\e[7m" | |
export NOCOLOR="\e[0m" | |
export RESET=$NOCOLOR | |
export NORMAL=$NOCOLOR | |
function print_colors { | |
printf "*** ${REVERSE} COLORS IN THE BASH${RESET}" | |
echo "" | |
printf "NORMAL " | |
printf "${RED}RED${NOCOLOR} " | |
printf "${GREEN}GREEN${NOCOLOR} " | |
printf "${YELLOW}YELLOW${NOCOLOR} " | |
printf "${BLUE}BLUE${NOCOLOR} " | |
printf "${CYAN}CYAN${NOCOLOR} " | |
printf "${MAGENTA}MAGENTA${NOCOLOR} " | |
printf "${BLACKBG}BLACKBG${NOCOLOR} " | |
printf "${REDBG}REDBG${NOCOLOR} " | |
printf "${GREENBG}GREENBG${NOCOLOR} " | |
printf "${YELLOWBG}YELLOWBG${NOCOLOR} " | |
printf "${BLUEBG}BLUEBG${NOCOLOR} " | |
printf "${MAGENTABG}MAGENTABG${NOCOLOR} " | |
printf "${BOLD}BOLD${RESET} " | |
printf "${UNDERLINE}UNDERLINE${RESET} " | |
printf "${REVERSE}REVERSE${RESET}" | |
echo "" | |
printf "${BOLD}Examples:${RESET}" | |
echo "" | |
printf " printf 'Normal \${RED}red and \${UNDERLINE}" | |
printf "underlined\${REVERSE}reversed\${RESET} Text" | |
printf " --> " | |
printf "Normal ${RED}red and ${UNDERLINE}" | |
printf "underlined${REVERSE}reversed${RESET} Text" | |
echo "" | |
printf " printf '\${YELLOW}yellow\${REVERSE}reversed\${RESET}" | |
printf " --> " | |
printf "${YELLOW}yellow${REVERSE}reversed${RESET}" | |
echo "" | |
printf "${RED}H${GREEN}A${BLUE}V${CYAN}E${RESET} ${MAGENTABG}FUN!${RESET}" | |
echo "" | |
} | |
# Show the latest changes in the current directory | |
# used when entering a .git-directury from chdir | |
function show_latest_git_changes { | |
FILES="`ls -t | head -n 3`" | |
ONELINE=`echo -n $FILES` | |
echo -e "${GREEN}Last 3 changed files are:${NOCOLOR}" | |
echo -e "${BLUE} * $(ONELINE)${NOCOLOR}" | |
echo "" | |
} | |
# Format a colored prompt depending on git status | |
function git_prompt { | |
if [ -z "$(git status -s 2>/dev/null)" ]; then | |
# Git status is clean | |
printf "${GREEN}$(git branch 2>/dev/null | grep '^*' | colrm 1 2)${NOCOLOR}" | |
else | |
# Git status has uncommitted changes | |
printf "${RED}$(git branch 2>/dev/null | grep '^*' | colrm 1 2)${NOCOLOR}" | |
fi | |
} | |
# UPDATE GISTS | |
function pull_gists { | |
printf "${GREEN}.bashrc${RESET}" | |
gist -r ed91af202c66e435469021cef009bec2 > ~/.bashrc | |
printf ", ${GREEN}.vimrc${RESET}" | |
gist -r 53176a554f74b8097e4c06da795fb929 > ~/.vimrc | |
printf ", ${GREEN}.vim.plugins${RESET}" | |
gist -r 9f634aa50aecec94dbd19046a9b67dce > ~/.vimrc.plugins | |
printf ", ${GREEN}.andi-bash-functions${RESET}" | |
gist -r d6e6d17aa92058dc0b05abfc5d8dcb4f > ~/.andi-bash-functions | |
echo -e "$NO_COLOR" | |
} | |
function push_gists { | |
printf "${CYAN}.bashrc ............... ${GREEN}" | |
gist -u ed91af202c66e435469021cef009bec2 ~/.bashrc | |
printf "${CYAN}.vimrc ................ ${GREEN}" | |
gist -u 53176a554f74b8097e4c06da795fb929 ~/.vimrc | |
printf "${CYAN}.vimrc.plugins ........ ${GREEN}" | |
gist -u 9f634aa50aecec94dbd19046a9b67dce ~/.vimrc.plugins | |
printf "${CYAN}.andi-bash-functions .. ${GREEN}" | |
gist -u d6e6d17aa92058dc0b05abfc5d8dcb4f ~/.andi-bash-functions | |
printf "$RESET" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment