is a terminal app I use to run everything in my MacOS. iTerm2 is a replacement for Terminal providing a lot of features with variety of themes that changes the look and feel. I run everything in iTerm2, from git commands to running live servers, searching texts end edit files. But one thing is always disturbing me— running long processes. Long processes alway hide the current prompt and with it the working directory. I installed and it added this nice prompt that displays the current working directory and the git branch I’m using, but when running long processes the prompt gets out of the buffer zone an I’m left clueless. iTerm2 Oh My Zsh Everything loses context in the terminal once you run a process — the status bar shows the running task and if the task is verbose enough the prompt gets out of the buffer zone and is not visible. The status bar, the tab name and everything I can think of just wont show the current working directory or anything about where I’m at. I can not even run because a process is running. pwd One thing I often do is running tasks with at the end of the command, for example , which runs the process in the background and leave the prompt available for interactions. You can run a several process in parallel by adding between them. When a process runs in the background you can not break it with , instead you need to explicitly kill it with or command. I am running sometimes but that kills all of the node processes running everywhere. & npm i & & cmd+C kill [pid] killall [name] killall node To kill a specific process you need to know the pid and to to do that you need to remember what you are running. You can run to get the pid, for example will give you all the node processes. iTerm2 provides a panel that shows all the processes with the pids . Just hit or , then check the to see the jobs panel containing the names of the processes and the pid for each one. ps -ef | grep [what you are running] ps -ef | grep node for every panel cmd+shft+B Toolbelt → Show Toolbelt Toolbelt → Jobs To kill a process you can select it and press , or execute in the console knowing the exact pid from the panel. select signal → kill kill [pid] One small problem I have with running many processes in parallel is the output — its not neat and hard to understand because the output stream get updates from different processes. I prefer to run a blocking processes and just know where I am at all time. There is a solution to the problem using iTerm2 badges. A badge is a large text label that appears in the top right of a terminal session. You can update that text using . iTem2 → Preferences → Profiles → General → Badge The badge can have static value, like in the example above, and dynamic value via script variables. Lets try to achieve what we wanted in the first place, we will try to set the badge to the following: just like I have in my prompt. [git repo] git:([git branch]) We would like to create some kind of a variable that will contain the text, and set it to the badge field. To create and update variables we need to install the iTerm2 . It is a common integration and can be installed with . shell integration iTem2 -> Install Shell Integration Shell integration allows to create variables and use them, we would like to create a variable that will hold the badge text just as we described. In the configuration startup script, for me it’s add the following: ~/.zshrc, iterm2_print_user_vars() {iterm2_set_user_var gitStatus "$(gitStatus)"} function getGitStatus { [[ $(git status 2> /dev/ ) = "" ]] thenecho "$(topDir)" echo "$(getGitProjectDir)$(topDir) git:($(getGitBranch))$(isGitBranchDirty)"fi} function if null else getGitProjectDir {basename $(git rev-parse --show-toplevel 2> /dev/ ) 2> /dev/**null**} function null topDir { [[ $(basename $(pwd)) = $(getGitProjectDir) ]] thenecho "" echo "/$(basename $(pwd))"fi} function if else getGitBranch {basename $(git branch 2> /dev/ | grep \* | cut -c3-) 2> /dev/**null**} function null isGitBranchDirty {[[ $(git diff --shortstat 2> /dev/ | tail -n1) != "" ]] && echo "⚡ "} function null The first function — is the main function here and will run after any command running in the terminal. It updates variable with what we wanted using the following functions: item2_print_user_vars gitStatus — returns the current directory if it’s not a git repository. getGitStatus — returns the git repo name. getGitProjectDir — returns the current directory if it’s not the main repo folder. It is useful for monorepos when the real project in a subdirectory in the main repo directory. topDir — returns the current git branch. getGitBranch — return “⚡ “ if we have panding changes. isGitBranchDirty Now to use the variable we created we just need to add it to the badge text as we did before with a static value. we will add it as the badge text in insert and walla! next time anything changes you will see it in a badge in you terminal and never lose you head. iTerm2 →Preferences →Profiles →general →Badge \(user.gitProjectDir)