using aliases for cygwin commands on win2k

Jean-Marc Eurin jmeurin@yahoo.com
Mon Sep 17 17:57:00 GMT 2001


Hello,
Here are a couple of bash functions that I use to open
files from cygwin. The first function is what I found
on the web a while back, the second one is my
customization.
You can then do things like:
of foo.doc ../bar.xls 
Jean-Marc 
#-*-shell-script-*-
# open any file in the correct program: an associated
file-type (see assoc
# and ftype at Windows NT/2000) will be opened with
the associated program.
# Not associated filetypes and files which extension
is contained in
# $PATHEXT will be opened in the texteditor (here
Emacs). Files with
# extension .exe and .com will not be opened!
function open-file-with-w32 ()
{
	for i in $*; do
		if [ -f "$i" ]; then
			# get the extension only
			erg=`echo $i | sed -e 's|.*.||g;'`
			# check if we try to open a program
 if [ "$erg" != "exe" ] &&
 [ "$erg" != "EXE" ] &&
 [ "$erg" != "com" ] &&
 [ "$erg" != "COM" ]; then
 # check if we try to open a file with
a extension from $PATHEXT
 is_path_ext=`echo "$PATHEXT"; | grep
-i ".$erg;"`
 if [ "$is_path_ext" == "" ]; then
 # check if this extension is
associated with a w32-program
 erg=`cmd /x /c assoc ".$erg"
2>/dev/null`
 if [ "$erg" != "" ]; then
 # an association exists
therefore this call should
 # theoretically not produce an
error.
 cmd /x /c start /b `cygpath -w
"$i"` 2>/dev/null
 else
 # we must open the file with a
text editor because
 # it is not associated.
 gnuclient -q `cygpath -w "$i"`
 fi
 else
 # files with a extension contained
in $PATHEXT will be
 # opened with the text editor.
 gnuclient -q `cygpath -w "$i"` 
 
 fi
 else
 echo "$i is a program!"
 fi
 fi
 done
 unset erg is_path_ext;
}
function fast-open-file-with-w32 ()
{
	# Loop through the parameters, which works better
	# with spaces in path or filename.
	while [ $# -ne 0 ]
	do
		# get the extension only, in lower case
		erg=`echo 1ドル | sed -e 's|.*.||g;' | tr [:upper:]
[:lower:]`
		case $erg in
			exe|com)
				# We try to open a program
				echo "1ドル is a program!"
				;;
			txt|bat|cmd|vbs|vbe|js|jse|wsf|wsh)
				# I make a special case for the text extensions,
				# to allow creating new text file.
				# This works for the native XEmacs:
				# gnuclient -q `cygpath -w "1ドル"`
				gnuclient -q "1ドル" # For the cygwin XEmacs
				;;
			1ドル)
				# There is no extension (i.e. erg == filename)
				# We open with XEmacs (could be a script).
				gnuclient -q "1ドル" # For the cygwin XEmacs				
				;;
			*)
				# check if this extension is associated with a
w32-program
				erg=`cmd /x /c assoc ".$erg" 2>/dev/null`
				if [ "$erg" != "" ]
				then
					# Windows does not allow to open a new file this
way...
					if [ -f "1ドル" ]
					then
						# an association exists therefore this call
should
						# theoretically not produce an error.
						# -a to run with remote paths.
						# -s to allow spaces in path or filename (grrrr)
						#echo "Use the Windows association for"
						cmd /x /c start /b `cygpath -wsa "1ドル"`
2>/dev/null
					else
						echo "This command cannot create the new file
1ドル"
					fi
				else
					echo "Invalid extension for 1ドル"
					# gnuclient -q "1ドル"
				fi
				;;
		esac
		#Deal with the next argument
		shift
	done
}
alias of=fast-open-file-with-w32
__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/


More information about the Cygwin mailing list

AltStyle によって変換されたページ (->オリジナル) /