#!/bin/sh ## ## Nautilus ## SCRIPT: 00_multiFiles_shoFILETYPEs_file.sh ## ## PURPOSE: For a set of user-selected files, this script shows their ## file types, using the 'file' command in a for-loop. ## ## METHOD: In a for-loop, for each of the user-selected files, ## concatenates the output of the 'file' command, onto a text file. ## ## Shows the text file in a text-file viewer of the user's ## choice. ## ## HOW TO USE: In Nautilus, go to any directory, select one ## or more files, right-click, choose this ## script to run (in an FE NautilusScripts submenu). ## (See script name above.) ## ## Created: 2011may10 ## Changed: 2011may11 Get 'nautilus-scripts' directory via an include script. ## Changed: 2011jul07 Changed to handle filenames with embedded spaces. ## (Removed use of FILENAMES var and use a 'for' loop ## WITHOUT the 'in' phrase. Ref: man bash ) ## Changed: 2012feb29 Changed the script name in the comment above. ## FOR TESTING: (show statements as they execute) # set -x ############################################## ## Prepare the output file. ## ## If the user has write-permission on the ## current directory, put the file in the pwd. ## Otherwise, put the file in /tmp. ############################################## CURDIR="`pwd`" OUTFILE="${USER}_temp_fileTypesList.txt" if test ! -w "$CURDIR" then OUTFILE="/tmp/$OUTFILE" fi if test -f "$OUTFILE" then rm -f "$OUTFILE" fi ##################################### ## Generate a heading for the list. ##################################### DATETIME=`date '+%Y %b %d %a %T%p'` echo "\ ..................... $DATETIME ............................ From directory: $CURDIR LIST of selected filenames and their FILE-TYPES. FORMAT: Filename : File-type info (on a line under filename) ........................................................................... " > "$OUTFILE" ################################### ## START THE LOOP on the filenames. ################################### for FILENAME do ################################################### ## Use 'file' to show the file-type info. ################################################## echo "" >> "$OUTFILE" file "$FILENAME" | sed 's|:|:\n|' >> "$OUTFILE" done ##################################### ## Generate a trailer for the list. ##################################### SCRIPT_BASENAME=`basename $0` SCRIPT_DIRNAME=`dirname $0` echo " ....................................................................... This list was generated by script $SCRIPT_BASENAME in directory $SCRIPT_DIRNAME To show the file-type of each user-selected file, this script used the command 'file'. ..................... $DATETIME ............................ " >> "$OUTFILE" ################### ## Show the list. ################### ## . $HOME/.gnome2/nautilus-scripts/.set_VIEWERvars.shi . $HOME/.freedomenv/feNautilusScripts/set_DIR_NautilusScripts.shi . $DIR_NautilusScripts/.set_VIEWERvars.shi $TXTVIEWER "$OUTFILE" &