Skip to content

Instantly share code, notes, and snippets.

@OlivierFreyssinet
Created June 16, 2021 14:18
Show Gist options
  • Save OlivierFreyssinet/5d5c03e09c9c9e782029f73a224ee980 to your computer and use it in GitHub Desktop.
Save OlivierFreyssinet/5d5c03e09c9c9e782029f73a224ee980 to your computer and use it in GitHub Desktop.
# ______ _ ___ __ __ _
# | ____| \ | \ \ / / / _(_)
# | |__ | \| |\ \ / / ___ ___ _ __ | |_ _ __ _
# | __| | . ` | \ \/ / / __/ _ \| '_ \| _| |/ _` |
# | |____| |\ | \ / | (_| (_) | | | | | | | (_| |
# |______|_| \_| \/ \___\___/|_| |_|_| |_|\__, |
# __/ |
# |___/
#
# if you want to set secrets (API tokens etc.) maybe put them in a separate config file so you can share your .bash_profile easily w/ someone else
# the "2> /dev/null" just redirects the error output of that command in case that file doesn't exist
source ~/.bash_profile_secrets 2> /dev/null
export MAVEN_HOME="/opt/local/bin/apache-maven-3.3.9"
export SFML_HOME="~/Software/SFML-2.4.2.bin"
export PATH=".:~/.scripts:/opt/local/bin:/opt/local/sbin:$HOME/bin:$PATH:$MAVEN_HOME:$SFML_HOME:/bin:~/.npm-global/bin"
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
bold="" #$(tput bold) # This is disabled because it was causing some formatting issues on the lines following user prompt
normal="" #$(tput sgr0) # This is disabled because it was causing some formatting issues on the lines following user prompt
reverse="" #$(tput smso) # This is disabled because it was causing some formatting issues on the lines following user prompt
noreverse="" #$(tput rmso) # This is disabled because it was causing some formatting issues on the lines following user prompt
# This shows the prompt like this: "[username@machinename] currentDirName (branch name in green if in a git repo) $ "
# it might not work in zsh
export PS1="${reverse}${bold}[\u@\h] \W${noreverse}\[\033[32m\]\$(parse_git_branch) \[\033[00m\]\$ ${normal}"
export JAVA_HOME="/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home"
eval $(/usr/libexec/path_helper -s)
# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH
CLASSPATH=$CLASSPATH:"/Library/Java/Extensions/jade/lib/jade.jar"
CLASSPATH=$CLASSPATH:"/Library/Java/Extensions/Jess71p2/lib/jess.jar"
CLASSPATH=$CLASSPATH:"/Library/Java/Extensions/Jess71p2/lib/jsr94.jar"
export HISTTIMEFORMAT="%d/%m/%y %T "
export CLASSPATH
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
export WORKSPACE=$HOME/Workspace
export BLLOC=$WORKSPACE/Blloc
export BLLOCOSN=$BLLOC/bllocosn
echotime() {
now=$(date +"%T")
echo "Current time : $now"
}
# _____ _ _ _
# / ____| | | | | |
# | (___ | |__ ___ _ __| |_ ___ _ _| |_ ___
# \___ \| '_ \ / _ \| '__| __/ __| | | | __/ __|
# ____) | | | | (_) | | | || (__| |_| | |_\__ \
# |_____/|_| |_|\___/|_| \__\___|\__,_|\__|___/
#
#
alias python=python3
alias pip=pip3
alias logwatchman='tail -f /usr/local/var/run/watchman/olivier-state/log'
# open bash_profile in vscode
alias bashprofile='code ~/.bash_profile'
# load bash_profile (prevents having to open a new terminal to use changes)
alias bashprofilesource='source ~/.bash_profile'
# open local gradle.properties file
alias gprops='code ~/.gradle/gradle.properties'
# _ _ _ _ _
# | \ | | (_) | | (_)
# | \| | __ ___ ___ __ _ __ _| |_ _ ___ _ __
# | . ` |/ _` \ \ / | |/ _` |/ _` | __| |/ _ \| '_ \
# | |\ | (_| |\ V /| | (_| | (_| | |_| | (_) | | | |
# |_| \_|\__,_| \_/ |_|\__, |\__,_|\__|_|\___/|_| |_|
# __/ |
# |___/
#
# Stuff to navigate easily between directories
#
# Just some shortcuts for navigating quickly in frequently visited directories
alias cdsdk='cd /Users/olivier/Workspace/Blloc/ratio-sdk'
alias cdwebviewplayground='cd /Users/olivier/Workspace/Blloc/webviewPlayground'
alias cdbllocosn='cd $BLLOCOSN'
alias cdw='cd $WORKSPACE/whatsplayin'
alias cdws='cd $WORKSPACE/whatsplayin-server'
alias cdr='cd $BLLOC/r4tio'
alias cdn='cd $BLLOC/ratioNative'
alias br='cd $BLLOCOSN/android/app/build/outputs/apk/release && pwd'
alias bro='cd $BLLOCOSN/android/app/build/outputs/apk/ && open .'
# something related to the "lf" file explorer, this function makes it automatically `cd` the
# dir where the explorer is when the "lf" process terminates, makes up for easy navigation
# https://formulae.brew.sh/formula/lf
lfcd () {
tmp="$(mktemp)"
lf -last-dir-path="$tmp" "$@"
if [ -f "$tmp" ]; then
dir="$(cat "$tmp")"
rm -f "$tmp"
if [ -d "$dir" ]; then
if [ "$dir" != "$(pwd)" ]; then
cd "$dir"
fi
fi
fi
}
alias lf='lfcd'
#
# _____ _ _ _
# | __ \ | | | | (_)
# | |__) |___ __ _ ___| |_ _ __ __ _| |_ ___ _____
# | _ // _ \/ _` |/ __| __| | '_ \ / _` | __| \ \ / / _ \
# | | \ | __| (_| | (__| |_ | | | | (_| | |_| |\ V | __/
# |_| \_\___|\__,_|\___|\__| |_| |_|\__,_|\__|_| \_/ \___|
#
# Some stuff to help with React Native apps development
#
alias rndevtools='react-devtools & adb reverse tcp:8097 tcp:8097'
alias rn='npx react-native'
alias rna='npx react-native run-android'
alias rnaRatio='npx react-native run-android --variant=ratioDebug && echotime'
alias rnaRatioLight='npx react-native run-android --variant=ratioLightDebug && echotime'
alias rnaZ18='npx react-native run-android --variant=z18Debug && echotime'
# useful for forwarding TCP ports for React Native
alias adbr='adb reverse tcp:8081 tcp:8081' # use this one so that the running RN app can find the locally running Metro bundler
alias adbrd='adb reverse tcp:8097 tcp:8097' # I think this is for remote debugging but useu
# _____ ____
# /\ | __ \ | _ \
# / \ | | | | | |_) |
# / /\ \ | | | | | _ <
# / ____ \ | |__| | | |_) |
# /_/ \_\ |_____/ |____/
#
# Just some nice stuff to make your life easier as an Android dev
#
# some colored adb logcat, but i think it's shit as it doesn't always work properly
alias blloccat='adb logcat -v color --pid=`adb shell pidof -s com.bllocosn`'
alias blloccatd='adb logcat -v color --pid=`adb shell pidof -s com.bllocosn.debug`'
alias blloccatdumb='adb logcat -v color *:E | grep `adb shell pidof -s com.bllocosn`'
# killing apps on adb
alias kb='adb shell am force-stop com.bllocosn'
alias kbd='adb shell am force-stop com.bllocosn.debug'
alias ks='adb shell am force-stop com.spotify.music'
alias kbdev='adb shell am force-stop com.bllocosn.releasedev'
alias adbkill='adb shell am force-stop '
# list adb devices
alias adbd='adb devices'
# get local wlan IP adress of phone connected through adb
adbgetip()
{
adb shell ip addr show wlan0 | grep inet | grep wlan0 | xargs | cut -d' ' -f2 | cut -d'/' -f1
}
# very nice one that sets up adb wirelessly
# 1. plug your android device with remote debugging enabled
# 2. type `adbconnectwithwifi`
# 3. you can now unplug your phone and it's still connected w/ adb
adbconnectwithwifi()
{
adbgetip | ( adbip=$(</dev/stdin); echo $adbip; adb tcpip 5555; sleep 3; adb connect "$adbip:5555" )
}
# some shortcuts for my lazy ass
alias adbwifi='adbconnectwithwifi'
alias adbw='adbconnectwithwifi'
# directly connect adb to a known IP -> for this to work, the phone needs to have been connected to the computer at least once since it (the phone) booted
alias adbwo='adb connect 192.168.2.6:5555' # Office phone IP
alias adbwh='adb connect 192.168.178.53:5555' # Home phone IP
alias adbwhh='adb connect 192.168.0.48:5555' # Home secondary phone IP
# launch an scrcpy session (to control android device from computer) (requires scrcpy to be installed: https://github.com/Genymobile/scrcpy)
alias adbcontrol='scrcpy -m1024 -b 32M'
alias adbc='adbcontrol'
alias adbcontrolbig='scrcpy -m4096 -b 32M'
alias adbcontrolwifi='scrcpy -m512 -b 8M'
# toggle dev preferences 'show touches' to display the taps on the phone screen (helpful for screen recordings)
alias adbtouchesON='adb shell content insert --uri content://settings/system --bind name:s:show_touches --bind value:i:1'
alias adbtouchesOFF='adb shell content insert --uri content://settings/system --bind name:s:show_touches --bind value:i:0'
# start battery historian (Android battery profiling tool: https://github.com/google/battery-historian)
alias batteryhistorian='docker -- run -p 7777:9999 gcr.io/android-battery-historian/stable:3.0 --port 9999'
alias batteryhistorianhelp="echo 'docs > https://github.com/google/battery-historian' && echo 'cmdline > adb bugreport bugreport.zip' && echo 'reset > adb shell dumpsys batterystats --reset'"
# alias runemu="cd /Users/olivier/Library/Android/sdk/tools/ && emulator @device -writable-system &"
alias runemu='cd /Users/olivier/Library/Android/sdk/tools/ && emulator @Nexus_5X_API_28 -writable-system -gpu on &'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment