Simple Shell Script to Create Quicklink in Home Folder

Lately I’ve been finding myself working predominantly in and around a particular directory for a day or two, and then moving somewhere else. I like a lot of organization in my file system, but the downside to that is a lot of times, the project I’m working on is buried many levels deep in my folder structure, and I start to spend a lot of time typing out change directory commands (okay, not a lot, but definitely enough to be annoying!). Today I wrote a script to do something about it. Now all I have to do is type set-current from any directory, and a link to the current directory titled current will be placed in my home folder. Here’s the script:

#!/bin/sh
# set-current
 
if [ -e $HOME/current ]; then
    echo "Overwrite $HOME/current? (y or n)"
    read answer
    if [ $answer = y ]; then
        rm $HOME/current
        ln -s $PWD $HOME/current
    fi
else
    ln -s $PWD $HOME/current
fi

Place set-current in /usr/local/bin, or any other place you wish in your PATH and that’s it.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">