#!/bin/sh ## ## SCRIPT: xpg ## ############################################################################## ## PURPOSE: This shell script starts up a GUI utility, nicknamed 'xpg', to ## browse AND/OR search AND/OR extract-match-lines AND/OR ## print a text file. ## ############################################################################## ## FURTHER DESCRIPTION: ## This script calls Tcl-Tk script 'shofil.tk' to present the GUI ## and to do browse actions on the text file --- per user actions on ## the widgets of the GUI. ## ## By default, this script starts 'shofil.tk' in the BACKGROUND. ## (Uses an '&' with 'shofil.tk' for BACKGROUND execution.) ## But the user can supply a '-f' parameter to this script, to ## force FOREGROUND execution of 'shofil.tk'. ## ## 'shofil.tk' is basically an X-GUI-version of the Unix (SGI-IRIX) ## 'pg' command. The 'pg' command offered a way to 'page' back and forth ## through a text file in a Unix virtual terminal. The 'pg' command ## was similar to the 'more' and 'less' command --- a big step up from ## using the 'cat' command to browse a text file. 'cat' did not have an ## option to page back (or forward) in the text. ## ## 'shofil.tk' adds a unique extract-matching-lines facility as well as ## built-in print function --- in addition to browse & search functions ## similar to those of the non-GUI 'pg' command (which is like 'less') ## --- but the 'xpg/'shofil.tk' browse & search options are much nicer ## (easier to use, faster, feature-rich). ############################################################################## ## CALLED BY: Can be called manually at a Unix shell prompt. ## Example: xpg ## ## Also could be called from within shell or Tcl-Tk scripts. ## ## One of many ways the 'xpg' script could be implemented on Linux/Unix/BSD: ## ## Each user could implement 'xpg' via a shortname alias ## put in their $HOME/.bashrc or $HOME/.bash_aliases ## or $HOME/.kshrc or $HOME/.profile (or whatever) file, like ## ## alias xpg='$DIRxpg/scripts/xpg' ## ## where $DIRxpg represents the install directory of the 'xpg' ## system files: ## Tk scripts: ## shofil.tk ## sho_colorvals_via_sliders3rgb.tk ## select_font.tk ## Shell scripts: ## xpg ## findANDshow_NOTstringsINfile.sh ## findANDshow_stringsINfile_plusminusNlines.sh ## set_localoutlist.sh ## Help file: ## shofil.hlp (plain text) ## ## The directory DIRxpg could be a subdirectory of the user's ## home directory --- example: ## $HOME/apps/xpg ## ## Alternatively, a link to that 'xpg' script could be used. ## Example: $HOME/apps/bin/xpg ############################################################################## ## This 'xpg' script was adapted from the 'xpg' script of the 'FE xpg' ## subsystem, which is provided, along with other FE subsystems, at ## www.freedomenv.com. FE = Freedom Environment ## FE system Copyright 2006+ by Blaise Montandon ############################################################################## ## MAINTENANCE HISTORY of this 'xpg' script for posting at wiki.tcl.tk: ## ## Written by: Blaise Montandon 2013aug05 Started based on the 'xpg' script ## of the 'FE xpg' subsystem which is ## packaged at www.freedomenv.com. ## Updated by: Blaise Montandon 20....... ############################################################################## ############################################################# ## Set the installation directory of the set of 'xpg' files. ############################################################# # DIRxpg="$HOME/apps/xpg" DIRxpg="." ###################### ## Set USAGE_TEXT var. ###################### SCRIPTBASENAME=`basename $0` USAGE_TEXT="Usage: $SCRIPTBASENAME [-h] [-f] file1 [ file2 ... file8 ] -h - gives this help -f - to execute this utility in the foreground, rather than background." ########################################################### ## If this script was not executed on the command line and ## if no vars (filenames) were passed, pop a msg (using ## the 'zenity' utility) and exit. ########################################################### ## FOR TESTING: # env > $HOME/env.lis if test "$_" = "" -a "$1" = "" then zenity --info --title "xpg: Need filename." \ --text "\ No filename was passed to the 'xpg' script. $USAGE_TEXT Exiting." exit fi #################################################################### ## Otherwise, if this script IS executed on the command line ## and if no vars (esp. filenames) were passed, echo a msg and exit. #################################################################### # if test $# -eq 0 if test "$1" = "" then echo " $USAGE_TEXT " exit fi ############################################################################## ## Process 'xpg' command options with 'getopts'. ############################################################################## ## '-q' (for QUIET) is not used for now. Maybe someday. ############################################################################## QUIET=false FOREGROUND=false while getopts qhf OPTION do ## FOR TESTING # echo "OPTION: $OPTION" case $OPTION in q) QUIET=true ;; f) FOREGROUND=true ;; h|?) echo " $USAGE_TEXT " exit ;; esac done shift `expr $OPTIND - 1` ############################################################################## ## STARTUP THE 'xpg' GUI --- using a loop. ## A max of 8 files is accepted --- to prevent ## starting up a huge bunch of instances. Who hasn't done that? ############################################################################## ## NOTE: We are using a 'for' loop --- WITHOUT 'in' --- to handle getting ## filenames --- even filenames with embedded spaces. Ref: man bash ############################################################################## ## FOR TESTING: # set -x ######################################################### ## These vars can be changed to set the initial location ## and size of the shofil.tk window(s). ## USERS MIGHT WANT TO RESET THESE TO SUIT THEIR OWN ## PREFERENCES. ######################################################### # export WINLOCX="80" # export WINLOCY="80" # export WINSIZEX="750" # export WINSIZEY="450" ############################################################# ## CNT is used in the loop below to delay starting subsquent ## instances of shofil.tk. ## CNT is also used to limit input filenames to 8. ############################################################# CNT=0 ############################################################### ## The LOOP to display the files, with shofil.tk, for the ## filenames passed to this 'xpg' script. (max of 8 files used) ############################################################### for FILE do ## FOR TESTING: # echo " # FILE = $FILE" if test $CNT = 0 then CNT=`expr $CNT + 1` else ## Pause before starting subsequent instances, ## to make sure they are noticed. sleep 1 CNT=`expr $CNT + 1` fi ## FOR TESTING: # set -x if test "$FOREGROUND" = "false" then $DIRxpg/shofil.tk "$FILE" & else $DIRxpg/shofil.tk "$FILE" fi ## FOR TESTING: # set - if test $CNT -ge 8 then exit fi done