React Native Developers - Save your Time with these 24 Terminal Tricks

Ran Greenberg
Wix Engineering
Published in
3 min readSep 13, 2018
Photo by Wu yi on Unsplash

I am a React Native developer. During my day-to-day work, I found these most useful terminal tricks to be super time savers for me, so I’m sharing. Enjoy!

This list is mine .zshrc related to react-native development

General

  • Open WebStorm from the current directory

alias ws=”open -a /Applications/WebStorm.app .

  • Print all scripts section in package.json (jq is required)

alias scripts=”cat package.json | jq -r ‘.scripts’”

alias editReadme=”open -a /Applications/MacDown.app README.md”

  • Search command or part of it in the history

alias hgrep=”history | grep $1"

iTerm

  • Open .zschrc quickly

alias openzshrc=”open -a <MY_FAVOURITE_TEXT_EDITOR> ~/.zshrc”

  • Load .zschrc quickly

alias loadzshrc=”source ~/.zshrc”

React Native

  • Start the packager

alias rns=”adb reverse tcp:8081 tcp:8081 && watchman watch-del-all && react-native start”

  • Build and Launch iOS (on iPhone X)

alias rnrios="react-native run-ios --simulator='iPhone X'"

  • Build and Launch Android on the currently open emulator

alias rnrandroid="react-native run-android"

NPM | Yarn

  • Reset npm (delete node_modules and reinstall)

alias resetnpm=”rm package-lock.json && rm -rf node_modules && npm i”

  • Reset yarn (delete node_modules and reinstall)

alias resetyarn=”rm yarn.lock && rm -rf node_modules && yarn”

  • Switch between private and public npm

alias npmpublic=”npm config set registry https://registry.npmjs.org/"

alias npmprivate=”npm config set registry http://my-private-npm.com"

  • Show remote dist-tags

alias npmd="npm view $1 dist-tags"

alias yarnd="yarn info $1 dist-tags"

Android

  • Android adb reverse port 8081

alias rvrs=”adb reverse tcp:8081 tcp:8081"

  • Launch big screen Android emulator (for instance, Nexus 5X; the emulator should be preliminary installed)

alias android_big=”cd ~/Library/Android/sdk/tools/; ./emulator -avd Nexus_5X_API_25"

  • Launch small screen Android emulator (for instance, Nexus S, the emulator should be preliminary installed)

alias android_small=”cd ~/Library/Android/sdk/tools/; ./emulator -avd Nexus_S_API_25"

  • Open Android Studio from root react native app (the root should include android folder)

alias as=’open -a /Applications/Android\ Studio.app ./android’

  • Reload Android Simulator

alias rr="adb shell am broadcast -a react.native.RELOAD"

Git

  • If you use zsh you can use all Git commands that are embedded in your terminal — see all commands here
  • Open repo page in a browser

alias gh=’git config — get remote.origin.url | xargs open’

  • Reset HEAD (hard)

alias gitresethard=’git add . | echo “all added” | git reset — hard’

  • Fetch and rebase

alias gfpr=”git fetch && git pull — rebase”

  • Open SourceTree from the current directory (should include .git/)

alias stree=”/Applications/SourceTree.app/Contents/Resources/stree .”

Here is the complete list of the aliases. Copy it to your .zshrc file and remember to adjust to your application installation locations

  1. alias ws="open -a /Applications/WebStorm.app ."
  2. alias scripts="cat package.json | jq -r ‘.scripts’"
  3. alias editReadme="open -a /Applications/MacDown.app README.md"
  4. alias hgrep="history | grep $1"
  5. alias openzshrc="open -a <MY_FAVOURITE_TEXT_EDITOR> ~/.zshrc"
  6. alias loadzshrc="source ~/.zshrc"
  7. alias rns="watchman watch-del-all && react-native start"
  8. alias rnrios="react-native run-ios --simulator='iPhone X'"
  9. alias rnrandroid="react-native run-android"
  10. alias resetnpm="rm package-lock.json && rm -rf node_modules && npm i"
  11. alias resetyarn="rm yarn.lock && rm -rf node_modules && yarn"
  12. alias npmpublic="npm config set registry https://registry.npmjs.org/"
  13. alias npmprivate="npm config set registry http://my-private-npm.com"
  14. alias npmd="npm view $1 dist-tags"
  15. alias yarnd="yarn info $1 dist-tags"
  16. alias rvrs="adb reverse tcp:8081 tcp:8081"
  17. alias android_big="cd ~/Library/Android/sdk/tools/; ./emulator -avd Nexus_5X_API_25"
  18. alias android_small="cd ~/Library/Android/sdk/tools/; ./emulator -avd Nexus_S_API_25"
  19. alias as="open -a /Applications/Android\ Studio.app ./android"
  20. alias rr="adb shell am broadcast -a react.native.RELOAD"
  21. alias gh="git config — get remote.origin.url | xargs open"
  22. alias gitresethard="git add . | echo "resetting hard" | git reset —- hard"
  23. alias gfpr="git fetch && git pull — rebase"
  24. alias tree="/Applications/SourceTree.app/Contents/Resources/stree ."

Does it feel like you can add something to this list?
More then welcome to contact me on twitter @
gran33

Like it? please 👏 and share 😍

--

--