A Beautifully Productive Terminal Experience iTerm, Oh-My-Zsh

Written by  Friday, 13 October 2017 21:00

Every developer can benefit from using the command line. Whether you use it to bounce between projects or create complex scripts, getting familiar with the command line can drastically improve your workflow.

In this post, we’ll cover some of the great tools available for streamlining your command line experience.

After some experimenting, I’ve found that using a combination of iTerm 2, Oh-My-ZshZsh, Prezto, Z, Trash & Origami for Sublime Text - makes for an extremely productive setup.

iTerm

iTerm2 is a replacement for Terminal and the successor to iTerm. It works on Macs with macOS 10.8 or newer. iTerm2 brings the terminal into the modern age with features you never knew you always wanted.

http://www.iterm2.com/

Oh-My-Zsh

Oh My Zsh is an open source, community-driven framework for managing your zsh configuration.

Sounds boring. Let's try again.

Oh My Zsh will not make you a 10x developer...but you might feel like one.

Once installed, your terminal shell will become the talk of the town or your money back! With each keystroke in your command prompt, you'll take advantage of the hundreds of powerful plugins and beautiful themes. Strangers will come up to you in cafés and ask you, "that is amazing! are you some sort of genius?"

Finally, you'll begin to get the sort of attention that you have always felt you deserved. ...or maybe you'll use the time that you're saving to start flossing more often.

https://github.com/robbyrussell/oh-my-zsh

Install OH-MY-ZSH

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

First - you need fix system Fonts: https://github.com/powerline/fonts

# clone
git clone https://github.com/powerline/fonts.git --depth=1
# install
cd fonts
./install.sh
# clean-up a bit
cd ..
rm -rf fonts

Install Homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install wget

brew install wget

Install Powerlevel9k theme to ZSH

If you prefer the Powerlevel9k look with added info such as exit codes and timestamps on the right, run:

git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k

Then edit your ~/.zshrc and set ZSH_THEME="powerlevel9k/powerlevel9k"

Trash

Works on macOS, Linux, and Windows.

In contrast to fs.unlink, del, and rimraf which permanently delete files, this only moves them to the trash, which is much safer and reversible.

sudo npm install --global trash

https://github.com/sindresorhus/trash

 

OSx Plugin

osx commands a3650

Z

Tracks your most used directories, based on 'frecency'. After a short learning phase, z will take you to the most 'frecent' directory that matches ALL of the regexes given on the command line, in order. For example, z foo bar would match /foo/bar but not /bar/foo.

U need copy z.sh raw file from github to ~

https://github.com/rupa/z/

Download it to root directory ~

Plugins what u can use in ~/.zshrc

plugins=(battery git node npm cloudapp composer docker fastd zsh-peco-history osx sublime sudo)

I attache my .zshrc file or watch all code:

# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh

# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
#ZSH_THEME="dockerps"
#ZSH_THEME="senzagnoster"
ZSH_THEME="agnoster" #my theme
#ZSH_THEME="the_poncho"

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to change how often to auto-update (in days).
export UPDATE_ZSH_DAYS=13

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.


plugins=(battery git node npm cloudapp composer docker fastd zsh-peco-history osx sublime sudo chucknorris)

source $ZSH/oh-my-zsh.sh


# User configuration

export PATH=$HOME/bin:/usr/local/bin:$PATH
# export MANPATH="/usr/local/man:$MANPATH"

eval "$(rbenv init -)"

# include Z, yo
. ~/z.sh

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# ssh
# export SSH_KEY_PATH="~/.ssh/dsa_id"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
alias db="cd ~/Dropbox/"
alias doc="cd ~/Documents/"
alias zs="subl ~/.zshrc"
alias gum="git pull upstream master"

alias -g xcopy='xclip -selection clipboard'
alias -g xpaste='xclip -selection clipboard -o'


# set java home
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=/usr/local/bin:/usr/local/sbin:$PATH

