Skip to content

Instantly share code, notes, and snippets.

@DCzajkowski
Last active July 6, 2020 10:46
Show Gist options
  • Save DCzajkowski/c826852c0a630ebbf6b821ea10d2775b to your computer and use it in GitHub Desktop.
Save DCzajkowski/c826852c0a630ebbf6b821ea10d2775b to your computer and use it in GitHub Desktop.
My bash configuration
# aliases
alias ~="cd ~"
alias ..="cd .."
alias cd..="cd .."
alias ls="ls -G"
alias ll="ls -alh" # -S for sort by size
alias rmf="rm -rf"
alias bat="bat --paging never"
alias sourceb="source ~/.bash_profile"
alias cod="cd ~/code"
alias a="php artisan"
alias console="./bin/console"
alias scripts="list-scripts"
alias bash_profile="sudo vi ~/.bash_profile"
alias ohmy="code ~/.zshrc"
alias bash_theme="code ~/.oh-my-zsh/custom/themes/dc.zsh-theme"
alias open.="open ."
alias code.="code ."
function kill-grep () {
for i in `ps aux | grep $1 | awk '{print $2}'`;
do
kill -9 $i;
done
}
# Git
alias ga="git add"
alias gaa="git add --all"
function gc {
git commit -m "$*"
}
alias gch="git checkout"
alias gchn="git checkout -b"
alias gp="git push"
alias gpu="git pull"
alias gs="git status"
alias gst="git stash"
alias nah="git reset --hard;git clean -df;"
alias gl="git log --oneline --decorate --all --graph"
alias glo="git log --oneline"
alias gu="git reset HEAD~"
alias gr="git reset"
alias gam="git commit --amend"
alias gb="git branch"
alias gf="git fetch"
alias gm="git merge"
function gh() {
url=`git remote get-url origin`
url=`cut -d ":" -f 2 <<< "$url"`
url=${url: : -4}
open https://github.com/${url}
}
function gpn() {
git push --set-upstream origin `git branch | grep '*' | tr -d '* '`
}
function gpr() {
open https://github.com/`git remote get-url origin | sed -e "s/^git\@github\.com\://" -e "s/\.git$//"`/pull/new/`git branch | grep '*' | tr -d '* '`
}
# Git stash staged
function gsts() {
# Stash everything temporarily. Keep staged files, discard everything else after stashing.
git stash --keep-index
# Stash everything that remains (only the staged files should remain) This is the stash we want to keep, so give it a name.
git stash save "$1"
# Apply the original stash to get us back to where we started.
git stash apply stash@{1}
# Create a temporary patch to reverse the originally staged changes and apply it
git stash show -p | git apply -R
# Delete the temporary stash
git stash drop stash@{1}
}
# C compiler
function c {
gcc $1.c -o $1 -Wall && ./$1 "${@:3}"
# gcc -Wall -ansi -pedantic $1.c -o $1 && ./$1
}
function cpp {
g++ $1.cpp -o $1 && ./$1
}
# Laravel Zonda
function l {
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Create Laravel Projects fast."
echo "Flags:"
echo " - -a Create an auth scaffolding"
echo " - -d Create a MySQL database"
echo " - -g Add GitHub remote"
return
fi
if [ -z ${1+x} ]; then
echo "Required parameter {name} is not set."
return
fi
PROJECT=$1
echo "Creating new Laravel project: $PROJECT..."
web
~/.composer/vendor/bin/laravel new $PROJECT
cd $PROJECT
git init
git add .
git commit -m "Fresh Laravel installation"
sed -i '' "s/APP_URL=http\:\/\/localhost/APP_URL=http\:\/\/$PROJECT\.test/g" .env
sed -i '' "s/DB_DATABASE=homestead/DB_DATABASE=$PROJECT/g" .env
sed -i '' "s/DB_USERNAME=homestead/DB_USERNAME=root/g" .env
sed -i '' "s/DB_PASSWORD=secret/DB_PASSWORD=/g" .env
sed 's/<server name="SESSION_DRIVER" value="array"\/>/<server name="SESSION_DRIVER" value="array"\/>, <server name="DB_CONNECTION" value="sqlite"\/>, <server name="DB_DATABASE" value=":memory:"\/>/g' phpunit.xml | tr ',' '\n' > phpunit2.xml
rm phpunit.xml
mv phpunit2.xml phpunit.xml
git add .
git commit -m "Updated phpunit to use sqlite database"
function authenticationScaffold {
php artisan make:auth
git add .
git commit -m "Authentication scaffolding"
composer require dczajkowski/auth-tests
php artisan make:auth-tests --without-email-verification -as
git add .
git commit -m "Authentication tests"
}
function githubAddRemoteAndPush {
git remote add origin git@github.com:DCzajkowski/$PROJECT.git
git push -u origin master
}
function createDatabase {
brew services start mysql
mysql -u root -e "CREATE DATABASE \`$PROJECT\`;"
}
if [[ "${@#-a}" = "$@" ]] then else
authenticationScaffold
fi
if [[ "${@#-g}" = "$@" ]] then else
githubAddRemoteAndPush
fi
if [[ "${@#-d}" = "$@" ]] then else
createDatabase
fi
subl .
echo -e "\e[36mEverything done! Happy coding 😎"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment