Page 1 of 1

Code Tray

Posted: Sun 14 Jun 2020, 10:48
by fredx181
*** Code Tray ***

Update 2020-07-03 Some improvements, by misko_2083 http://murga-linux.com/puppy/viewtopic. ... 77#1062177
Update 2020-06-17 version 2, attached code_tray2.sh.tar.gz, see changes here

Often I need to try out code snippets, e.g. from text file, from here or anywhere else on the web.
As I wanted a convenient way to do that and also the ability to save, edit them quickly, I made this for my own use, perhaps it's useful for others too.
I know there are different ways to do similar, e.g. by using geany (but frankly I didn't explore them much)
Took some parts from 'trans_tray' and from examples in the 'YAD - tips' thread, thanks misko, mochimoppel, vovchik, stemsee and others.

Attached is: code_tray.sh.tar.gz, extract and run code_tray.sh, then just highlight a piece of code and left-click the tray icon to run it.
Depends on yad and xclip. (yad needs to be version 0.37 or higher)
(preferences, geometry settings and saved codes are stored in ~/.code_tray)
The terminal to use is set to 'xterm' by default, some puppies don't have it perhaps, then change in the settings to e.g. urxvt or e.g. lxterminal.

From Help (right-click menu):
- Select some code (bash) (no need to copy, just select it), e.g. in browser or text file.
Then by left-clicking the icon, a terminal will appear running the code.

- From menu (right-click) there are some other options, e.g:
- Preferences, to change some default settings, e.g. texteditor, terminal, set font
- Show selected code, save to a file if you wish
(can be handy to edit it, select it, then run it by left-clicking the icon)
- View saved codes (located in ~/.code_tray/saved)

Hint: If you need to edit selected code, run 'Show selected code' from menu,
then edit it, select it and run by left-clicking the icon

Required is to have 'xclip' installed.
It could be that there's a limit for the amount of lines, I tried with 1000+ lines of code and still works ok though.

Any opinions, suggestions to improve are welcome!

Fred

Posted: Sun 14 Jun 2020, 13:14
by vovchik
Dear Fred,

Very nice and useful - for people who code and want to test quickly. I changed the terminal setting to sakura -h and it works fine.

With kind regards,
vovchik

Posted: Wed 17 Jun 2020, 18:25
by fredx181
Updated code_tray, version 2 (code_tray2.sh), changes:
- Added to menu choice where to save codes (Save directory)
- Changed "Change run directory" from menu, now opens a selection dialog to choose a directory.
Attached at first post.

Fred

Posted: Thu 02 Jul 2020, 21:10
by misko_2083
Fred is runc function used at all? :?:

I've got some changes in the script:
- Changed the terminal field to CBE and added some default terminal commands.
- Added an option to replace non-breaking characters to regular spaces.
Because Eugene asked here:
https://unix.stackexchange.com/question ... -character
Don't ask how I opened that webpage...
Anyway, I remembered Fred is into pasting business. :)

BTW, Someone with an account on unix.stackexchange.com should tell Eugene that he can map NBSP to regular space on the readline level.
Apparently, Eugene tried to paste the output of this command

Code: Select all

echo -e "echo\u00A0test"
and copied that to the command line whole line is treated like a command, resulting in error

Code: Select all

bash: echo test: command not found
From the readline library manual https://linux.die.net/man/3/readline
it's config file is ~/.inputrc

So if you create .inputrc in your home direrecory and put next inside

Code: Select all

# include default system config because ~/.inputrc overrides system config
$include /etc/inputrc
# map NBSP to whitespace
"\xc2\xa0":" "
Save the file and restart the terminal, all NBSP characters will be mapped as regular space
"\xc2\xa0" <- NBSP aka "\u00A0" in unicode

Posted: Fri 03 Jul 2020, 17:42
by fredx181
Thanks for the improvements, misko
Fred is runc function used at all?
Wel, I initially had different functionality in mind, but yes, if accidentally clicking the icon while nothing is highlighted, you can highlight some code , then type runc to run it in the terminal that has appeared (and again by keeping the terminal open).
Interesting about non-breaking characters and regular spaces, didn't know about that.

Fred

Posted: Tue 07 Jul 2020, 16:45
by misko_2083
fredx181 wrote:Thanks for the improvements, misko
Fred is runc function used at all?
Wel, I initially had different functionality in mind, but yes, if accidentally clicking the icon while nothing is highlighted, you can highlight some code , then type runc to run it in the terminal that has appeared (and again by keeping the terminal open).
Interesting about non-breaking characters and regular spaces, didn't know about that.

Fred
It's a good idea.
If the terminal is open and I select the code somewhere, middle mouse button click will paste it.
It defeats the purpose of the script. :)
But it's good to see that the script can follow what is copied.
Perhaps it would be more useful if Code Tray is transformed to a clipboard manager. To show the last 10 commands or as defined in the settings. And an option to clear the history in the last menu item.

Posted: Wed 08 Jul 2020, 10:28
by fredx181
misko wrote:It's a good idea.
If the terminal is open and I select the code somewhere, middle mouse button click will paste it.
It defeats the purpose of the script.
Yes, middle click to paste in terminal is what I often use, but it doesn't work always, not exactly sure why, I think in case the code contains tabs (one of the reasons I made code_tray as it seems to work in all cases).
Perhaps it would be more useful if Code Tray is transformed to a clipboard manager. To show the last 10 commands or as defined in the settings. And an option to clear the history in the last menu item.
Great idea, I'm not sure if I'm capable to make it like that, but certainly something to keep in mind.

Fred

Posted: Fri 10 Jul 2020, 11:17
by fredx181
Been playing some more with code_tray by adding misko's suggestion, when copied to clipboard, entrie(s) will show in right-click menu, set the max number in Preferences (default 10)
All the rest I kept the same, maybe not finished yet, attached code_tray3.sh for testing.
So now two options:
1) Select some code (bash) (no need to copy, just select/highlight it), e.g. in browser or text file.
Then by left-clicking the icon, a terminal will appear running the code.

2) Copy some code (not just highlight) or a script, right-click the icon and on top of the menu select one of the entries to run it.

Adding an entry to right-click menu by just highlighting would be possible too, but not the right way, I think, because it depends on how much time it takes to highlight a piece of code, and things can become weird then.
But maybe I don't know enough about xclip options.

Fred

Posted: Sat 11 Jul 2020, 01:20
by sunburnt
my god! fredx!
it's great to see you, it's been years!
I hope all is well with you and yours.

I'm making due in this Covid Trump mercamera
world they have us stuffed into here in the U.S.
it has not been good at all. in an instant everything
changed and it'll Never be the same again!
the U.S. mints stopped making change!
the stores ran out! no joke!

hey, I'd love to chat more if you would like to.
just let me know, I'll look back here.