Page 1 of 1

bash scripting advice - tee

Posted: 30. Mar 2016, 16:46
by mimosa
When opening a new ticket to submit a package on Sourceforge, I have found only Ctrl-V (not the X clipboard accessed by middle click) will paste selected text into the box. All through the previous packaging cycle, my workflow was to select the output of slkbuild-postgen with the mouse, open leafpad, paste it in the window with the middle mouse button, do Ctrl-A Ctrl-C, then go to the browser and paste into the box with Ctrl-V. This quickly becomes annoying, but that is what bash is for, right?

So I wrote this little script, which puts the output of the report generator in the right clipboard, as well as sending it to stdout:

Code: Select all

#!/bin/bash
#post.sh
#run slkbuild-postgen (passing any arguments to it) and output result to the xclipboard sourceforge likes
slkbuild-postgen $@ ./SLKBUILD | tee ~/post.txt
cat ~/post.txt | xclip -selection c
I'm quite new to bash scripting, and cobbled this together with duckduckgo searches. The intermediate step of the file is inelegant and (I suspect and hope) unnecessary. I could just pipe the output of the report generator directly to xclip, but then you wouldn't see it on stdout - a useful check if it is garbage, before going over to Sourceforge to submit the package.

I tried this recommendation from stackexchange, but it threw an error:

Code: Select all

slkbuild-postgen $@ ./SLKBUILD | tee >  (xclip -selection c)
Can anyone suggest a neater way?

Re: bash scripting advice - tee

Posted: 30. Mar 2016, 19:12
by gapan
Use the xclip -f option:

Code: Select all

slkbuild-postgen $@ ./SLKBUILD | xclip -selection c -f

Re: bash scripting advice - tee

Posted: 3. Apr 2016, 23:59
by laprjns
Well I stole your idea. I added the following alias to my bashrc file

Code: Select all

alias 'clip=xclip -selection c -f'
Now when i want to generate a package submission report I use the following on the command line. ( using pygtksourceview as an example)

Code: Select all

slkbuild-postgen -32 -64 pygtksourceview/2.10.1/ | clip

Re: bash scripting advice - tee

Posted: 4. Apr 2016, 07:04
by mimosa
I think that may be the neatest solution of all.