Customizing my macOS Terminal

On April 24th, 2021 in Myself, Tech

MacOS Terminal is ugly and not very functional. I have one always open, so I decided to make it look better. I used some tips from a Medium post (How To Customize Your macOS Terminal).

Setting the Theme

I’ve been using a theme called Homebrew for the last months, but I wasn’t satisfied with it, so I decided to take a look on the recommended theme “atom-one-dark-terminal“. I imported it and I liked it.

Setting preferences

On the same Terminal Preference Window, set those settings.

Text Tab
* Font: Menlo Regular 12 pt
*Text: Deselect Use Bold Fonts and Allow Blinking Text
*Cursor: Select Vertical Bar and Blink Cursor
Window Tab
*Title: Deselect Active process name, Arguments, Dimensions
Tab Tab
*Title: Deselect Path, Active process name, Arguments, Show activity indicator
Shell Tab
*Startup: Select Run command: and add ‘clear’ to the textbox, select Run inside shell
Keyboard Tab
*Select Use Option as Meta key

It’s almost the same as the Medium post suggested, my only change was the font size. I prefer it with 12pt.

Configuring .bash_profile

My .bash_profile was already set, but I decided to improve it and clean with the Medium suggestions.

# My .bash_profile source ~/.bash_prompt source ~/.aliases
Code language: PHP (php)

Configuring .bash_prompt

I had to create the .bash_prompt:

touch .bash_prompt
Code language: CSS (css)

If you want to understand what to what, take a look in the Medium post. It’s well written and explained. I’m showing my complete .bash_prompt:

#!/usr/bin/env bash # GIT FUNCTIONS git_branch() { git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' } # TERMINAL PROMPT PS1="\[\e[0;93m\]\u\[\e[m\]" # username PS1+=" " # space PS1+="\[\e[0;95m\]\W\[\e[m\]" # current directory PS1+="\[\e[0;92m\]\$(git_branch)\[\e[m\]" # current branch PS1+=" " # space PS1+=">> " # end prompt export PS1; export CLICOLOR=1 export LSCOLORS=ExFxBxDxCxegedabagacad
Code language: PHP (php)

Configuring .aliases

I had to create my .aliases too:

touch .aliases
Code language: CSS (css)

And here’s my file:

# NAVIGATION alias ..="cd .." alias ...="cd ../.." alias ....="cd ../../.." alias .....="cd ../../../.." # COMMON DIRECTORIES alias dl="cd ~/Downloads" # alias dt="cd ~/Desktop" alias dc="cd ~/Documents" # alias p="cd ~/Documents/projects" # alias home="cd ~" # GIT alias g="git" alias gs="git status" alias gd="git diff" alias gb="git branch" alias gm="git checkout master" # SHOW/HIDE HIDDEN FILES #alias showhidden="defaults write AppleShowAllFiles -bool true && killall Finder #alias hidehidden="defaults write AppleShowAllFiles -bool false && killall Finder # SHOW/HIDE DESKTOP ICONS #alias hidedesktop="defaults write CreateDesktop -bool false && killall Finder #alias showdesktop="defaults write CreateDesktop -bool true && killall Finder # CUSTOM CHANGES alias ll="ls -alh"
Code language: PHP (php)

Notice that I copied the Medium post file, but commented many of the lines. I also recreated one of my most used alias on this file (the “ll”).

After that, you just need to reopen Terminal and it’ll be working with the new tweaks.


Tags: bash mac terminal

How regex changed my life (for good)

On April 17th, 2021 in Tech

To be honest, I’m writing this post for myself. A place where I can store many little tips and bits of information about regex that can be useful on everyday life. If you want something more dense and better documented, I recommend to skip to the end of this post where you can find some great references, including websites that teaches regex exclusively. I’m not here to compete with them.

What is regex?

A regular expression (shortened as regex or regexp; also referred to as rational expression) is a sequence of characters that specifies a search pattern. Usually such patterns are used by string-searching algorithms for “find” or “find and replace” operations on strings, or for input validation. It is a technique developed in theoretical computer science and formal language theory.

From Wikipedia

How can it improve your life?

Regex is “Find” or “Find and Replace” but with Steroids. Regex allows us to use a LOT of search patterns that makes it a Swiss knife for the daily uses (when you get used to it).

I won’t bullshit, it is NOT human readable and the learning curve is quite steep, but regex is that kind of with that after learned, you will use for the rest of your life in a computer. Editing documents, converting text to table, programming, or even studying and reading on the web.

Some basics

Many of the examples bellow are from other websites that I found and saved for myself. If you want it removed or credited, please ask me that.

Special characters

There are 12 characters with special meanings:

  • the backslash \,
  • the caret ^,
  • the dollar sign $,
  • the period or dot .,
  • the vertical bar or pipe symbol |,
  • the question mark ?,
  • the asterisk or star *,
  • the plus sign +,
  • the opening parenthesis (,
  • the closing parenthesis ),
  • the opening square bracket [, and
  • and the opening curly brace {

Special characters in regex must always be preceded by “\” . For example: if I want to find “US$ 2.5 (diet coke)” it would be written: “US\$ 2\.5 \(diet coke\)”.

Things get even crazier when you start to declare common characters using escape backslash and special characters, eg.: search for “\\SE+VER.23(beta)” would be written “\\\\SE\+VER\.23\(beta\)”.

the backslash \

\+plus = +plus \\esc = \esc \t = "tab" (the special character)
Code language: JavaScript (javascript)

the caret ^

^text = text (in the beginning of a line) ^text = text is something ^text ≠ something is text (text is not on the beginning of the line)

the period or dot .

ton. = tone ton. = ton# ton. = ton4 ton. ≠ tones . = any char except newline \. = the actual dot character .? = .{0,1} = match any char except newline zero or one times .* = .{0,} = match any char except newline zero or more times .+ = .{1,} = match any char except newline one or more times
Code language: PHP (php)

the vertical bar or pipe symbol |

pand(abc|123) = pandora OR pand123

the asterisk or star *

tre*= tree (e is found 2 times) tre* = tre (e is found 1 time) tre* = tr (e is found 0 times) tre* ≠ trees

the plus sign +

tre+ = tree (e is found 2 times) tre+ = tre (e is found 1 time) tre+ ≠ tr (e is found 0 times)

the opening and closing parenthesis ( )

Find: (something) = There's something around here. (finds something) Replace: I can taste $1. = I can taste something. Find: (frog) = There's a frog in the pound. (finds frog) Replace: I can taste $1. = I can taste frog.
Code language: PHP (php)

the opening square bracket [

[a-z] = mice (will find 4 entries: m, i, c, e) [a-z]+ = mice (will find mice) [a-z]+ = car monkey dinamite (will find 3 entries: car, monkey, and dinamite) [A-Z] = mice (won't find anything) [A-Z]+ = Mice (won't find anything) [A-Z]+ = MICE (will find one entry) [a-zA-Z]+ = MICE (will find MICE) [a-zA-Z]+ = mice (will find mice) [a-zA-Z]+ = Mice (will find Mice) [a-zA-Z]+ = MICE Mice mice (will find 3 entries: MICE, Mice, and mice)
Code language: PHP (php)

and the opening curly brace {


The next post

For today that’s all. On the next post I’ll show some examples and useful tips that I learned while using regex.

List of regex references

List of regex tools

Tags: regex