Let’s explore: what is a shell and terminal?


I still feel new to the world of terminals, consoles, and yes, shells. Being a Java engineer for 12 years really didn’t expose me much to these concepts in my day-to-day work, but now as a Ruby on Rails engineer, it is my preferred way of interacting with my tests, servers, get and any other command/app or API I might need to use. With Java, my day was just composed of working in my IDE (Integrated Development Environment) which was Eclipse or pretty much Eclipse (I’m looking at you Spring Tool Suite). So sometimes I really feel like I am at step one when I start hearing folks discuss bash vs zsh or vim vs emacs, admittedly I am not quite sure what a kernel is either.

What is a shell?

So I thought I would take myself to step one, and answer the question, what even is a shell? It seems like something that is mixed up with a terminal, and frankly I can’t keep them apart. So let’s untangle that mess.

University of Chicago professor Benjamin Soltoff has a great write-up about this, which summerizes:

The shell is a program on your computer whose job is to run other programs, rather than do calculations itself. The shell is a very old program and in a time before the mouse it was the only way to interact with a computer. It is still extremely popular among programmers because it is very powerful, fast, and is particularly powerful at automating repetitive tasks.

https://cfss.uchicago.edu/setup/shell/

So it is a helps with interactions between programs, maybe even programs and the operating system (OS), clear as mud there. Maybe by tracking down the definitions of terminal, and console, it might make more sense.

What is a terminal?

According to The Linux Information Project

terminal window, also referred to as a terminal emulator, is a text-only window in a graphical user interface (GUI) that emulates a console.

http://www.linfo.org/terminal_window.html

Ok. so a terminal (for example iTerm2, Window Terminal, Linux console) allows a user to enter text and use commands through command-line interfaces (CLI) and text user interface (TUI) applications.

Ok, so terminal might be the application you open for running such commands as git commands, or booting up your rails server. I know on my system my terminal is iTerm2. Adding in what we now know about shells and terminal, it seems like these two definitely work together. So the terminal is where your shell is used. They are pretty intertwined, in that you can’t really use your shell without a terminal! No wonder people have a hard time breaking them down.

How do I tell what I am using?

Well in the case of the terminal, what is the application you are opening up? For me, I know because I am hitting the little iTerm icon!

iTerm’s icon

Try searching for “Terminal” on your OS, and see what pops up. The default MacOS Terminal app is usable for when you want to dip your toes finding out what a terminal is about, but most devs prefer something a little bit more customizable.

In the case of your shell, you need to boot up your terminal app and put in a command. One to try could be echo $SHELL (echo is a command to output that argument of $SHELL which should correspond to what is our system level shell program in use). Or give echo $0 a go. Testing out those commands shows that I am using a bash shell:

Trying out echo $SHELL in my iTerm2 terminal, and getting a /bin/bash result

You might see zsh or something else, but don’t worry if you want to change it. There are many resources to help you out.

But what should I use?

That’s the great thing, it’s up to you! This is one of those programming things that a lot of people have a lot of opinions on. Frankly, I think start using one, and see what works for you. I have been using bash for years, or at least I think it is years, because I can’t recall when I might have installed it so that probably means it has been a while. If you see something that looks interesting in another shell, try it out for a while! Maybe you will find it does help you in some way. If not, at least now you are more familiar with multiple shells.

Here’s some shell options but let me know, what’s your favorite shell and why?

Git workflow and my new love of Git alias

For good or bad, my current Git workflow does not include merges, but rebasing.

It keeps the history cleaner, works with the established workflow (pretty standard GitHub flow) just no merge commits.  I was trying to find a nice graph of the master branch, but coming from a GitLab background it isn’t hard to find this information in the GitLab repo, but I don’t think GitHub really has this history feature. Anyone know the best way figuring out the history on GitHub?

We really enforce making sure to have meaningful commits, and commit messages. When you are working on your local branch, feel free to commit away, but an interactive rebase is needed before requesting your pull request. After you have done a couple of these rebases, there really isn’t anything to be afraid of. I hadn’t done one, and let me tell you, my first pull request was pretty painful. I think getting through the review process on that, and getting my commit history clean took just as long as coding my feature >_<. Now me, rebases, and amends are friends.  I haven’t had a chance to use fixup commits yet, but they are something on my raider to try out soon!

I enjoy using Git bash for my source repository needs.  Even with my more advanced workflow at my company, for me it has the most flexibility.  I have given Sourcetree (works better with BitBucket then GitHub) and Git Kracken a try before, and it is nice to have visuals when you need to deal with complex conflict situations, but I keep on going back to my trusty Git Bash.  I never used to be a command line person, just in certain situations, but now especially since I have switched over to Ruby and Rails I have at least 3-4 terminals open at anyone time. I even exited Vim yesterday without having to look it up! I feel that should be some sort of milestone.

 

 

 

 

 

 

Also I have been making use of GIT CLI alias, also installed multiple scripts to run in the terminal (terminal parrot I’m looking at you!).  Some of these help me with my job more then others :). If you don’t have a git alias, get yourself one stat. You just need to add lines to ~/.gitconfig

[alias]
    st = status
    ci = commit -v

Some of my personal favorites right now are:

st = status
co = checkout
dm = diff –patience master
prb = pull –rebase
pu = pull –rebase origin master
pf = push –force-with-lease
po = push origin master

What’s in your Git alias? And also how awesome is Command+Option+Shift+V on MacOS? That was the key to my problem with copy and pasting text and not keeping the old formatting!