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

Re: using zshz to select target directory



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).




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