Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: using zshz to select target directory




On 22/09/2022 08:25, Daniel Shahaf wrote:
zzapper wrote on Tue, 20 Sep 2022 07:55 +00:00:
sz () {
     alias z='zshz 2>&1'
     if (( $# != 2 ))
     then
         echo 'Usage: Enter file to copy & destination directory string 
for z'
         echo 'e.g: sz file.txt project2'
         return 1
     fi
     f=$1
     zshz $2 2>&1
     cp -ip ~-/$f .
}
Instead of changing global state (cwd), it would be more idiomatic to
call a function that returns a string via $REPLY, and then «cp -ip --
./$f $REPLY».  Or just stick the last two commands in a subshell, so the
outer shell's cwd doesn't change.

The alias definition is also a form of changing global state.

Also, usage messages should start with the name of the command (or in
this case, function).

Daniel

I've been able to simplify it because the zsh port of 'z' has a list only function '-e'

(https://github.com/agkozak/zsh-z)

zcp(){cp $1 $(zshz -e $2)}

e.g.

zcp dog.jpg dogPhotosDir

zzapper



Messages sorted by: Reverse Date, Date, Thread, Author