Category: Unix

  • Ubuntu: Show current Git branch on Terminal prompt


    There are times when I keep running git status or git branch to check which branch I’m on and I just found that I could do something to show the name of my current Git branch on my Terminal prompt, thanks to a colleague.

    In the following screenshot I’m working in the directory “sample_app”, on Git branch that is named “static-pages”:

    ubuntu-terminal-prompt-git-branch-

    In Ubuntu, here’s how I did it.

    Create .bash directory in Home:
    mkdir ~/.bash

    Go to the new directory
    cd ~/.bash

    Clone the git-aware project from GitHub:
    git clone git://github.com/jimeh/git-aware-prompt.git

    Edit your .bashrc file. I use Vim editor for this:
    vim ~/.bashrc

    Add the following to the top of your .bashrc:

    If you want colored prompts, add the following to the bottom of your .bashrc:

    Otherwise, if you doon’t like colors, use this instead:

    Open a new Terminal tab or restart Terminal. Navigate to any directory that has a Git repository and your Ubuntu’s Terminal prompt should now show the current Git branch’s name.

  • Mac OS: How to batch edit file extension via Terminal

    Today I had a directory of images whose file name extensions are .jpeg. I need them as .jpg but I didn’t want to rename them one by one.

    Here’s how we can change the file extensions in a directory by batch. And by the way, I am on Mac OS El Capitan version 10.11.5 with Homebrew package manager.

    First, open your Mac’s Terminal.

    Type the command rename just to check if you have it installed in your system. If the Terminal displays usage instructions on rename then you already have it.

    If rename is a command not found, then install it via Homebrew using this command:

    Once the rename command is available, navigate to the directory where your files that need new extensions are.

    Then edit the following command to suit your needs before running:

    The syntax for this is actually rename "s/OLD_EXTENSION/NEW_EXTENSION/" *.OLD_EXTENSION

    That’s all! I hope that worked for you.

    Resource: Changing extension to multiple files