👨🏼‍💻

khriztianmoreno's Blog

Home Tags About |

Posts with tag bash

Pimp my Term - Mac

2020-05-03
tutorialbashterminal

As a Mac OS user, I enjoy working with the terminal and find it a particularly powerful tool. Therefore, I spent quite a bit of time customizing it and here is my ultimate guide to terminal customization.Alt TextAt first I thought I would just create a short post with some of the settings I like. But I had so many things I wanted to show that this started to turn into a considerably long post. So I've decided to post it now, with as many tips as I can write, and I'll update it with new tips and tricks.My terminalRecommended installationsiTerm2Nerd fonts - Hack Boldzshzsh extensions:autosuggestionssyntax-highlightingPowerlevel10klsd: The next gen ls commandccat: Colorizing catlolcatNeofetch: A command-line system information tool written in bash 3.2+Let's start configuring all the tools we will need.PrerequisitesFirst, you must install iTerm2.Then install brew.Now install oh-my-zsh, open iTerm2 and paste the following command:sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"After we have these couple of things installed let's get more into it.Patched fontsI want to start talking about patched fonts, since many of the customizations I will explain later may depend on them. Patched fonts consist of regular fonts to which some additional symbols have been added. That way, you can display special icons (like your operating system icon) or add new shapes to your prompt.The most successful project is nerd-fonts, which includes many of the most commonly used fonts and a favorite of this project is Hack BoldNerd fontsNerd Fonts is a project that patches developer-driven fonts with a large number of glyphs (icons). Specifically to add a large number of additional glyphs from popular 'iconic fonts' such as Font Awesome, Devicons, Octicons and others.Nerd fontsThen to install these fonts on your Mac OS you can use brew:brew tap homebrew/cask-fonts brew cask install font-hack-nerd-fontI have seen that sometimes it does not install the fonts with cask, here is another option:brew install --cask font-hack-nerd-fontNow, if you look in the folder where you just installed it, you will see that it appears there: ls ~/Library/Fonts.Configure your terminalOnce you have downloaded Nerd Fonts, you can configure your terminal to use it. Configure iTerm2 to use the font by going to:iTerm2 -> Preferences -> Profiles -> Text -> Font -> Change FontSelect the Hack Regular Nerd Font and adjust the size if desired. Also check the Use a different font for non-ASCII text box and select the font again. It should display the new font and icons in the application.iTerm2 Text nerd fontsDon't worry if you don't see a significant change in your terminal, this will set the stage for the next steps.Colorize the terminalOn the road to the ultimate terminal, there is nothing that will improve its appearance more than customizing its color scheme, so this will be our starting point. By searching the Internet, you will be able to find many themes, but the easiest way to apply them is to use Gogh.This tool requires no installation and allows you to choose your favorite colors from a long list of different pre-built schemes.Simply copy and paste the command: bash -c "$(curl -sLo- https://git.io/vQgMr)"After selecting a theme, it will be installed and available for selection on your terminal.iTerm2 -> Preferences -> Profiles -> Colors -> Color PresetsLSD, LOLcat y ccatSome of the following tools to make them look better you need your iterm2 to have a minimum contrast.lsd is very much inspired by the supercolor project but with some small differences. For example, it is written in RUST and not in ruby, which makes it much faster.LSDIt is necessary to install the patched powerline fonts nerd-font and/or font-awesome.To install LSD just use brew and execute this line in your terminal:brew install lsdlolcat 🤣️ It gets rainbows and unicorns everywhere! This tool appears commonly used together with Neofetch, adding a stunning rainbow effect to your prompt.LOLcatTo install LOLcat just use brew and execute this line in your terminal:brew install lolcatTo verify that it is installed and working correctly you can run in the terminalls | lolcatccat This is the cat coloring. It works similarly to cat but displays content with syntax highlighting.asciicastTo install ccat just use brew and execute this line in your terminal:brew install ccatCustomize the bash promptIn case you have installed a patched font as described above, you can now use any kind of symbols to build your prompt. These sources include many powerline symbols that will allow you to fully customize your terminal without having to install any external plugins.Powerlevel10kThis is a fast reimplementation of POWERLEVEL9K with even some additional features. It even keeps the same variable names, so you won't need to change your configuration if you are coming from POWERLEVEL9k.One thing I love about POWERLEVEL10K is that, if you don't already have settings, when you first start it up, it will show you a guide that asks you for your preferences. During this process, it shows several examples, making it much easier to customize.Powerlevel10kTo install it on Mac we have two ways, the first one can be using brew or the second one that will be the one we will use is with Oh My Zsh, paste the following line in your terminal.git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10kNow you must tell zsh which will be the theme to use, for that edit the file ~/.zshrc, you can use any editor of your preference and look for the theme property and change it to ZSH_THEME="powerlevel10k/powerlevel10k.We must reload this file to see the changes in our terminal.source ~/.zshrcConfiguration WizardType p10k configure to access the built-in configuration wizard directly from your terminal.Powerlevel10k wizardAt the end of the wizard you will have a more personalized terminal and you will be very happy :)Now let's continue adding more high glamour details to our terminal.Some aliasesSome of the commands you have already installed do, in fact, support color highlighting, for example: ls, grep and diff. In case you want these commands to always have the color option enabled, you can write aliases in your terminal configuration file (.bashrc /.zshrc) to force them.alias l='ls -l' alias la='ls -a' alias lla='ls -la' alias lt='ls --tree' alias cat=ccatZsh customizationsZsh is a much more configurable shell with tons of plugins and themes that will make your terminal look amazing and even improve your workflow. For this shell, the customization possibilities are almost limitless, so now I will simply explain the configuration I use.One key difference with Zsh is that it doesn't come with preconfigured settings like other shells such as bash or fish, so I would suggest copying some of my settings as a starting point, particularly if you are installing it for the first time.Configuring keybindings - keybindingsOne of the first things I quickly noticed when using Zsh is that many of the keybindings and shortcuts I was used to, coming from bash, would not work at all or would cause unexpected behavior. Even the HOME and END keys didn't work. So here are all the key combination settings I use:bindkey '^[[2~' overwrite-mode bindkey '^[[3~' delete-char bindkey '^[[H' beginning-of-line bindkey '^[[1~' beginning-of-line bindkey '^[[F' end-of-line bindkey '^[[4~' end-of-line bindkey '^[[1;5C' forward-word bindkey '^[[1;5D' backward-word bindkey '^[[3;5~' kill-word bindkey '^[[5~' beginning-of-buffer-or-history bindkey '^[[6~' end-of-buffer-or-historyUseful add-onsAutosuggestions Suggests commands as you type based on history and completions.Syntax highlighting This package provides syntax highlighting for the Zsh shell. It allows highlighting commands as they are typed at a Zsh prompt in an interactive terminal. This helps to check commands before executing them, particularly for syntax errors.That's it, we're done with setting up our terminal, I hope this has been useful and/or made you learn something new!Profile@khriztianmoren