Skip to content

Instantly share code, notes, and snippets.

@danabrey
Last active March 5, 2019 15:42
Show Gist options
  • Save danabrey/2d4fa18d4af9f0dea6d8820af99aec61 to your computer and use it in GitHub Desktop.
Save danabrey/2d4fa18d4af9f0dea6d8820af99aec61 to your computer and use it in GitHub Desktop.
Install and configure oh-my-zsh with git and svn plugins and autosuggestions/syntax highlighting

oh-my-zsh require the zsh shell, along with git for self-installation and updating and Powerline fonts for the git/Subversion prompt decoration:

sudo apt install curl git zsh fonts-powerline

Install oh-my-zsh

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

Basic config

The shell will show your username and hostname by default, which is annoying (at least for me). Set DEFAULT_USER in ~.zshrc to remove it unless you're currently a user other than the one that owns the shell.

DEFAULT_USER=`whoami

Install and enable autosuggestion and syntax highlighting plugins

git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting

Append to enabled plugins in ~/.zshrc:

plugins=(git zsh-autosuggestions zsh-syntax-highlighting)

git/Subversion prompt helper

Show the current branch and revision number (for Subversion) and status on your terminal prompt.

For git

The built-in git plugin is enabled by default in ~/.zshrc, e.g.:

plugins=(git)

For Subversion

Enable the svn plugin by adding it to the enabled plugins in ~/.zshrc (space-separated):

plugins=(git svn)

For a git-like prompt showing the current branch and revision, you'll need to add the following to your .zshrc, as described in the oh-my-zsh docs:

prompt_svn() {
    local rev branch
    if in_svn; then
        rev=$(svn_get_rev_nr)
        branch=$(svn_get_branch_name)
        if [ `svn_dirty_choose_pwd 1 0` -eq 1 ]; then
            prompt_segment yellow black
            echo -n "$rev@$branch"
            echo -n "±"
        else
            prompt_segment green black
            echo -n "$rev@$branch"
        fi
    fi
}

build_prompt() {
    RETVAL=$?
    prompt_status
    prompt_context
    prompt_dir
    prompt_git
    prompt_svn
    prompt_end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment