pet icon indicating copy to clipboard operation
pet copied to clipboard

new snippet to change dir will not execute

Open optio50 opened this issue 6 years ago • 4 comments

Ubuntu 19.04 [[snippets]] description = "Temp Dir" command = "cd /media/POOL/Temp" output = ""

execute and dir is not changed and no feed back provided. All other snippets work as advertised. manual bash command entry works

any ideas?

optio50 avatar Aug 28 '19 05:08 optio50

I have the same issue too on Ubuntu Disco.

I found a small workaround by creating the following alias. alias pet-cd='PET_CD_SEARCH=$(pet search --query cd) && $PET_CD_SEARCH' I just have to type pet-cd which pulls up fzf and allows me to select the cd command.

Make sure to add the new alias to ~/.bashrc or appropriate location.

Note: Use the full path and no variable when creating pet snippets with cd.

DeepInThought avatar Sep 03 '19 10:09 DeepInThought

Yeah so the issue here is a bit hidden indeed. I think I can understand it only cause I've worked with pet for a while.

Pet basically executes a command by doing sh -c "your command" which executes it in a subshell. This means that in the subshell, the directory change was successful, but when the command is over you go back to the parent shell which is still in the same directory. I might be wrong, still a new maintainer here, but I think this is what's happening with high certainty.

RamiAwar avatar Feb 21 '24 16:02 RamiAwar

✨ Actions ✨ 1- Make this more clear somehow, starting with adding some context in the docs. 2- Provide a workaround - you can indeed use pet search to get the query copied to your cursor, then you execute it in the parent shell. This means that the directory change will happen in the parent shell and not in the subshell. There are lots of other kinds of commands where you'd have to do the same thing.

Btw this is also why if you use pet exec, the command won't appear in your history. But if you use the pet-select snippet (bashrc or zshrc) then you avoid all of these problems.

Now that I think about it 🤔 maybe that should be the default usage.

Pet exec has a lot of side effects like this that are hard to understand. I think we can maybe push harder for the use of the pet select setup as the default way of using pet and discourage the use of pet exec a little. I personally never use pet exec honestly.

@knqyf263 What are your thoughts about this? 😃

RamiAwar avatar Feb 21 '24 16:02 RamiAwar

I don't mind encouraging "pet search" if it confuses users.

knqyf263 avatar Feb 21 '24 17:02 knqyf263

Alright, create a new issue to push for different wording around using the pet search command with the shell shebangs, that will end up providing a better DX.

RamiAwar avatar Feb 26 '24 19:02 RamiAwar