This is the mail archive of the
cygwin-xfree@cygwin.com
mailing list for the Cygwin XFree86 project.
Re: First pass at script to build start menu icons
OK, here's a better set. It actually sets the right icons and deals
correctly with having symlinked programs without the trailing .exe.
# Yo! Emacs! Edit this in -*- shell-script -*- mode!
# This is the root for the icon creation.
TOPFOLDER="$(cygpath -A -P)/Cygwin-XFree86"
#format of an entry here:
#executable name:Description:sub-folder:which function to call:icon offset:arguments
#If the sub-folder is empty, then the icon will be placed in $TOPFOLDER
#the "function to call" should be either xapp or tapp
#If the program provides its own icon in the executable, this is the offset for it (0 based)
#The arguments (if any) will be appended to the command.
X11proggies=(
bitmap:"Bitmap Editor"::xapp::
dpsexec:"Display PostScript command interface":Tools:tapp::
dpsinfo:"The Display PostScript extension":Information:tapp::
editres:"Xaw resource editor":Tools:xapp::
fc-list:"List available FreeType fonts":Information:tapp::
glxgears:"Gear Demo":Toys:xapp::
glxinfo:"GLX information":Information:tapp::
ico:"Bouncing Icosohedron":Toys:xapp::
oclock:"Shaped Clock"::xapp::
showrgb:"List rgb database":Information:tapp::
texteroids:"DPS demo asteroids game":Games:xapp::
viewres:"Xaw resource viewer":Tools:xapp::
vncviewer:"VNC viewer client"::xapp::
wmagnify:"magnifying glass":Tools:xapp::
xbiff:"mail checker"::xapp::
xcalc:"Calculator"::xapp::
xclock:"Clock"::xapp::
xconsole:"Console":Tools:xapp::
xcutsel:"Clipboard manipulator":Tools:xapp::
xditview:"Ditroff output viewer"::xapp::
xdpyinfo:"Display information":Information:tapp::
xdvi:"DVI viewer"::xapp::
xedit:"Simple file editor":Editors:xapp::
xev:"X11 event debugger":Tools:xapp::
xeyes:"Watches the Mouse":Toys:xapp::
xfontsel:"Pick a font":Tools:tapp::
xfsinfo:"The font server":Information:tapp::
xgc:"X11 demo":Toys:xapp::
xkill:"Kill an X11 window":Tools:xapp::
xlogo:"Display the X11 logo":Toys:xapp::
xlsatoms:"List available atoms":Information:tapp::
xlsclients:"List all connected clients":Information:tapp::
xlsfonts:"List all available fonts":Information:tapp::
xmag:"Magnifying glass":Tools:xapp::
xman:"Manual page reader"::xapp::
xmh:"GUI for the MH mail system"::xapp::
xprop:"Display the propertis of a window":Information:tapp::
xrefresh:"Refresh all X11 clients":Tools:xapp::
xterm:"X Terminal"::xapp:0:
xtrapinfo:"The TRAP extension":Information:tapp::
xvinfo:"The X-Video Extension":Information:tapp::
xwd:"Dump X11 window image to file":Tools:tapp::
xwininfo:"A single window":Information:tapp::
gvim:"GUI for VIM":Editors:xapp::
emacs:"Emacs":Editors:xapp::
xemacs:"XEmacs":Editors:xapp:0:
idle:"Python IDE":Tools:xapp::
rxvt:"RXVT"::xapp:0:
)
#! /bin/bash
# Author: Brian Gallew <geek+@cmu.edu>
# This next line defines TOPFOLDER and X11proggies
. /etc/X11/icon-list
#Ensure that a given program is somewhere in the current $PATH
function checkpath () {
c=$(which $1 2> /dev/null)
test ! -z "$c"
}
#Make sure the program we *think* we're pointing to is the real deal.
function canonicalize () {
a=$(which "$1")
while test -h "$a"
do
set $(ls -l "$a")
while test ! -z "$2";do shift;done
a=$(dirname "$a")/"$1"
done
test -f "$a".exe && echo "$a".exe || echo "$a"
}
# Create a shortcut for an application that draws its own windows
# Takes four or five arguments: appname, description folder, the
# offset of the icon , and any arguments
function xapp () {
app="$1"
shift
description="$1"
shift
folder="${TOPFOLDER}/$1"
shift
if [ -z "$1" ]
then
icon="--icon=/usr/X11R6/bin/run.exe"
ioff="--iconoffset=2"
else
icon=--icon=$(canonicalize "$app")
ioff="--iconoffset=$2"
fi
shift
test -d "${folder}" || mkdir -p "${folder}"
mkshortcut "${icon}" "${ioff}" --arguments=${app}\ -display\ :0\ "$@" \
--name="${folder}/${description}" \
--workingdir="${HOME}" /usr/X11R6/bin/run.exe
}
# Create a shortcut for a text-output-only application
function tapp () {
app="$1"
shift
description="$1"
shift
folder="${TOPFOLDER}/$1"
shift
test -d "${folder}" || mkdir -p "${folder}"
mkshortcut --arguments=xterm\ -display\ :0\ -e\ sh\ -c\ \"${app}\ -display\ :0\ "$@"\ "| less"\" \
--name="${folder}/${description}" --icon=/cygwin.ico \
--workingdir="${HOME}" /usr/X11R6/bin/run.exe
test $? -eq 0 && return
echo $app:$description:$folder::
}
function create_icons () {
for index in $(seq 0 ${#X11proggies[*]})
do
a=${X11proggies[$index]}
test -z "$a" && continue
# This next line breaks up the elements and set $1..$6 appropriately
IFS=":";set $a;unset IFS
checkpath $1
test $? -eq 0 || continue
case $4 in
xapp)
xapp $1 "$2" "$3" $5 $6
;;
tapp)
tapp $1 "$2" "$3" $6
;;
*)
echo `hosed!`
echo $*
esac
done
}
function destroy_icons () {
for index in $(seq 0 ${#X11proggies[*]})
do
a=${X11proggies[$index]}
test -z "$a" && continue
# This next line breaks up the elements and set $1..$6 appropriately
IFS=":";set $a;unset IFS
icon="${TOPFOLDER}/${3}/${2}.lnk"
test -f "${icon}" && \rm -f "${icon}"
done
find "${TOPFOLDER}" -depth -type d -exec rmdir -v --ignore-fail-on-non-empty "{}" \;
}
function usage () {
cat >&2 <<EOF
Usage: $0 [-d]
Without any switches, this will recreate the defined icon set. The
"-d" switch indicates that all the icons should be removed. If, after
the icons are removed, any of the folders are empty, they, too, will
be removed.
EOF
exit -1
}
delete=${1}
shift
test -z "$*" || usage
if [ -z "$delete" ]
then
create_icons
else
test "$delete" = "-d" || usage
destroy_icons
fi