As a software developer I always tend to tune my development environments. I usually do this by using and setting keyboard shortcuts and creating workflows that works best for me.
One of the environments that is essential to me is the terminal. I spend a lot of time everyday in it compiling and testing my code. In addition to that and because I love the simplicity of the terminal, I prefer to do other things than code-related stuff in it as well. For example, I use Newsboat RSS reader to follow up my favorite blogs.
Every morning I start my day by setting up my
tmux windows and panes. The first window is for my VPN connection (Since we can do nothing without a VPN connection in Iran) and
htop. The second window is always for backend development. It usually contains a pane that belongs to
docker-compose, another for running my tests, and another for
neovim. If I do freelancing, the third window goes to frontend development and so on. Because setting it up takes a little bit of time everyday, I decided to write a bash script to create all windows and panes for me automatically.
tmux new-session -d tmux rename 'dev' tmux renamew 'vpn' tmux new-window -n 'backend' -c ~/go/src -d tmux split-window -h -t 2. -c ~/go/src -d tmux new-window -n 'frontend' -c ~/dev -d tmux new-window -n 'other' -c ~/dev/scripts -d tmux attach -t dev
Let’s see what we have in here:
- In line 1 we create a new tmux session. The
-dswitch creates the session in detached mode.
- Line 2 renames the session name to
devin this case.
- Since the session always starts with a window by default, we rename the first window name by using
renamewcommand in line 3.
- In line 4, we create the second window and name it
-coption is used to specify the current working directory for that window. As you can see a
-doption is also used to prevent switching to that window automatically.
- Line 5 splits the second window in half. The
-hoption is used for horizontal splitting. The
-tswitch is also used to specify which window should be split.
- Line 6 and 7 create two other windows named
otherwith same arguments used in line 4.
- Finally we attach what we have created to the screen using the
attachcommand. As you may have already guessed, the
-toption is used to specify which session we should attach to the screen.
The script may seem very simple, but it saves me plenty of time every day. One routing I’m trying to adopt in my life is to automate whatever is possible to be automated. I hope you do the same because it saves you a lot of time and hence you can spend that freed time doing something more important.