[arch-projects] grab, drop and clone
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
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.
hmmm, it sounds like an editor feature extended to terminal-land... i like it... it's be fun however, I would personally use an enironment variable, as a sort of clipboard.... I think zsh may have something similar to this built in... not sure though... zsh is too complicated for my tastes
hmmm, it sounds like an editor feature extended to terminal-land... i like it... it's be fun
however, I would personally use an enironment variable, as a sort of clipboard....
Yeah, I tried that work, but it doesn't work so good if you have two xterms open, and grab in one of them and want to drop in the other.... is it possible to export between two sessions after they've been opened? Dusty
On Thu, 2005-03-17 at 13:16 -0600, Aaron Griffin wrote:
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.
I think zsh may have something similar to this built in... not sure though... zsh is too complicated for my tastes
Heretic. zsh is the answer to all your problems :) I don't know of anything in zsh exactly like this, but you can just use the ~<number> syntax to refer to directories in the directory stack (I've a feeling this is standard ksh syntax too, so should work in bash too). i.e. 'cp ~1/foo .' copies foo from the directory on the top of the stack to the current directory. - olly
I don't know of anything in zsh exactly like this, but you can just use the ~<number> syntax to refer to directories in the directory stack (I've a feeling this is standard ksh syntax too, so should work in bash too).
i.e. 'cp ~1/foo .' copies foo from the directory on the top of the stack to the current directory.
It works in bash, I just tried it. This is wonderful. Thanks for this hint! Dusty
participants (3)
-
Aaron Griffin
-
Dusty Phillips
-
Oliver Burnett-Hall