[arch-projects] grab, drop and clone

Dusty Phillips buchuki at gmail.com
Thu Mar 17 13:11:41 EST 2005


Posting about pushd in that last post reminded me of some scripts I
wrote a while back. I am certain there MUST be something like this
available out there, probably built into bash, but I never found it,
so I wrote these scripts. Let me know what I missed. ;-)

Basically, they behave as 'cut and paste files' on the command line. I
can cd into a directory, 'grab' a file or list of files, cd or pushd
to another directory, and 'clone' (copy) or 'drop' (move) those files
into that directory without having to type the full path to different
directories in a mv or cp command. Here's the scripts:

################## grab ####################
#!/bin/sh
grabfile=~/.grab

if [ $# -le 0 ]; then
	echo "Usage: grab filename (filename...)"
	echo
	echo "copies filenames to the grabboard to be moved/copied using drop/clone"
    exit 1
fi
if [ -e $grabfile ]; then
    rm $grabfile
fi
while [ "$#" -ne "0" ]; do
    if [ -e $1 ]; then
        if [ $(echo $1 | grep -e "^\/") ]; then
            echo  -n $1" " >> $grabfile
        else
            echo -n $(pwd)/$1" " >> $grabfile
        fi
    fi
    shift
done

##################### clone ##############
#!/bin/sh
grabfile=~/.grab
function usage() {
	echo "Usage: drop [mv|cp]"
	echo
    echo "copy/move file[s] specified in a grab statement to the
current directory"
    exit 1
}
if [ $# -eq 1 ]; then
    if [ $1 = "cp" -o $1="mv" ]; then
        command=$1
    else
        usage
    fi
elif [ $# -eq 0 ]; then
    command=cp
else
    usage
fi
if [ $command = cp ]; then
    command="cp -r"
fi

if [ -e $grabfile ]; then
    eval $command $(cat $grabfile) .

else
    echo "no files to drop"
    exit 1
fi

##################### drop ##################
#!/bin/sh
clone mv

Somebody please tell me I'm not the first to think of this and that I
overlooked some simple bash built-in or pacman package... Its so
simple... but sometimes very useful.

NOTE: I have had trouble with some of these with files that have names
beginning with a dash or number.

Dusty




More information about the arch-projects mailing list