I fell in love with the terminal during my first job as a junior developer. My CTO at the time was nothing short of a wizard.
He worked magic on an old, battered MacBook Air, yet managed to accomplish everything effortlessly.
It didn’t take long for me to notice his secret: he never actually coded on his laptop. Instead, he used it as a gateway, SSHing into a high-performance EC2 instance. From there, he opened vi (not even vim!) and began typing away. In a single SSH session, he developed, tested, and deployed all the backend services for our startup.
I picked up a few tutorials on the basics of vim. And haven't looked back ever since.
Setting up a new development environment can be tedious, especially with numerous tools and plugins
Here’s a snippet of a script I use to set up my development environment.
1#!/usr/bin/env bash
2
3install_java() {
4 if [ -n "$(command -v java)" ]; then
5 echo 'Java already installed'
6 else
7 echo 'Installing Java'
8 brew install java
9 sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk \
10 /Library/Java/JavaVirtualMachines/openjdk.jdk
11 fi
12 if ! [ -d '/opt/homebrew/opt/openjdk@22/libexec/openjdk.jdk/Contents/Home' ];
13 then
14 echo 'Creating Java 22'
15 brew install openjdk@22
16 sudo ln -sfn /opt/homebrew/opt/openjdk@22/libexec/openjdk.jdk \
17 /Library/Java/JavaVirtualMachines/openjdk-22.jdk
18 fi
19}
20
21install_java_packages() {
22 if [ -n "$(command -v ant)" ]; then
23 echo 'Ant already installed'
24 else
25 echo 'Installing Ant'
26 brew install ant
27 fi
28 ...
29}
30
31install_lua
32install_python
33install_neovim
34install_node
35install_yarn
36install_ruby
37install_ruby_packages
38install_rust
39install_rust_sub_packages
40install_java
41install_java_packages
42install_tmux
43install_oh_my_zsh
44install_go
45install_markdown_preview
46...
47
48exec "$HOME/.config/bin/dev_setup"
Now I just need to clone my repository into the new machine, run the following command, and I’m good to go.
1setup
This script does the following:
Beyond this I use bash and shell scripting is to create wrappers for Git commands. These are some of the wrappers I use on a daily basis:
1# Smarter git checkout (figures out if branch exists in remote with same name)
2$ g-co -t feature/xyz
3
41. Checking pre-requisites [In Progress]
5 > Checking pre-requisites [Done]
62. Stash changes [Skipped]
73. Check out to branch feature/xyz [In Progress]
8 > Checking if branch exists in remote...
9 > Branch with name does not exist.
10 Do you want to create a new branch? (Y/n): y
11 > Switched to a new branch 'feature/xyz'
12 > Created new local branch feature/xyz. [DONE]
13
14Log file: /Users/santhosh/.config/bin/.g-co.log
15Error log file: /Users/santhosh/.config/bin/.g-co-error.log
16
17# Smarter git push (figures out which branch to push to)
18$ g-push
19
20# Smarter git pull (figures out which branch to pull from, unless specified)
21$ g-pull
22$ g-pull -t feature/xyz
23
24# Reset local branch to remote (cleans up your git tree)
25$ g-rto
26
27# Add git worktree
28$ g-wa -b develop -p ../develop;
29
30# and so on...
31
Another way I use bash and shell scripting is to simplify complex build processes. For example, I have a script that automates the building and deployment of my applications.
For example, At Whatfix, we have a complex dev environment setup. Doing it manually every time you need a fresh setup is a pain. So I automated away the pain (for the most part) with a script that does the setup for me.
Here is a runtime preview of the script:
1$setup_wfx_repo
2__ _________ __ ____ _____ _____ _ _ ____
3\ \ / / ___\ \/ / / ___|| ____|_ _| | | | _ \
4 \ \ /\ / /| |_ \ / \___ \| _| | | | | | | |_) |
5 \ V V / | _| / \ ___) | |___ | | | |_| | __/
6 \_/\_/ |_| /_/\_\ |____/|_____| |_| \___/|_|
7
8Checking pre-requisites...
9All pre-requisites are satisfied. [DONE]
10All repositories are in place
11
12fix_all_repos: y
13stash_changes: y
14skip_branch_checkout: n
15branch: develop
16fallback_branch: master
17sync_with_remote_branch: n
18skip_module_x: n
19skip_module_y: n
20...
21point_to: uataz
22
23Use current configuration (Y/n): n
24Skip branch checkout (Y/n):
25Fix all repos (Y/n):
26Point to (uataz): prod
27
28Fixing module_x
29 - Updating yarn and yalc path
30 - Removing <module> build
31 - Updating .info file
32 - Removing firefox and safari build
33 - Fixing .properties file
34 - Set /Users/santhosh.kumarsiva/.nvm/versions/node/v21.6.0/bin/yarn
35 and /opt/homebrew/bin/yalc paths
36 - Fixed <module> errors
37 - Updated wfx info to use subdomain.domain.com
38 - Removed edge, firefox and safari builds
39
40...
41
42Done
If you’re new to bash and shell scripting, here are a few tips to get started:
Here are a few tools that I use to make my life easier:
Bash and shell scripting are powerful tools that can help you automate your daily tasks and improve your productivity. By leveraging these tools, you can streamline your workflow and focus on the tasks that matter most.
What tasks in your workflow could you automate today? Start small, experiment, and see how scripting can make your life easier.