Setting up aliases.mine for tcsh in OSX

You're beginning to tinker around with the Unix command line in OSX, and you're now at the point where you are feeling frustrated with what seems like repetitive typing of the same commands and parameters again and again (and you have already uncovered the handy up-arrow and tab-complete features). You are now ready to learn more about configuring your shell environment.

Unfortunately...
Apple has been going out of its way to make this difficult. When I first created this script in 2002 it "just worked" - copy and paste into Script Editor, compile, run, done. But now, there is additional manual setup that is required. But hey! That makes it more of a learning opportunity, right?

So here is what you need to set up, and what you might want to set up.

First, this page is exclusively for the tcsh shell on MacOS®. If you want to tinker with sh, csh, bash, zsh or any others, look elsewhere.

When OSX was first released, and for the first few iterations, the default shell was tcsh. This was changed to bash when 10.3 (Panther) was released. To enter a tcsh shell from a bash shell, type tcsh at the command line prompt. This script is for the tcsh shell only.

You can change your default shell in 2 ways.
  1. Open the Terminal app (in the /Applications/Utilities folder), go to Preferences, and set "Shells open with:" to "/bin/tcsh" (you will also need to select the radio button for "Command (complete path):" as shown in the picture). Feel free to explore the other preference options - they're kind of fun!

    Setting the default shell in this way affects only the local user when using the shell locally, not when remotely logging in to your device from another machine.

    OR...

  2. At the shell command prompt, enter
    sudo chsh -s /bin/tcsh {username}
    This will change the default shell for remote logins. You will need to enter your administrator password.

Second, you may want to make the user Library folder visible. It's been hidden since MacOS X 10.7 (Lion). The page at https://www.lifewire.com/os-x-is-hiding-your-library-folder-2260833 nicely explains this and how to make it visible. There are many other sites that discuss this.

Third, you will need the source files. Apple removed them and basically made it impossible to re-create them. You can download the tcsh.zip archive here. It comes from MacOS 10.6. Unpack/unzip/decompress it and place it in the folder /Users/{username}/Library/applesux (same as ~/Library/applesux) - you will need to create that folder by entering

mkdir ~/Library/applesux
And then move the tcsh folder into applesux (do you sense my frustration?)

If you do this correctly you will be able to view the README file as follows:
cat ~/Library/applesux/tcsh/examples/README
which is the same as...
cat /Users/{username}/Library/applesux/tcsh/examples/README
where {username} is the short name of your MacOS user.
I could have automated this process, but that would have required bringing files in from outside under program control, creating a possible security hole. Doing this part manually gives you control and a chance to inspect what is coming in.

So here's the fun stuff...

As background, if you enter this into your command line shell (yes, this is insecure pseudocode!):

alias ssh1 'ssh myserver.mydomain.com -l myshortname -p mypassword'
you will find that you can connect to myserver.mydomain.com by entering only ssh1. What a handy time saver! Unfortunately, when you exit your shell, you lose this shortcut. But there is a solution!

The file aliases.mine can hold an arbitrary number of such aliases, which are automatically enabled at login time (tcsh shell only). However, setting it up manually is a bit tedious; the following Applescript does the work for you, and provides a tidy teaching lesson as well.

Here is the Script

Besides setting up aliases.mine, this script also sets pico as the default text editor.

To set up aliases.mine, copy and paste the above script into your Applescript Script Editor, compile it, and run it. The script includes several display dialog commands, which allow you to watch, learn, and debug, and to stop the script if something seems awry. It is also helpful to open the Script Editor event log (before running the script!) and check "Show Event Results" to follow the progress of the script.

When completed, a Finder alias to aliases.mine will be in your Favorites folder (along with a Finder alias to ~/Library/init/tcsh/), and it should (hopefully) conveniently open in BBEdit. If you have trouble after editing any of the files using BBEdit, be sure to save them using Unix line breaks (there's an "Options" button in the open/save dialog). You can also edit your aliases.mine file by typing myaliases at your command line prompt (in the tcsh shell). You will need to exit your current shell and log in anew before these changes will take effect.

The inspiration for this script can be viewed in the terminal with:
cat /usr/share/tcsh/examples/README
cat ~/Library/applesux/tcsh/examples/README
which will bring up something similar to the following:

The above Applescript creates, but does not further modify, completions.mine, rc.mine, and path. This is because this is a work in progress, I have no current need to extend those functions further, and I wanted to keep the script lean and focused on aliases.mine (and I don't know yet what I can do with them anyway).

Legacy

This is the pre-MacOSX 10.4 (Tiger) version. It is here only as a historical reference. Don't use it.

Links

Re-establishing ~/Library/init/tcsh functionality (2002)

Credits

My thanks to Daniel Woods who helped me debug the problem with /usr/share/tcsh/examples/aliases.





 © 1997-2019 Jeffrey W Baumann dba LinkedResources. All Rights Reserved. Last Updated April 6, 2019.