bash scripting advice - tee

Other talk about Salix
Post Reply
User avatar
mimosa
Salix Warrior
Posts: 3311
Joined: 25. May 2010, 17:02
Contact:

bash scripting advice - tee

Post 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?
User avatar
gapan
Salix Wizard
Posts: 6238
Joined: 6. Jun 2009, 17:40

Re: bash scripting advice - tee

Post by gapan »

Use the xclip -f option:

Code: Select all

slkbuild-postgen $@ ./SLKBUILD | xclip -selection c -f
Image
Image
User avatar
laprjns
Salix Warrior
Posts: 1105
Joined: 28. Aug 2009, 01:30
Location: Connecticut USA

Re: bash scripting advice - tee

Post 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
“Don’t you see that the whole aim of Newspeak is to narrow the range of thought?"
User avatar
mimosa
Salix Warrior
Posts: 3311
Joined: 25. May 2010, 17:02
Contact:

Re: bash scripting advice - tee

Post by mimosa »

I think that may be the neatest solution of all.
Post Reply