bash scripting advice - tee

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

bash scripting advice - tee

Post by mimosa » 30. Mar 2016, 16:46

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: 5619
Joined: 6. Jun 2009, 17:40

Re: bash scripting advice - tee

Post by gapan » 30. Mar 2016, 19:12

Use the xclip -f option:

Code: Select all

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

User avatar
laprjns
Salix Warrior
Posts: 1051
Joined: 28. Aug 2009, 01:30
Location: Connecticut USA

Re: bash scripting advice - tee

Post by laprjns » 3. Apr 2016, 23:59

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: 3141
Joined: 25. May 2010, 17:02
Contact:

Re: bash scripting advice - tee

Post by mimosa » 4. Apr 2016, 07:04

I think that may be the neatest solution of all.

Post Reply