# set up andoird home
# android installed into ~/Public/installations
export ANDROID_HOME=/Users/eranga/Public/installations/android-sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools

# set up andoird NDK
#export NDK_HOME=/Users/eranga/Public/installations/android-ndk
export NDK_ROOT=/Users/eranga/Public/installations/android-ndk-r13b
export NDK_HOME=/Users/eranga/Public/installations/android-ndk-r13b
export PATH=$PATH:$NDK_HOME

# setup gradle home
export GRADLE_HOME=/Users/eranga/Public/installations/gradle
export PATH=$PATH:$GRADLE_HOME/bin

# set up RabbitMQ server scripts
export PATH=$PATH:/usr/local/sbin

# fix django locale issue from here on mac
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

# swift run on command line
# alias swift="/Applications/Xcode6-Beta2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift"

# enable/venv
# alias venv="source /Users/eranga/Public/installations/venv/bin/activate"

# django auto complete
# . $HOME/.django_bash_completion

# set up maven home 
#export M2_HOME=/usr/local/Cellar/maven/3.2.3/libexec

# Colorize maven
alias maven="/usr/local/bin/mvn"
alias mvn="colorize_maven"

colorize_maven() {
  local BOLD=`tput bold`
  local TEXT_RED=`tput setaf 1`
  local TEXT_GREEN=`tput setaf 2`
  local TEXT_YELLOW=`tput setaf 3`
  local RESET_FORMATTING=`tput sgr0`

  maven $@ | sed -e "s/\(\[INFO\]\ \-\-\-\ .*\)/${TEXT_BLUE}\1${RESET_FORMATTING}/g" \
    -e "s/\(\[INFO\]\ \[.*\)/${RESET_FORMATTING}\1${RESET_FORMATTING}/g" \
    -e "s/\(\[INFO\]\ \)\(BUILD SUCCESS\)/\1${TEXT_GREEN}\2${RESET_FORMATTING}/g" \
    -e "s/\(\[INFO\]\ \)\(BUILD FAILURE\)/\1${TEXT_RED}\2${RESET_FORMATTING}/g" \
    -e "s/\(\[WARNING\].*\)/${TEXT_YELLOW}\1${RESET_FORMATTING}/g" \
    -e "s/\(\[ERROR\]\)/${TEXT_RED}\1${RESET_FORMATTING}/g" \
    -e "s/\(Failed tests: \)/${TEXT_RED}\1${RESET_FORMATTING}/g" \
    -e "s/\(Exception in thread \".*\" \)\(.*\)/\1${TEXT_RED}\2${RESET_FORMATTING}/g" \
    -e "s/\(SUCCESS \)\[/${RESET_FORMATTING}${TEXT_GREEN}\1${RESET_FORMATTING}\[/g" \
    -e "s/\(FAILURE \)\[/${RESET_FORMATTING}${TEXT_RED}\1${RESET_FORMATTING}\[/g" \
    -e "s/\(Caused by: \)\([^:\t ]*\)/\1${TEXT_RED}\2${RESET_FORMATTING}/g" \
    -e "s/\(ERROR\ \[.*\)/${TEXT_RED}\1${RESET_FORMATTING}/g" \
    -e "s/Tests run: \([^,]*\), Failures: \([^,0]*\), Errors: \([^,]*\), Skipped: \([^,]*\)/${TEXT_GREEN}Tests run: \1${RESET_FORMATTING}, Failures: ${TEXT_RED}\2${RESET_FORMATTING}, Errors: ${TEXT_RED}\3${RESET_FORMATTING}, Skipped: ${TEXT_YELLOW}\4${RESET_FORMATTING}/g"

  echo -ne ${RESET_FORMATTING}
}

# set up boot2docker
export DOCKER_HOST=tcp://192.168.59.103:2375
unset DOCKER_TLS_VERIFY
unset DOCKER_CERT_PATH
#export DOCKER_CERT_PATH=/Users/eranga/.boot2docker/certs/boot2docker-vm
#export DOCKER_TLS_VERIFY=1

