ZCP — Zenity Copy program

Geek, Lighting Tech, Maker

ZCP — Zenity Copy program

 #!/bin/bash  
# Zenity based graphical Progress bar for the cp command
# currently only works for a single file
# bugs, Using the dialog kill command kills ALL instances of "cp" not just the active one
# Developed by CPYarger <cpyarger@gmail.com>
# Released under GPLv3

trap "killall cp" SIGINT SIGTERM EXIT #stops the "cp" command on case of error or zenity dialog cancel butting being pressed
infile=$1 #variable for input file
outfile=$2 # variable for output file
#rm $outfile #for testing only
insize=$(ls -alt $infile |cut -d " " -f 5 ) #Gives input file size
infiles=$(readlink -f $infile) #gives full link to input file
outfiles=$(readlink -f $outfile) #gives full link to output file

x=0 # helps keep the while loop functioning at init
z=0 # helps keep the while loop functioning at init
touch $outfile # helps keep the while loop functioning at init

while [[ z -lt 100 ]]; do x=$(ls -alt $outfile|cut -d " " -f 5 );z=$(( $x*100/$insize )) ;echo $z 2>&1 ;echo $z ;done | zenity --progress --auto-kill --title=ZenityCopy --text="Copying File" & # Checks file size. does a basic percentage calculation and outputs the percentage to the zenity progress dialog window
#--text="Copying $infiles ton $outfiles"& #do not use, It causes hang ups with the zenity dialog box
#--title=ZenityCopy #just in case
cp $infile $outfile #the copy command
exit 0 #gives a clean exit.

No Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.