Macos Terminal Zsh Separate History For Each Window

Posted on by
Macos Terminal Zsh Separate History For Each Window Rating: 3,5/5 5966 reviews

Bash Profile Configuration. The profile file is run during boot-up to configure the terminal to define file path, shims, and autocompletion handlers. This is the single biggest frustration with people using Linux on Mac. One of the earliest articles on bash here shows shell variables, environment variables, and aliases. Each operating system has its own file name for its profile. The only (visual) difference to my bash prompt is the% instead of the $. Note: creating a file /.hushlogin will suppress the status message at the start of each Terminal session in zsh as well as in bash (or any other shell). Basic Prompt Configuration. The basic zsh prompt configuration works similar to bash, even though it uses a different syntax.The different placeholders are described. Close, quit and re-open iTerm; run nano.zshhistory; use the arrow keys to navigate to the part of your history you'd like to delete.; use the delete key to remove all unwanted history logs.; Once you've removed everything you'd like to remove, select control X to Exit.; You'll be prompted to Save the changes. If you're happy with your changes click shift Y.; You'll be asked where you'd like.

by Chiamaka Ikeanyi

Sometimes, using the default terminal sucks. You want to go out of the ordinary, to add life to the boring terminal and improve your productivity.

Z shell (Zsh) is a Unix shell built on top of bash (the default shell for macOS) with a large number of improvements.

In this walk-through, we will configure iTerm2 with ZSH and its dependencies. This is a no-brainer, and after this, you’ll ponder the reason for not discovering ZSH earlier. Well, since you’re here already, let’s kick-start this.

Keynotes

  • Homebrew installation
  • iTerm2 installation
  • ZSH and Oh My ZSH installations
  • Setting up the dependencies to create a beautiful terminal

Step 1: Install Homebrew

Homebrew is a free and open-source software package management system that simplifies the installation of software on Apple’s macOS.

Before installing Homebrew, we need to install the CLI tools for Xcode. Open your terminal and run the command:

If you get an error, run xcode-select -r to reset xcode-select.

Then, install Homebrew.

Step 2: Install iTerm2

iTerm2 is a replacement for terminal and the successor to iTerm. Most software engineers prefer iTerm2 over the default terminal that ships with macOS as a result of its cool features. You can integrate zsh into iTerm2 to increase productivity.

To install iTerm2, run the command:

Step 3: Install ZSH

Zsh is a shell designed for interactive use, although it is also a powerful scripting language.

By default, macOs ships with zsh located in/bin/zsh.

Let’s install zsh using brew and make iTerm2 use it.

Step 4: Install Oh My Zsh

“Oh My Zsh is an open source, community-driven framework for managing your zsh configuration. It will not make you a 10x developer…but you might feel like one”
— Robby Russell

It runs on Zsh to provide cool features configurable within the ~/.zhrc config file. Install Oh My Zsh by running the command

Check the installed version

You can upgrade it to get the latest features it offers.

Macos Zsh Profile

Restart iTerm2 to dive into the new experience of using Zsh. Welcome to the “Oh My Zsh” world ?.

That’s not all. Now, we will install the dependencies to get the best out of Zsh.

Step 5: Change the Default Theme

Oh My Zsh comes bundled with a lot of themes. The default theme is robbyrussell, but you can change it to any theme of your choice. In this scenario, I changed it to agnoster, an already pre-installed theme.

You then need to select this theme in your ~/.zshrc. To open the config file (.zshrc), run the command:

Or open the file in a text editor with

Set the zsh theme and update your changes

Using a Custom Theme

To install another theme not pre-installed, clone the repository into custom/themesdirectory. In this scenario, we’ll install powerlevel9k,

Then, select this theme in your ~/.zshrc

Update your changes by running the command source ~/.zshrc

Navigate to iTerm2 > Preferences > Profiles > Colors if you wish to change the background color of the terminal.

/microsoft-office-for-el-capitan-1011-6.html. The selected theme in this scenario requires powerline fonts. So, let’s install that.

Step 6: Install Fonts

I will be using Inconsolata. Get your preferred font out of these powerline fonts. Then, download and install it.

Or download the entire font.

To change the font, navigate to iTerm2 > Preferences > Profiles > Text > Change Font.

Now, you can see Inconsolata listed as one of the fonts. Select your preferred font. For fonts that support ligatures like FiraCode, check the “Use ligatures” option to view your arrows and other operators in a stylish manner like ( ).

Step 7: Install Color Scheme

Let’s change the color scheme to bring out the beauty of our terminal. Navigate to iTerm2-Color-Schemes and download the ZIP folder. Then, extract the downloaded folder cos what we need resides in the schemes folder.

Navigate to iTerm2 > Preferences > Profile > Colors > Color Presets > Import

  • Navigate to the schemes folder and select your preferred color schemes to import them.
  • Click on a specific color scheme to activate it. In this scenario, I activated Batman which is my preferred color scheme.

Tada! ? We’re done with the basic settings.

Step 8: Install Plugins

Oh My ZSH comes preloaded with a git plugin. To add more, for instance, docker, auto-suggestion, syntax highlighting and more:

  • Clone the Git repository
  • Head over to .oh-my-zsh > custom > plugins directory to view the cloned directory. To access this, run the command open ~/.oh-my-zsh
  • Add the plugin to the plugin section of the config file ~/.zshrc shown below
  • Update your changes by running the command source ~/.zshrc

Step 9: Add Aliases

Aliases are shortcuts used to reduce the time spent on typing commands. Add aliases to commands you run in the section shown below.

Thanks for reading.

If you know about other means of improving productivity using ZSH, you can drop them on the comment section, I will be glad to hear from you.

Last week, I had a very nice reader email me to ask a question about how to look through the commands he’d previously typed into Terminal. So if, for example, he’d used a “defaults write” command to alter how OS X looks or acts, he could find exactly what he did in his history to know how to reverse the changes.

There are quite a few ways you could go about this; I mentioned one method a couple of years ago that’ll help you search through the history, which is useful if you at least know a keyword in the command you’re trying to find. However, you could also just view your history in either the Terminal window or as a text file. To do the former, simply type “history” in at the prompt, and you’ll get what you’re looking for.

Macos Zsh Bash

If you’re familiar with using the “greater than” (“>”) symbol in Terminal, that’s an easy way to make “history” easier to read—it’ll take the command and create a file you designate with the output. So this example…

…means “run the ‘history’ command, and then create a new file on Melissa’s desktop called ‘history.txt’ with the results.” That little “greater than” symbol is handy for all sorts of stuff within Terminal, but be aware of its one big caveat: If there is already an existing file in your requested location with the same name, using the command above will replace it. If you want to add to existing text instead of replacing it, type “greater than” twice (“>>”).

Finally, there is one more method I’m going to suggest, and I think it’s the simplest of all. You could just open the file containing your history and view it as text! Unsurprisingly, though, that file is hidden by default, so to access it, open a new Terminal window, type this command in, and press Return:

That should open your list of previously entered commands within your default text editor, and you can search through it at your leisure.

Macos Terminal Zsh Separate History For Each Windows 7

(If the command above didn’t work, you may have navigated away from your user folder within Terminal, and if so, you can use the “cd ~” command [without the quotes] before running “open .bash_history” again.)

Macos Terminal Zsh Separate History For Each Windows 10

And finally, it wouldn’t be a command-line tip if I didn’t offer the usual disclaimers—be very careful of what you type, always copy and paste commands if you aren’t confident in your skills, blah de blah blah. Terminal’s awesome, but boy, could you cause issues if you really tried. Please don’t try, OK?