Last active
July 6, 2021 03:06
-
-
Save Twoody/799277ca2fef6461e02aa94f2c3a6d5b to your computer and use it in GitHub Desktop.
The best of my bashrc's from over time
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
# Author: [email protected] | |
# Date: 2019-03-29 | |
#Import (i.e. `source`) all files in ~/bin/ | |
#for f in ~/bin/*; do source $f --source-only; echo "imported ~/bin/$f"; done | |
### Most convenient aliases | |
alias c='clear && ls && echo -e "\n" && gs' | |
alias q='exit' | |
alias g='grep -ri ' ## `g f foo/` | |
alias v='vim' | |
alias ga="git add" | |
alias gs='git status' | |
alias gb='git branch' | |
alias gd='git diff' | |
alias gc='git commit' | |
alias gl='git log --stat' | |
alias gm='git merge' | |
alias gch='git checkout' | |
alias :q="echo \"THIS IS NOT vim, DUMMY\"" | |
alias :w="echo \"THIS IS NOT vim, DUMMY\"" | |
alias la='ls -la' | |
alias sl='ls' | |
alias brc="vim ~/.bashrc" | |
alias lsd="du -h | sort -n -r" ## List all contents in dir by file size; | |
alias plog='vim ~/.pylog/logs/main.log' ## Personal location for all python logs | |
alias hgrep="history | grep " | |
alias bhist="vim ~/.bash_history" | |
alias attic="sh ~/bin/attic.sh" ## Source file attic.py | |
alias clogs="sh ~/bin/clogs.sh" ## Source file consolidate_logs.py | |
alias wcount="sh ~/bin/wcount.sh" ## Source file get_word_count.py | |
alias sbrc="source ~/.bashrc" | |
alias gfind="find . -not -path \"./node_modules*\" -iname" ## Probably should be a full function... | |
#find . -type f -name '*.log' -print0 | xargs -0 grep "fo" | |
### Docker | |
alias dockup="docker-compose up --force-recreate" ##Casey: "If up, will down then up? I.T.S." | |
alias dockpatch="docker-compose pull && docker-compsoe build --pull" | |
alias dockdown="docker-compose down --remove-orphans" | |
alias art="php artisan" | |
## Fun | |
alias shrug="echo '¯\_(ツ)_/¯'"; | |
alias fight="echo '(ง'̀-'́)ง'"; | |
### Show just the directories contained in current dir; | |
alias folders='find . -maxdepth 1 -type d -print0 | xargs -0 du -sk | sort -rn' | |
### ### ### Color for ALL grep commands (grep, egrep, zgrep) ### ### ### | |
### Highlights search within colow | |
export GREP_OPTIONS='--color=auto' | |
### ### ### Color for manpages and `less` ### ### ### | |
### SECONDARY OPTION | |
#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' | |
### PRIMARY OPTION | |
#export LESS_TERMCAP_us=$'\E[01;32m' | |
export LESS_TERMCAP_mb=$'\e[1;32m' | |
export LESS_TERMCAP_md=$'\e[1;32m' | |
export LESS_TERMCAP_me=$'\e[0m' | |
export LESS_TERMCAP_se=$'\e[0m' | |
export LESS_TERMCAP_so=$'\e[01;33m' | |
export LESS_TERMCAP_ue=$'\e[0m' | |
export LESS_TERMCAP_us=$'\e[1;4;31m' | |
### ### ### TRAVERSAL ALIASES ### ### ### | |
alias ..="cd .." | |
alias ...="cd ../.." | |
alias ....="cd ../../.." | |
alias .....="cd ../../../.." | |
### ### ### PYTHON ASSISTED PROGRAMMING ### ### ### | |
export PYTHONPATH=$PYTHONPATH:$HOME/pytils | |
### ### ### BASH HISTORY ### ### ### | |
export HISTFILESIZE=20000 | |
export HISTSIZE=10000 | |
shopt -s histappend | |
# Combine multiline commands into one in history | |
shopt -s cmdhist | |
# Ignore duplicates, ls without options and builtin commands | |
HISTCONTROL=ignoredups | |
#export HISTIGNORE="&:ls:sl:[bf]g:exit:q:attic:" | |
### ### ### BASH PROMPT CONFIG ### ### ### | |
###[12:17][useralpha:~/foo/bar]$ | |
function __setprompt { | |
#https://unix.stackexchange.com/questions/381113/how-do-i-shorten-the-current-directory-path-shown-on-terminal | |
local BLUE="\[\033[0;34m\]" | |
local NO_COLOUR="\[\033[0m\]" | |
local SSH_IP=`echo $SSH_CLIENT | awk '{ print $1 }'` | |
local SSH2_IP=`echo $SSH2_CLIENT | awk '{ print $1 }'` | |
if [ $SSH2_IP ] || [ $SSH_IP ] ; then | |
local SSH_FLAG="@\h" | |
fi | |
#PS1='\u@\h: \W:\$' | |
#PS1="\[\033[42m\]\[\033[31m\]\u@\h:\w\$ " | |
#PS1="\[\033[42m\]\[\033[31m\]\u@\h:\W\\[\033[00m\]\$ " | |
PS1="\[\033[4;41m\]\[\033[33m\][\$(date +%H:%M)][\u:\W]\\$ \[\033[00m\]" | |
#PS1="\e[41;4;33m[\$(date +%H:%M)][\u$SSH_FLAG:\W]\$ $NO_COLOUR" | |
#PS1="\\[$(tput setaf 1)\\]\\u@\\h:\\w #\\[$(tput sgr0)\\]" | |
#PS2="\e[41;4;33m$NO_COLOUR " | |
#PS4="\e[41;4;33m$NO_COLOUR " | |
} | |
__setprompt | |
### For all of the extraction conveniences | |
extract () { | |
if [ -f $1 ] ; then | |
case $1 in | |
*.tar.bz2) tar xvjf $1 ;; | |
*.tar.gz) tar xvzf $1 ;; | |
*.bz2) bunzip2 $1 ;; | |
*.rar) unrar x $1 ;; | |
*.gz) gunzip $1 ;; | |
*.tar) tar xvf $1 ;; | |
*.tbz2) tar xvjf $1 ;; | |
*.tgz) tar xvzf $1 ;; | |
*.zip) unzip $1 ;; | |
*.Z) uncompress $1 ;; | |
*.7z) 7z x $1 ;; | |
*) echo "don't know how to extract '$1'..." ;; | |
esac | |
else | |
echo "'$1' is not a valid file!" | |
fi | |
} | |
### Get the changes done by a Git commit ## | |
gdc () { | |
git diff $1~ $1 | |
true | |
} | |
### Execute an sqlite3 file on a given db | |
sql3-exec () { | |
# TODO: Ensure that $1 is a db | |
# TODO: Ensure that $2 is a .sql file | |
# TODO: Probably store a backup... | |
# TODO: write a --help flag | |
sqlite3 $1 ".read $2" | |
true | |
} | |
### Get grep results for vue build ### | |
gvue () { | |
# Skip over node_modules/ and .git/ + Follow sylinks on recursion; | |
grep --exclude-dir={node_modules,.git} -Ri "$1" ./src/ | |
true | |
} | |
### Very Liberal Search for somethign that looks like what we want ### | |
search () { | |
find . -iname *$1* | |
true | |
} | |
### For Deploying reactJS builds: | |
### **Note a deploy-live is available within /twoody/ gists** | |
deploy () { | |
if [ ! -d build/ ] | |
then | |
echo -e "ERROR:\n\tDoes not appear to be correct directory;" | |
echo -e "\tDir /build/ not found;" | |
false | |
fi | |
echo -e "STARTING:" | |
if [ -d ../static/ ] | |
then | |
echo -e "\tREMOVING ../static/*" | |
rm -r ./../static/ || echo "\tWARNING: DID NOT REMOVE DIR" | |
else | |
echo -e "\tDID NOT FIND ../static/ FOR REMOVAL" | |
fi | |
# Redirecting the ls output to make it completely silent | |
if ls ../precache-manifest* 1> /dev/null 2>&1; | |
then | |
echo -e "\tREMOVING ../precach*" | |
rm -r ./../precache-manifest* || echo "\tWARNING: DID NOT REMOVE CACHE" | |
else | |
echo -e "\tDID NOT FIND ../static/ FOR REMOVAL" | |
fi | |
echo -e "\tRUNNING: npm run build" | |
npm run build | |
echo -e "\tCOPYING OVER NEW BUILD DIR" | |
cp -r build/* ../ | |
echo -e "DONE" | |
true #Bash is weird; 0 is true, 1 is false; | |
} | |
### Replace all spaces with underscores within parent | |
strip-spaces () { | |
find . -depth -name '* *' \ | |
| while IFS= read -r f ; do mv -i "$f" "$(dirname "$f")/$(basename "$f"|tr ' ' _)" ; done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment