zsh-users
 help / color / mirror / code / Atom feed
* using zshz to select target directory
@ 2022-09-20  7:55 zzapper
  2022-09-22  7:25 ` Daniel Shahaf
  0 siblings, 1 reply; 3+ messages in thread
From: zzapper @ 2022-09-20  7:55 UTC (permalink / raw)
  To: Zsh-Users List

Hi

The following actually works very well but I feel it's a bit of a 
kludge/work-around.

I can copy a file 'fish.jpg' to the directory which zshz thinks I'm most 
likely to want according to my string 'myfishes'

e.g.

sz fish.jpg myfishs

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

Is there anything more elegant more 'zsh'?


zzapper




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: using zshz to select target directory
  2022-09-20  7:55 using zshz to select target directory zzapper
@ 2022-09-22  7:25 ` Daniel Shahaf
  2022-09-22  8:15   ` david rayner
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Shahaf @ 2022-09-22  7:25 UTC (permalink / raw)
  To: zsh-users

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: using zshz to select target directory
  2022-09-22  7:25 ` Daniel Shahaf
@ 2022-09-22  8:15   ` david rayner
  0 siblings, 0 replies; 3+ messages in thread
From: david rayner @ 2022-09-22  8:15 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1068 bytes --]


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

[-- Attachment #2: Type: text/html, Size: 2261 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-22  8:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-20  7:55 using zshz to select target directory zzapper
2022-09-22  7:25 ` Daniel Shahaf
2022-09-22  8:15   ` david rayner

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).