Skip to content

Instantly share code, notes, and snippets.

@HeshamMeneisi
Last active March 19, 2020 05:14
Show Gist options
  • Save HeshamMeneisi/0f56bb1dfd3ca3d09d304d3a02107205 to your computer and use it in GitHub Desktop.
Save HeshamMeneisi/0f56bb1dfd3ca3d09d304d3a02107205 to your computer and use it in GitHub Desktop.
Useful bash paths, aliases and functions
# START_0f56bb1d
# To Install permanently:
# curl -s https://gist.githubusercontent.com/HeshamMeneisi/0f56bb1dfd3ca3d09d304d3a02107205/raw/Productivity >> ~/.bashrc && source ~/.bashrc
# To Uninstall:
# cp ~/.bashrc bashrc.bak && perl -0777 -i -pe "s/# START_0f56bb1d.+# END_0f56bb1d//igs" ~/.bashrc
# To use temporarily:
# source <(curl -s https://gist.githubusercontent.com/HeshamMeneisi/0f56bb1dfd3ca3d09d304d3a02107205/raw/Productivity)
# Useful paths
# !! MAKE SURE TO UPDATE VERSION NUMBERS !!
export PATH=/home/$USER/.dotnet:/usr/local/cuda-9.0/bin:~/browser-drivers:~/.composer/vendor/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export ASPNETCORE_ENVIRONMENT=development
export DOTNET_ROOT="/home/$USER/.dotnet"
# PY
# pip
alias 'spip2'='sudo -H pip2'
alias 'spip3'='sudo -H pip3'
alias 'spip'='sudo -H pip'
# git
# Add all and commit
alias git-ca='f_git_ca'
# Clean branches
alias git-clean-br='git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d'
# Cache credentials for t seconds (git-cache 10000)
alias git-remember='f_git_remember'
# Squash the last x commits for cleaner history (git-squash 5)
alias git-squash='f_git_squash'
# End-of-world pull
alias git-PULL='f_git_PULL'
# End-of-world push
alias git-PUSH='git add . && git commit --amend --no-edit && git push -f'
# Need to purge some 'accidental' files/passwords from the repo?
alias bfg='java -jar /usr/bin/bfg.jar'
# Lumen / Laravel
# Do some art
alias art='php artisan'
# hotspot [password] [ssid] [network] (Not present or "" will auto-detect/generate value)
alias hotspot='create_hotspot'
## _functions
create_hotspot(){
if [ -z `which create_ap` ] ; then install_create_ap ; fi
if [ -z $1 ] ; then pw=`random_str 8` ; else pw=$1 ;fi
if [ -z $2 ] ; then ssid=$USER ; else ssid=$2 ;fi
if [ -z $3 ] ; then
nw=`iw dev | grep 'Interface ' | awk '{print $2}' | while read line; do
if [[ $line == w* ]]; then echo $line; fi
done`
if [ -z $nw ] ; then nw=wlan0 ; fi
else nw=$3 ; fi
sudo create_ap --stop $nw
echo -e "\e[32m Starting hotspot on [$nw] as [$ssid] with password [$pw] ...\e[0m"
sudo create_ap $nw $nw $ssid $pw &
}
install_create_ap(){
echo "Installing create_ap"
sudo apt-get install hostapd -y
cd ~/Downloads
git clone https://github.com/oblique/create_ap
cd create_ap
sudo make install
}
random_str(){
head /dev/urandom | tr -dc A-Za-z0-9 | head -c $1
}
f_git_ca(){
git add .
if [ -z $1 ]; then
git commit --amend
else
git commit -m "$1"
fi
}
f_git_squash(){
if [ -z $1 ]; then
echo "Must determine how many commits."
else
git reset --soft HEAD~$1
git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"
fi
}
f_git_remember(){
if [ -z $1 ] ; then
git config --global credential.helper cache
else
local t=$1
t=${t:=10000}
git config --global credential.helper "cache --timeout=$t"
fi
}
f_git_PULL(){
local b=$1
b=${b:="master"}
git stash && git fetch --all && git reset --hard origin/$b
}
# END_0f56bb1d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment