How to Move on from the Mundane?

Based on my experience, I’d like to share a couple of approaches I follow to reduce the time spent on unnecessary tasks. What do I mean by this? Tasks which aren’t related to a project but still consume a significant portion of a developer’s time. Go ahead, use this time to read posts on HN and medium.

Create Aliases: Alias is used to shorthand a command or a group of commands.

Let’s take an example where we need to connect to the VPN every time we’re starting our day, using the following command:

sudo openvpn — config /home/user/Work/vpnconfigs/test.ovpn

This command can also be reverse searched using (Ctrl+R) but that also requires typing some characters & in some cases, we may end up typing nearly half the command before we find it.

Alias could be used to shorten this verbose command.

To create an alias:
$alias rvpn=”sudo openvpn — config /home/user/Work/vpnconfigs/test.ovpn”

Now, on terminal, we just need to type “rvpn”.

$rvpn

And that’s it. We just reduced a cumbersome command to a short and easy to remember one.

Similarly aliases could be shorten other commands.

eg: $alias connect_test=”ssh user@X.X.X.X”

$alias nginx_conf=”sudo gedit /etc/nginx/nginx.conf”

$alias tail_log=”tail -f /home/user/Work/project/logs/gunicorn/access.log”

Aliases could also be chained together using a “;” or “&&”.

To load a virtual environment and also quickly move to the directory of the project:

$alias load_project= “source /home/user/Work/project/bin/activate;cd /home/user/Work/project”

Following are a few examples one could use alias for:

  • VPN connect (Alias: connect_vpn)
  • Open a configuration file (Alias: nginx_conf, settings_json etc)
  • Tailing log files (Alias: tail_access, tail_error etc)
  • SSH connections( Alias: connect_test, connect_staging, connect_prod)

Note that these aliases created aren’t permanent. To be able to use them everytime system is started, all the alias commands could be added to /etc/bashrc file

Create Symlinks and utilize Bookmarks:
Symlinks are shortcut to files or folders.

Example of some symlinks:

~/Work/sym$ln -s /etc/nginx/nginx.conf nginx.conf

~/Work/sym$ln -s /home/user/Work/project_part1 project_part1

Just create symlinks to whatever is needed for a project in one folder and bookmark it in explorer. It might look very naive at first glance, but overall it saves a lot of time, especially if you realize that you go have to forward and backward a directory structure for more than 2–3 levels.

Shell script Launchers:

To start work on a project, we usually need the following things opened:

  • Running development server
  • A couple of Logs tailed
  • Database clients
  • IDE or editor (Sublime,Eclipse etc)

Running the following script opens a terminal with 3 tabs (log,mongodb,server) and a editor environment. It saves a lot of time which is wasted in opening these manually.

#!/bin/bash
op=””
tab=” — tab”
#Tail log files
cmd=”bash -c ‘cd /home/user/Work/logs;tail -f access.log;bash”
op+=($tab -e “$cmd”)
#Open databases
cmd=”bash -c ‘mongo’;bash”
op+=($tab -e “$cmd”)
#Run servers
cmd=”bash -c ‘cd /home/user/Work/project;export CUST_VAR=$CUST_VAR:val;python manage.py runserver’;bash”
op+=($tab -e “$cmd”)
gnome-terminal “${op[@]}”
subl “/home/user/Work/project”
exit

Shell Script Click execute:

Goto Edit>Preferences in file explorer. Under “Behavior” tab, either set executable files to always run or ask each time. So the shell script created above could be placed on a desktop and executed using double click, to avoid opening a terminal and then running it.

I’m going to be writing a lot more & you should definitely watch this space for more. After all, these hacks might as well be termed life hacks. Won’t you agree?

Stay Tuned!