Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use MacBook Air with OSX 10.7.2.

I would like to create an alias that does the following:

  • Opens TextMate with ~/.bashrc and allows me to edit it
  • Once I close TextMate, "sources" ~/.bashrc (so if I add a new alias, for example, it will be available immediately)

I tried the following:

alias b="/usr/bin/mate -w ~/.bashrc; source ~/.bashrc"

but it doesn't work: when I close TextMate, the shell doesn't return (I don't see the shell prompt).

Any ideas?

share|improve this question
Works for me. Is your bashrc syntax okay? – slhck Nov 22 '11 at 22:15
Yes, for sure.. – Misha Moroshko Nov 22 '11 at 22:55
Well, I tested on 10.6 with TextMate 1.5.10 (latest, afaik). Maybe you found a bug? Am I reading this right, your shell just does not work anymore? – slhck Nov 22 '11 at 22:58
Once you solve the non-returning shell issue, you may want to put an unalias -a command before the source command in the definition so any deletions you make in the editor will be reflected in the current shell's new alias set. F/ex, if you found you'd accidentally made a dangerous alias and you use your b alias to edit it out, the present definition would leave the bad alias in the current shell, waiting to bite you. – JRobert Nov 23 '11 at 1:11

I don't have TextMate, but using your example with emacs works as expected. Possibly a problem with TextMate? Could you try another editor?

share|improve this answer
It definitely works with TextMate, I just tried it exactly as written in the question. I presume it's a syntax error in bashrc. – slhck Nov 22 '11 at 22:19
There is no error in ~/.bashrc. I deleted it completely, and put only the one line above. I tried to do the same with emacs: /usr/bin/emacs ~/.bashrc; source ~/.bashrc (no -w here), and it works as expected. – Misha Moroshko Nov 22 '11 at 22:54

Okay, here are a few angles of attack:

1) Simplify. Have you tried the commands outside of the alias to see if it works?

/usr/bin/mate -w ~/.bashrc; source ~/.bashrc

A better test might be with a file that doesn't exist yet:

FILE=$TMPDIR/matewaiting-$(uuidgen); /usr/bin/mate -w $FILE; ls -al $FILE

If you get a file listing, it waited. If you get an error even though you typed something in the file and saved it, then it didn't.

2) Multiple binaries in $PATH. You didn't mention what version you're using, we should check...

$ mate --version
mate 2.4 (2013-11-03 revision 9495)

If you didn't get that but instead something like mate r1577 (2012-07-11), then you have multiple mate binaries in your $PATH and you're using the old one. In that case, run the following repeatedly and move/rename/trash any older mate/mate_wait's until you finally see the latest...OR run out of matching commands in your $PATH:

for MATE in mate{,_wait}; do
    p="$(which $MATE)"
    echo "$p: $("$p" --version)"

Actually, you should probably remove new ones too, since they may have been cp'ed in (you can never be too paranoid with your OS :-). The following command will hard-link the commands into your /usr/local/bin so that they are updated automagically when/if they get updated by a TextMate 2 update:

# This is just in case you changed the TM2 bundle name in /Applications
# Using Spotlight...might as well, since it turns every Mac into a heliport...
[[ -n "$TM2" ]] || TM2="$(mdfind '(kMDItemCFBundleIdentifier=com.macromates.TextMate.preview)')"

if [[ -n "$TM2" ]]; then
    # Search for the mate binary within the TM2 directory
    MATE="$(find "$TM2" -name mate)"
    if [[ -n "$MATE" ]]; then
        # Hard-link both mate and mate_wait to the
        # mate binary into /usr/local/bin
        for cmd in mate{,_wait}; do
            ln -f "$MATE" /usr/local/bin/$cmd
            echo "Linked /usr/local/bin/$cmd to $MATE"
        echo "ERROR: No mate found in $TM2"
    echo "ERROR: Could not find TextMate 2 app bundle in /Applications."
    echo "Please set TM2 environment variable with full path"

This, of course, assumes you HAVE a /usr/local/bin and that it's actually in your $PATH (hopefully in FRONT of /usr/bin and /usr/sbin)...

3) Ditch the alias! I also have a realias but mine is a function (read: better for anything more than an alias as the dictionary defines it) and it was crafted with slightly more defensive programming (i.e. against my greatest enemy: me!). This from my .aliases file

# Remove all aliases
unalias -a

alias aliases='alias '

# Re-read the aliases
realias() {
    local editor="${VISUAL:-emacs}"
    if [[ -z $editor ]]; then
        echo "realias: VISUAL environment variable unset" > /dev/stderr
    [[ "$editor" =~ .*mate$ ]] && editor="$editor -w "
    "$editor" $HOME/.aliases
    source $HOME/.aliases

$VISUAL is set in my .bashrc to emacs, though on Mac OS X, it gets reset later to $(which mate 2>/dev/null).

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .