1. Intended audience.
This article is for every programmers, who want to make their day to day command line experience cool as well as more productive.
2. Overview.
As a programmer, we always use terminal for git, navigating through directories, running servers etc. Why not take some time out and make this basic tool more productive and cool, thats what we are going to do in this article.
Note: To save in nano hit control+o and hit return, to exit hit control+x
3. Step-1: Download Iterm2 and Oh-My-Zsh.
- Download Iterm2 from its official website and install it. iTerm2 is a replacement for MacOS default Terminal
- MacOS now by default uses zsh, so we just need to install oh-my-zsh which is a framework for managing zsh configurations. Install it by using entering the following command
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
4. Add VsCode Shortcut.
- Run
nano ~/.zshrc
to open and edit zsh configuration files- To open vscode in PWD using "code ./" add the following line in your .zshrc:
# vscode
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
5. Add theme
Theme Credit: https://github.com/stefanjudis/dotfiles/blob/primary/config/oh-my-zsh/stefanjudis.zsh-theme
This theme will have random emoji at prompt section and will also display current git branch.
- Make a new theme file using
nano ~/.oh-my-zsh/themes/ishanextreme.zsh-theme
Copy and paste theme code from here to "~/.oh-my-zsh/themes/ishanextreme.zsh-theme" file
Finally run
nano ~/.zshrc
and setZSH_THEME="ishanextreme"
Run
source ~/.zshrc
to reload and apply changes.
6. Plugins
Here's the list of plugins I use
- git
- zsh-autosuggestions
- sudo
- zsh-syntax-highlighting
tutorial to add plugins here
7. Style ITerm2
- Open ITerm2 and hit
⌘ ,
go to "Appearance" tab and set theme to "Minimal".
- Color theme used: Blue Matrix
Next lets setup status bar, open settings (⌘ ,) then go to profiles tab select "Default" profile select "Session" tab from it and click on enable status bar("status bar enabled"), and finally start configuring it. Here's the list of things we will add to our status bar:
- Github current branch: drag "git state" from status bar component menu to active components(down). You can configure colors of component by selecting them and clicking "configure component" option at bottom.
- Current Working Directory: drag "Current Directory" component to active components list.
- Current conda environment: (If you have anaconda installed) or you can use this method to display any information(like node version, etc).
- Enable Shell Integration from ITerm2->Install shell integration. Note-> this will enable a blue prompt by default in terminal you can disable it, search "show mark indicators" setting and disable it.
- Now you can create your own variable and display them using "Interpolated Strings".
- Run
nano ~/.zshrc
and add the followingiterm2_print_user_vars() { # extend this to add whatever # you want to have printed out in the status bar # if you don't have anaconda install use it for displaying # your node version "echo node -v" or anything you like iterm2_set_user_var condaEnv $(echo $CONDA_DEFAULT_ENV) iterm2_set_user_var pwd $(pwd) }
- Now use this variable in status bar, again open configuration setting for status bar, drag "Interpolated String", click on configure component and input
\(user.condaEnv)
in "String value" field.
7. Adding and enabling scripts.
In this step we will add some useful scripts to our ITerm and will also add shortcuts for the same.
- Run
cd /Users/"your user name"/Library/Application\ Support/iTerm2/Scripts
, open any editor in this directory, create a new file "awesome_scripts.py" and copy the code from here to the editor and save the file (take care of identations, its a python code).- This will add globally callable functions which can be added as shortcuts, you need to everytime enable this scripts when you open ITerm window from scripts->awesome_scripts
- Now to add schortcut to touchbar, hit
⌘ ,
got to Keys tab, click add Touch Bar Item.- Give it a label(use fn for emojis), Under actions field choose "Invoke Script Function" now add the function name to "Function Call" field. (See function name and there action below)
- To customize touch bar, go to view->Customize Touchbar, you can see all your newly created shortcuts, drag and add them. (Tip: Remove siri icon to make more space in touchbar 😉)
List of function calls and their actions:
clear()
: It will run "clear" command on all the sessions in a particular tab.start_server()
: It will run "yarn start:qa" on all the sessions in a particular tab.stop_servers()
: It will run "killall node" and "clear" on all the sessions in a particular tab.shutdown()
: It will kill all processes in every tab and force closes ITerm window.git_push()
: To use this make sure you have the theme in Step-5 installed. It will run "git add -A", "git commit -m'random emoji in your current line of ITerm'" and "git push origin 'your current branch'" in only your current session.git_pull_staging()
: It will run "git pull origin @staging --ff" in all the sessions in your current tab.
Top comments (0)