1

I have a screenshot tool that only works if I start it from the same directory where the file is in. Now I want to make a shortcut to just press print, the command is:

bash -c '~/Documents/KneckPrint | xsel --clipboard'   

Now as I said, this doesn't work if I don't execute it from the KneckPrint folder.

I've tried

bash -c 'cd ~/Documents/KneckPrint | KneckPrint | xsel --clipboard'    

But that doesn't work so I'm left clueless.

E: the bash -c '…' seems to be necessary because otherwise xsel doesn't get executed.

2

Julie Pelletier suggested (in comments):

bash -c 'cd ~/Documents/KneckPrint && KneckPrint | xsel --clipboard'

A shorter variant of this would be

( cd ~/Documents/KneckPrint && KneckPrint | xsel --clipboard )

This (or Julie's suggestion) could be put into a shell function:

function knecksel {
  ( cd "$HOME/Documents/KneckPrint" && KneckPrint | xsel --clipboard )
}

The subshell ((...)) prevents the directory from remaining changed when the xsel command finishes.

| improve this answer | |
1

You can create rc-file on the fly: bash --rcfile <(cd directory) -c 'command line'

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.