Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have the latest executable screenfetch-dev in /Users/gav/scripts/ folder. I can execute it fine by running /Users/gav/scripts/screenfetch-dev

But how do I make it a command, so I can just type screenfetch and make it run?

I'm using OS X 10.8 ML.

share|improve this question

migrated from stackoverflow.com Aug 28 '12 at 21:03

This question came from our site for professional and enthusiast programmers.

3 Answers 3

up vote 2 down vote accepted

Assuming that you're using the default shell in OS X (BASH), you can add the following to the .bash_profile in your home directory (so /Users/gav/.bash_profile - you may have to create this file yourself if you've never used it before):

alias screenfetch="/Users/gav/scripts/screenfetch-dev"

Alternatively, you could add your scripts folder to your PATH, by adding the following line to the same .bash_profile:

export PATH="/Users/gav/scripts:$PATH"

The first method (creating an alias) allows you to assign any name as a "shortcut" for anything else - when the command is run, the BASH shell simply substitutes the "shortcut" for the full command. In this case, you could run the script simply by typing screenfetch.

The second method (adding the folder to your PATH variable) allows you to use any of the contents of the scripts folder from anywhere inside the shell, although you still have to use the script's full name to access it - in this case it would be screenfetch-dev.

share|improve this answer
    
This worked, thank you so much! –  gavflynn Aug 28 '12 at 22:43

I have in .bash_profile lines:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

And always creating ~/bin folder with custom binaries I can use. And it is automatically added to path if exists. I'm taken this code from ubuntu's .bashrc

after this I can just pass command "screenfetch-dev" or if file is renamed to screenfetch then "screenfetch"

and command to make your "screenfetch-dev" file in "~/bin" executable(if it doesn't set as executable):

chmod +x ~/bin/screenfetch-dev
share|improve this answer

Move screenfetch-dev to /usr/bin and then add screenfetch or screenfetch-dev to .bashrc

(OR)

Add /Users/you/Downloads/screenfetch-dev to .bashrc

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.