Configure common command-line tools on Mac OS X January 29, 2009

Get the configuration files

Now, instead of writing yourself all the needed configuration files, you will simply take mine, and install them properly. In fact, I am not the original author of those files, since they came from the Formation Debian/GNU Linux. I simply adapted them to Mac OS X, and I translated the comments. Of course, I mentioned the origin of the files inside each one of them.

Open a Terminal window. First thing, we need root‘s privileges for most of the things we are about to do, so type the following command:

sudo -s

in order to become root, and if you’re asked for your password, just type it. Then do the following:

cd /var/root
wget https://files.lopes-da-silva.com/macosx/command-line-tools-configuration/command-line-tools-configuration.tar.bz2
tar xvjf command-line-tools-configuration.tar.bz2

That’s it, the configuration files are ready.

Configure vim

Since you will probably need to edit many files in your Terminal, you need to have a text editor with a good configuration. I personally use vim, so I will provide instructions on how to install a good configuration file for vim. However, I don’t want to discus here whether or not vim is better than emacs. I simply suggest you pick the one you like. But if you want to use something other than vim, then, in the rest of the instructions in this tutorial, you will need to replace any occurrence of vim by the text editor of your choice, and you can skip this section. Anyway, considering how geek this article is, I will assume you already know how to use vim or any other text editor you might choose to use instead.

So, let’s install a nice configuration file for vim!

cp command-line-tools-configuration/etc/vimrc /etc
cd /usr/share/vim
mv vimrc vimrc.original && ln -s /etc/vimrc && cd /var/root

Done. You will now have syntax highlighting, and other cool stuff in vim!

Configure sudo

Now, let’s tweak the behavior of sudo a little bit:

visudo

Now, vim should be open with your configuration for sudo. Just remove everything, and paste the following:

/etc/sudoers

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# /etc/sudoers: sudo configuration file

# This file MUST be edited with the 'visudo' command as root.
# Failure to use 'visudo' may result in syntax or file permission errors
# that prevent sudo from running.

# See the sudoers man page for the details on how to write a sudoers file.

##-----------------------------------------------------------
## Alias specifications
##-----------------------------------------------------------

### Host alias specification ###


### User alias specification ###


### Command alias specification ###


### Run as alias specification ###


##-----------------------------------------------------------
## Settings
##-----------------------------------------------------------

# Defaults specification
Defaults        env_reset
Defaults        env_keep += "BLOCKSIZE"
Defaults        env_keep += "COLORFGBG COLORTERM"
Defaults        env_keep += "__CF_USER_TEXT_ENCODING"
Defaults        env_keep += "CHARSET LANG LANGUAGE LC_ALL LC_COLLATE LC_CTYPE"
Defaults        env_keep += "LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME"
Defaults        env_keep += "LINES COLUMNS"
Defaults        env_keep += "LSCOLORS"
Defaults        env_keep += "SSH_AUTH_SOCK"
Defaults        env_keep += "TZ"
Defaults        env_keep += "DISPLAY XAUTHORIZATION XAUTHORITY"
Defaults        env_keep += "EDITOR VISUAL"

# Never remember user's password
Defaults        timestamp_timeout = 0

# Insult users when they fail typing their password
Defaults        insults

# Default password prompt
Defaults        passprompt = "Password: "


##-----------------------------------------------------------
## User privilege specifications
##-----------------------------------------------------------

# Root has all privileges.
root                    ALL=(ALL)       ALL

# Members of the admin group may gain root privileges.
%admin                  ALL=(ALL)       ALL

# Members of the admin group may execute some script without password.
# %admin                  ALL=(ALL)       NOPASSWD:/path/to/some/script

# Uncomment to allow people in group wheel to run all commands
# %wheel        ALL=(ALL)       ALL

# Same thing without a password
# %wheel        ALL=(ALL)       NOPASSWD: ALL

# Samples
# %users  ALL=/sbin/mount /cdrom,/sbin/umount /cdrom
# %users  localhost=/sbin/shutdown -h now

Just save the file, and you’re done. Among other nice things, sudo will now insult you when you make a mistake inserting your password!

Page: 1 2 3Next >

One Comments
Romero January 31st, 2009

Hiding /opt created within the install process of MacPorts

Thanks for the tutorial! (still having some customizing problem with figlet, but the rest is fine!)

For my concern, the /opt folder wasn’t there before MacPorts install (I don’t know if it’s the only one to use it?).

In order to “clean” the all thing, I found two interesting issues:

1- I don’t like to see the whole content of /Developer and /opt in the Spotlight search. So I first recommend to get these two in the excluding list of Spotlight (System Preferences).

2- I looked a little bit to know how to hide /opt like /usr, /etc are.
In an OS X way, it’s not that bad! :-). Obviously, putting a . in front of the name is no solution… At all.

You’ll need the Developer Tools, but you are supposed to install them anyway if you want to use MacPorts.

In the Terminal.app of course, use the brand ‘new’ root user:

root@machine ~# SetFile -a V /opt

Basically, it’s switching a bit in the file, responsible for (in)visibility in the Finder. Usually, you have to reload the Finder, but I didn’t have to.

It’s nicer 🙂

Leave a Reply