Skip to content

Instantly share code, notes, and snippets.

@nhristov

nhristov/.bash_profile

Last active Feb 15, 2021
Embed
What would you like to do?
export CLICOLOR=1
export LC_ALL="C"
export LC_COLLATE="C"
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
export PS1="\[\033[36m\]\u\[\033[m\]:\[\033[33;1m\]\W\[\033[m\]$ "
[[ $PS1 && -f ~/.config/bash-completion/bash_completion ]] && . ~/.config/bash-completion/bash_completion
alias .....="cd ../../../../"
alias ....="cd ../../../../"
alias ...="cd ../../../"
alias ..="cd .."
alias .4="cd ../../../../"
alias .5="cd ../../../../.."
alias cd..="cd .."
alias chgrp="chgrp --preserve-root"
alias chmod="chmod --preserve-root"
alias chown="chown --preserve-root"
alias ci="code-insiders"
alias cp="cp -i"
alias df="pydf"
alias docker_prune="docker system prune && docker volume prune"
alias header="curl -I"
alias headerc="curl -I --compress"
alias l.="ls -d .*"
alias ll="ls -la"
alias ln="ln -i"
alias ls="ls -AlhG --color=always"
alias mkdir="mkdir -pv"
alias mv="mv -i"
alias myip="curl http://ipecho.net/plain; echo"
alias nocomment="grep -Ev '\''^(#|$)'\''"
alias ports="netstat -tulanp"
alias prettify="prettier --config ~/.prettierrc --ignore-path ~/.prettierignore --loglevel error"
alias psg="ps aux | grep -v grep | grep -i -e VSZ -e"
alias rm="rm -I --preserve-root"
alias rsync="rsync --compress --copy-links --devices --exclude={.git} --group --human-readable --info=progress2 --inplace --owner --partial --perms --recursive --specials --stats --times"
alias update_system="sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade && sudo apt-get autoremove && sudo apt-get clean"
alias wget="wget -c"
function backup_database() {
DB_EXCLUDE=(
"accounts"
"information_schema"
"mysql"
"performance_schema"
"sys"
"tmp"
)
echo "Enter Backup Directory:"
read -s DB_DIR
echo "Enter User:"
read -s DB_USER
echo "Enter Password:"
read -s DB_PASS
echo "Enter Host:"
read -s DB_HOST
mkdir -p $DB_DIR
cd $DB_DIR
DBS=$(mysql -u$DB_USER -p"$DB_PASS" --host="$DB_HOST" -e "SHOW DATABASES;" | tr -d "| " | grep -v Database)
BACKUP_DATE=$(date +%d_%m_%Y)
mkdir $BACKUP_DATE
for DBC in $DBS; do
for DBX in "${DB_EXCLUDE[@]}"; do
if [[ "$DBC" == "$DBX" ]]; then
continue 2
fi
done
if [[ "$DBC" != _* ]]; then
echo "Dumping Database: $DBC"
mysqldump --single-transaction --set-gtid-purged=OFF -u"$DB_USER" -p"$DB_PASS" --host="$DB_HOST" --databases $DBC >$BACKUP_DATE/$DBC.sql
fi
done
cd -
unset DB_EXCLUDE
unset DBS
unset BACKUP_DATE
}
function build_npm() {
if [ -f "package.json" ]; then
npm run build
fi
}
function cd() {
builtin cd "$@" && ls
}
function delete_all_tags() {
git fetch
git tag | xargs -L 1 | xargs git push origin --delete
git tag | xargs -L 1 | xargs git tag --delete
}
function erase_history() {
cat /dev/null >~/.bash_history && history -c
cat /dev/null >~/.nano/search_history
exit
}
function extract() {
if [ -z "$1" ]; then
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
else
if [ -f $1 ]; then
case $1 in
*.tar.bz2) tar xvjf ./$1 ;;
*.tar.gz) tar xvzf ./$1 ;;
*.tar.xz) tar xvJf ./$1 ;;
*.lzma) unlzma ./$1 ;;
*.bz2) bunzip2 ./$1 ;;
*.rar) unrar x -ad ./$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 ;;
*.xz) unxz ./$1 ;;
*.exe) cabextract ./$1 ;;
*) echo "extract: '$1' - unknown archive method" ;;
esac
else
echo "$1 - file does not exist"
fi
fi
}
function firebase_deploy() {
if [ -f "firebase.json" ]; then
firebase deploy
fi
}
function get_id() {
if [ -z "$1" ]; then
printf "Usage: get_id <process_name>"
else
printf "Listing IDs for $1:\n\n"
bash -c "ps aux | grep '$1' | awk '{printf \$11\" \"\$12 \" %s \\n\", \$2} END {print \"\"}'"
fi
}
function install_composer() {
if [ -f "composer.json" ]; then
composer install
fi
}
function install_npm() {
if [ -f "package.json" ]; then
npm install
fi
}
function proper_permissions() {
sudo find . -type d -name "node_modules" -prune -o -type f -exec chmod 0644 {} \;
sudo find . -type d -name "node_modules" -prune -o -type d -exec chmod 0755 {} \;
}
function run_in_dirs() {
for DIR in ./*; do
if [ -d "$DIR" ]; then
builtin cd "$DIR"
echo $PWD
bash -cl "$*"
builtin cd "$OLDPWD"
fi
done
unset DIR
}
function secure_pass() {
tr -dc 'a-zA-Z0-9~!@#$%^&*_-' </dev/urandom | head -c 24
echo -n
}
function sign_all_commits() {
git rebase --exec 'git commit --amend --no-edit -n -S' -i --root
}
function sign_commits() {
git rebase --exec 'git commit --amend --no-edit -n -S' -i $1
}
function sshagent_findsockets() {
find /tmp -uid $(id -u) -type s -name agent.\* 2>/dev/null
}
function sshagent_testsocket() {
if [ ! -x "$(which ssh-add)" ]; then
echo "ssh-add is not available; agent testing aborted"
return 1
fi
if [ X"$1" != X ]; then
export SSH_AUTH_SOCK=$1
fi
if [ X"$SSH_AUTH_SOCK" = X ]; then
return 2
fi
if [ -S $SSH_AUTH_SOCK ]; then
ssh-add -l >/dev/null
if [ $? = 2 ]; then
echo "Socket $SSH_AUTH_SOCK is dead! Deleting!"
rm -f $SSH_AUTH_SOCK
return 4
else
echo "Found ssh-agent $SSH_AUTH_SOCK"
return 0
fi
else
echo "$SSH_AUTH_SOCK is not a socket!"
return 3
fi
}
function sshagent_init() {
AGENTFOUND=0
if sshagent_testsocket; then AGENTFOUND=1; fi
if [ $AGENTFOUND = 0 ]; then
for agentsocket in $(sshagent_findsockets); do
if [ $AGENTFOUND != 0 ]; then break; fi
if sshagent_testsocket $agentsocket; then AGENTFOUND=1; fi
done
fi
if [ $AGENTFOUND = 0 ]; then
eval $(ssh-agent)
fi
unset AGENTFOUND
unset agentsocket
ssh-add -l
}
function update_composer() {
if [ -f "composer.json" ]; then
composer update
fi
}
function update_npm() {
if [ -f "package.json" ]; then
ncu -u
fi
}
eval "$(zoxide init bash)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment