Create your commands to Boost your productivity.

Mudit Sen
3 min readSep 20, 2023

--

As a developer we often use many terminal commands and often same commands repeatedly. Some commands are bit complicated and hard to remember and sometime we end up writing those commands in different order and end up in state of stress. To solve this problem we have two solutions

First: Create command aliases.

Type aliases are easy to create. For example as to push code on Gerrit I usually use this

git push origin HEAD:refs/for/$(git rev-parse — abbrev-ref HEAD)

command. To create a type alias for this just run

alias <string>=<command> i.e.

alias almighty-push='git push origin HEAD:refs/for/$(git rev-parse — abbrev-ref HEAD)'
#command push code when using Gerrit.

But this will only work for the current terminal session. To make this work every-time you need to:

  1. Create a .bash_profile file in your home directory if not present already.
  2. Paste the given alias command in your .bash_profile.
  3. Save and exit.
  4. In terminal run command
source ~/.bash_profile

Note: You can add multiple aliases in this file and can run in anywhere you like.

Second: First solution can solve small problems but if you have n number of commands and you also want add or create arguments in your command or have some logic how your command behaves than creating a shell script is an another option. For that you have to learn basic of shell scripting like conditional statements or you can just use chat GPT.

A simple example goes like:

  1. To begin, create a folder name mycommands in your home folder.
  2. Create a file “myInfo” in mycommands folder, without any extension.
  3. Copy paste this code.

#!/bin/bash
# Get laptop information
hostname=$(hostname)

# Get user information
current_users=$(who)

# Print the laptop information
echo “Laptop Information:”
echo “Hostname: $hostname”
echo “Operating System:”

sw_vers

echo

# Print user information
echo “Currently Logged-In Users:”
echo “$current_users”

4. Run command: this command will convert this file into executable. You can still open myInfo in text view.

chmod +x ~/mycommands/myInfo

Now we have to set the path of mycommands folder into .bash_profile. To set or append your PATH variable.

  1. Create .bash_profile if not already present in your Home folder.
  2. Write

export PATH=”$PATH:~/mycommands/”

3. Save and close the .bash_profile file.

4. Run command in your terminal

source ~/.bash_profile

Close all terminals and now run command

myInfo

It will print your Laptop Information in mac.

Read other articles:

  1. https://muditsen.medium.com/mix-in-pixel-for-android-ab30effd1da1
  2. https://muditsen.medium.com/finding-apps-which-can-handle-a-deeplink-ab45e2ec1180

--

--

Mudit Sen
Mudit Sen

Written by Mudit Sen

Android || React Native || Spring

No responses yet