Last active
January 20, 2020 14:33
-
-
Save erayerdin/c64ffbf0a85759fb40c2764cf3b848c3 to your computer and use it in GitHub Desktop.
Common Bash functions that I use.
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
######## | |
# Bash # | |
######## | |
# download from youtube as mp3 | |
# requires youtube-dl | |
function youtube-mp3 { | |
youtube-dl --extract-audio --audio-format mp3 "$1" | |
} | |
# mkdir and cd into it | |
function mdir { | |
mkdir -p "$1" | |
cd "$1" | |
} | |
# clean contents of a dir | |
function cleandir { | |
rm -rf "$1" | |
mkdir "$1" | |
} | |
# Creates directories recursively and attaches a new file at the end | |
function grab { | |
mkdir -p "$(dirname "$1")" | |
touch "$1" | |
} | |
########## | |
# Python # | |
########## | |
# activate python env | |
function activate { | |
DIR="" | |
if [ -d ".venv" ]; then | |
DIR=".venv" | |
elif [ -d ".env" ]; then | |
DIR=".env" | |
elif [ -d "venv" ]; then | |
DIR="venv" | |
elif [ -d "env" ]; then | |
DIR="env" | |
else | |
echo "No Python environment was found." | |
return -1 | |
fi | |
source "${DIR}/bin/activate" | |
return 0 | |
} | |
# creates python module | |
function mkpymod { | |
mkdir "$1" | |
touch "${1}/__init__.py" | |
} | |
# find in pip | |
function pipgrep { | |
pip freeze | grep $1 | |
} | |
####### | |
# Git # | |
####### | |
# delete git branch both locally and remotely | |
function git-delete-branch { | |
git push origin --delete $1 | |
git branch -D $1 | |
} | |
########## | |
# Django # | |
########## | |
function django-reset-migration { | |
for var in "$@" | |
do | |
cd "${var}/" | |
find . -path "*/migrations/*.py" -not -name "__init__.py" -delete | |
find . -path "*/migrations/*.pyc" -delete | |
cd .. | |
echo "Migrations were reset for ${var}." | |
done | |
echo "Do not forget to remove database and recreate it again." | |
} | |
######### | |
# Other # | |
######### | |
function gi() { curl -sL "https://www.gitignore.io/api/${1}" ;} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Resetting migrations method was taken from Simple is Better than Complex blog.