Elementolab/Mac/Unix Tips

From Icbwiki

(Redirected from Elementolab/Mac Tips)
Jump to: navigation, search
  • how to have your prompt show the working directory
export PS1="\u@\h:\w $"


Making Vim a source code browser

  1. Make sure you have Vim installed link
  2. Install the TagList plugin for Vim link
  3. Install Exuberant Ctags. This is typically different from the ctags program preinstalled on your computer link
  4. Check the FAQ if you have trouble making it work link. It is possible you did not set up filetype and Tlist_Ctags_Cmd in your .vimrc file. E.g.
filetype on
let Tlist_Ctags_Cmd='/usr/local/bin/ctags'
rsync -avz -e ssh dirhere ole2001@euros:dirthere/

(installation initially failed on my mac .. I installed using perl -MCPAN -e shell ... then install Local::lib .. that failed but then following the web page's instructions, it worked)

Emacs for Mac OS: http://aquamacs.org/index.shtml

Emacs Tips & Tricks


To disable the ultra annoying auto-fill, add this to /Users/yourusername/Library/Preferences/Aquamacs\ Emacs/Preferences.el

(setq text-mode-hook (quote (turn-off-auto-fill)))
(setq auto-word-wrap-default-function 'turn-on-word-wrap)

http://www.emacswiki.org/emacs/CustomizeAquamacs: To be able to launch files in Aquamacs from the command line, just select “Install Command Line Tools” from the Tools menu and follow through with the installation. It will ask for the password of a user with administrator privileges. You can then use the command ‘aquamacs’ from a shell to start Aquamacs. 

Dynamic abbreviations in emacs aka auto-completion


Setting font size in .emacs

(defun fontify-frame (frame)
  (set-frame-parameter frame 'font "Monospace-15"))

;; Fontify current frame
(fontify-frame nil)
;; Fontify any future frames
(push 'fontify-frame after-make-frame-functions)

etags http://emacswiki.org/emacs/EmacsTags

find .  -iname "*.[chS]" | xargs etags -a

Then in emacs

Esc-. to go to the source file of the tag under the cursor


make, gcc and other development tools are not installed by default on Mac OS X machines. They come bundled in a large, separate development tool package from Apple called xcode.

To download xcode, you have to create an Apple developer connection account (http://developer.apple.com/technology/xcode.html), then under Downloads, Developer Tools, download the xcode DVD image. Once done (it will take a little while) double-click on the file, then double click on package.


Unfortunately, xcode doesn't include xemacs and other useful development tools. Most of these tools can however be downloaded from macports at http://www.macports.org/install.php

Download the macports package, and install it. It installs in /opt/local, with the most important tool, port, in /opt/local/bin

I added /opt/local/bin to my PATH, which wasn't as easy as expected, because by default .bashrc is not present in $HOME, and when present not source'd at startup. To remedy that, I created a .profile in $HOME (http://forums.macosxhints.com/archive/index.php/t-34083.html), with the following code:

if [ -f ~/.bashrc ]; then
 . ~/.bashrc

Installing a macports package is then very simple:

sudo port install xemacs
sudo port install wget
sudo port install ghostscript
sudo port install coreutils

package installation takes a little while because it looks like packages are compiled on the fly.

I installed coreutils primarily to get the 'seq' bash utility. Turns out its called gseq in the port. All coreutils tools have this g prefix.

macports need to be updated from time to time:

sudo port -d selfupdate

Useful link: https://trac.macports.org/wiki/FAQ

  • Some useful stuff
open -a Finder . #  opens the Finder in the current dir ... great for attaching docs in emails by drag n drop.
  • Xcode <-> Makefile
  • Debugging

To debug 64bits Mac OS programs, use gdb -arch x86_64. Also remember to remove optimization flags (-O3), because certain optimizations cause variables to be unavailable to the debugger.

  • To compile a library for multiple architectures (so-called fat libraries)
./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" CPP="gcc -E" CXXCPP="g++ -E"
  • to put a program in nohup-type background
get process id
disown -h procid
useful settings for your $HOME/.screenrc:
 escape ^gg                               # use ctrl-G instead of ctrl-A 
 defscrollback 5000                       # enable the scrollback buffer
 hardstatus alwayslastline
 hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'
Useful keyboard shortcuts:
 Ctrl+G F                 resize the screen to fit the current terminal 
 Ctrl+G Ctrl+G            go back to previous window
 Ctrl+G "                 select from a list of windows
 Ctrl+G [                 enter scroll back mode
  • command line calculator

add the following to your ~/.bashrc

calc(){ awk "BEGIN{ print $* }" ;}  

then you can run from command line:

calc 100*200+300
  • A very nice UNIX TUTORIAL[1]
Personal tools