June 14, 2008
Always wanted to watch a man page in a pdf file? It is clearly needed sometimes, especially on mac, since it is the easiest way i know to print a man page or to read it not from a terminal.
The problem is solved easily for both Mac OS and linux. I had to add control for <code>pstopdf</code> too, since on mac it is called that way and has different parameters (but you may have <code>ps2pdf</code> installed with macports anyway).
#! /bin/bash
if [ $# -eq 1 ] ; then
to_pdf=$(which ps2pdf)
if [ -z "$to_pdf" ] ; then
to_pdf=$(which pstopdf)
fi
name="$1"
case "$to_pdf" in
*pstopdf) man -t "$name" | "$to_pdf" -i -o "$fname.pdf" ;;
*ps2pdf) man -t "$name" | "$to_pdf" - "$name.pdf" ;;
*) man -t "$name" > "$fname.ps"
esac
exit $?
fi
echo "Wrong number of parameters"
exit 1
Just call it like man2pdf gcc and you’ll get gcc.pdf
1 Comment |
Script | Tagged: linux, mac, man, pdf, print, Script |
Permalink
Posted by Dario Meloni
June 10, 2008
Since the introduction of dual core machines the number of mono core machines is declined and almost no computer of that kind are sold at all. Having such a machine is clearly a big advantage, but for many things you must tell programs that you are on a multi-cpu machines to make them use all the power. So i wrote a very little and simple script to replace the default make.
Just place this script in a path before the standard make. I made a folder ~/.bin in my home directory and modified the PATH accordingly export PATH=~/.bin:$PATH
#!/bin/sh
# verbosity check
if [ "$VERBOSE" = "yes" ] ; then
verbose=yes
fi
# Get the number of cores
if [ -z $NCPU ] ; then
tmp=$(sysctl hw.ncpu)
NCPU=${tmp#hw.ncpu: }
if [ "$VERBOSE" = "yes" ] ; then
echo "Parallelization enabled with $NCPU threads"
fi
fi
j=$(($NCPU*5/2))
if [ ! -z $NOPMAKE ] ; then
echo "Parallelization Disabled" >&2
/usr/bin/make $@
exit $?
fi
# Start the compilation in parallel
if [ ! -z "$DISTCC_HOSTS" ] ; then
if [ -z "$HOST_COUNT" ] ; then
export HOST_COUNT=$(echo $DISTCC_HOSTS | wc -w)
fi
/usr/bin/make CC='distcc /usr/bin/gcc' CXX='distcc /usr/bin/g++' -j$((j+$HOST_COUNT)) $@
else
/usr/bin/make -j$j $@
fi
To make it work on linux the sysctl command must be replaced with a count of the lines containing “processor” in the file /proc/cpuinfo. Something like grep processor /proc/cpuinfo | wc -l
Leave a Comment » |
Script | Tagged: bash, make, parallel, Script |
Permalink
Posted by Dario Meloni