# Set java opts to find whats going wrong with jrebel
export JAVA_OPTS="$JAVA_OPTS -Drebel.log=true"

# github token for homebrew
export HOMEBREW_GITHUB_API_TOKEN=0633wefdd93ff53f84a85957def2d7ef1c85c698

# cheat 
export CHEATCOLORS=true
export EDITOR=vim 

# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"


Color Presets

##Installation Instructions## To install:

  • Launch iTerm 2. Get the latest version at iterm2.com
  • Type CMD+i (⌘+i)
  • Navigate to Colors tab
  • Click on Load Presets
  • Click on Import
  • Select the .itermcolors file(s) of the scheme(s) you'd like to use
  • Click on Load Presets and choose a color scheme

Link to iTerm Color Schemes or download my attasched file iTerm2-Color-Schemes-master.zip

Terminal Are Sexy!

2829 Read Last modified on Wednesday, 08 November 2017

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.

1 comment

  • Comment Link Inger Linley Thursday, 23 November 2017 21:28 Inger Linley

    Just wanna input on few general things, The website layout is perfect, the articles is very superb : D.

Related items

  • How to change screenshot format png → jpg
    in Mac

    To save screenshots in JPG, execute the following commands in the terminal:

    defaults write com.apple.screencapture type jpg;killall SystemUIServer

    macOS also support: tiff, pdf, bmp & pict.

  • Как повысить свою эффективность в macOS можно с помощью режима «единственного окна»?
    in Mac

    В macOS есть специальный режим, который позволяет задействовать одновременно лишь одно окно. Все остальные программы при переключении будут просто скрыты.

    defaults write com.apple.dock single-app -bool true; killall Dock

    Чтобы вернуть настройки назад, нужно поменять true на false командой:

    defaults write com.apple.dock single-app -bool false; killall Dock
  • Launch Sublime Text 3 from the command line & simlink to Subl
    in Mac

    These instructions assume you’re using the Terminal app out of the box, without ZSH or any fancy prompts like that. I trust you will be able to adapt these instructions yourself if you do.

    Step 1 : Create a symlink called sublime

    sudo ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/sublime

    Step 2 : Check that your system profile can find the symlink you just created.

    open ~/.bash_profile

    Step 3 : Add both these lines & then save the file :

    alias subl="open -a /Applications/Sublime\ Text.app"
    
    export PATH=/usr/local/bin:$PATH

    Step 4 : Reload your bash_profile :

    source ~/.bash_profile

    Done ! You can now navigate to any of your code/script folders in Terminal and open them in Sublime with the following commands :

    subl .
    subl .zshrc
  • How to Stop .DS_Store File Creation on Network Volumes in Mac OS X
    in Mac

    To disable the creation of .ds_store files, launch the Terminal application from /Applications/Utilities/ and enter the following command string exactly:

    defaults write com.apple.desktopservices DSDontWriteNetworkStores true

    Reboot the Mac for changes to take full effect.

  • Customize OS X's Login Screen with Any Logo You Want
    in Mac

    The login screen on your Mac is perfectly functional as it is, but if you want to spice it up a little bit, blogger Jacob Salmela shows you how to customize the login screen with a logo of your choosing.

    If you don't want to install a whole program just for a simple tweak it's easy to do manually. All you need is a PNG that's 428 X 248. Then, you'll need to save it as four different files.

    Here's instructions:

    You need four copies of this file, and they need to be named:

    • apple.png
    • apple@2x.png
    • apple_s1.png
    • apple_s1@2x.png

    Once they are named correctly, just drag them into the following path:

    /System/Library/PrivateFrameworks/LoginUIKit.framework/Versions/A/Frameworks/LoginUICore.framework/Resources/

    and then choose to replace all of them.

    That's it, log out, and you should see your new logo. Head over to Salmela's site for a few sample images and instructions for making your own.