DEV Community

Bigyan Thapa
Bigyan Thapa

Posted on • Edited on

Mistakes made and lessons learnt - bash to zsh

Bash to zsh

Recently, I migrated from using bash go zsh as most of us did.

chsh -s /bin/zsh easy right :)

But somehow I managed to break my terminal in the process of setting up AndroidStudio. I am not a shell pro but I like to keep couple of adb and git commands as alias, so that I can use AndroidStudio Terminal or System Terminal to perform quick actions. All, I wanted to do was to add the path to android-sdk and platform-tools to the system path so that all the adb commands would be recognized and life would be simple. But somehow I managed to break it.

These are the steps I took to kind of migrate everything my .bash_profile had over to zsh.

Setting up Android SDK and platform path

  • create .zshrc file -> nano ~/.zshrc

  • add the path to zshrc . We can open and edit this file in TextEditor or edit it in the terminal itself like:

    • vi ~/.zshrc ,then press i for insert, paste the path, then :wq for write and quit.
    • something like below:
export PATH='$PATH:/~YOUR_HOME/Library/Android/sdk'
export PATH='$PATH:/~YOUR_HOME/Library/Android/sdk/platform-tools'
  • At this point, most of you might already notice the mistake in the above snippet. Somehow, having the quotes broke everything and nothing worked. When I say nothing, I mean the cd, ls, cd .. etc. commands from the system's zsh (/bin/zsh) also didn't work. Once, I delete these two lines, everything would work and I would be where I started, i.e. adb commands wouldn't work.

  • The key to this was to remove the quotes surrounding the path. Once I removed those, everything started working fine.

export PATH=$PATH:/~YOUR_HOME/Library/Android/sdk
export PATH=$PATH:/~YOUR_HOME/Library/Android/sdk/platform-tools
  • One way to verify this is to check the path in the terminal, and the path now should include path to android-sdk and platform-tools, this is the command echo $PATH.

Setting up .zprofile corollary to .bash_profile

  • create .zprofile file -> nano ~/.zprofile
  • add the aliases to .zprofile . We can open and edit this file in TextEditor or edit it in the terminal itself like:
    • vi ~/.zprofile ,then press i for insert, paste the path, then :wq for write and quit.

Bonus - some aliases that I use

# Git Commands
alias gf='git fetch'
alias gp='git pull'
alias gs='git status'
alias gcd='git checkout develop' #or master if you have master

# Gradle Commands
alias at='./gradlew assembleDebug assembleAndroidTest'
alias allTest='./gradlew assembleDebug testDebugUnitTest'
alias cbc='./gradlew cleanBuildCache'
alias build='./gradlew build'
alias stop='./gradlew --stop'
alias status='./gradlew --status'

# ADB Commands
alias devs='adb devices'
alias kill='adb kill server'
alias restart='adb restart server'

Please comment if there better ways of doing this and feel free to add more helpful aliases.

Thank you!

Top comments (2)

Collapse
 
fayefossegrim profile image
Fäyè Fossègrim

THANK U BABE ! JUST WHAT I NEEDED <3

Collapse
 
hydranix profile image
Hydranix

You need to use double quotes for variable expansion to work properly.

Single quotes takes the string litterally.