(OLD) (ARCHIVED) Puppy Linux Discussion Forum Forum Index (OLD) (ARCHIVED) Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info

This forum can also be accessed as http://oldforum.puppylinux.com
It is now read-only and serves only as archives.

Please register over the NEW forum
https://forum.puppylinux.com
and continue your work there. Thank you.

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups    
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 18 Sep 2020, 04:04
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Code Tray
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. View previous topic :: View next topic
Page 1 of 1 [9 Posts]  
Author Message
fredx181


Joined: 11 Dec 2013
Posts: 4481
Location: holland

PostPosted: Sun 14 Jun 2020, 06:48    Post subject:  Code Tray
Subject description: Convenient way to try out shell code snippets
 

*** Code Tray ***

Update 2020-07-03 Some improvements, by misko_2083 http://murga-linux.com/puppy/viewtopic.php?p=1062177#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):
Quote:
- 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
code_tray2.sh.tar.gz
Description  Extract and run code_tray2.sh
gz

 Download 
Filename  code_tray2.sh.tar.gz 
Filesize  5.56 KB 
Downloaded  130 Time(s) 
code_tray.sh.tar.gz
Description  Extract and run code_tray.sh
gz

 Download 
Filename  code_tray.sh.tar.gz 
Filesize  5.35 KB 
Downloaded  125 Time(s) 
code-tray.jpg
 Description   code-tray menu and text window
 Filesize   40.9 KB
 Viewed   809 Time(s)

code-tray.jpg

code-tray-settings.jpg
 Description   code-tray settings
 Filesize   37.04 KB
 Viewed   809 Time(s)

code-tray-settings.jpg


_________________
Dog Linux website
Tinylinux blog by wiak

Last edited by fredx181 on Fri 03 Jul 2020, 13:58; edited 5 times in total
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1538
Location: Ukraine

PostPosted: Sun 14 Jun 2020, 09:14    Post subject:  

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
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4481
Location: holland

PostPosted: Wed 17 Jun 2020, 14:25    Post subject:  

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

_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
misko_2083


Joined: 08 Nov 2016
Posts: 114

PostPosted: Thu 02 Jul 2020, 17:10    Post subject:  

Fred is runc function used at all? Question

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/questions/596260/can-i-make-shell-consider-nbsp-a-whitespace-character
Don't ask how I opened that webpage...
Anyway, I remembered Fred is into pasting business. Smile

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:
echo -e "echo\u00A0test"

and copied that to the command line whole line is treated like a command, resulting in error
Code:
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:
# 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
code_tray2.sh.tar.gz
Description 
gz

 Download 
Filename  code_tray2.sh.tar.gz 
Filesize  5.8 KB 
Downloaded  111 Time(s) 
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4481
Location: holland

PostPosted: Fri 03 Jul 2020, 13:42    Post subject:  

Thanks for the improvements, misko

Quote:
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

_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
misko_2083


Joined: 08 Nov 2016
Posts: 114

PostPosted: Tue 07 Jul 2020, 12:45    Post subject:  

fredx181 wrote:
Thanks for the improvements, misko

Quote:
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. Smile
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.
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4481
Location: holland

PostPosted: Wed 08 Jul 2020, 06:28    Post subject:  

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).

Quote:
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

_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
fredx181


Joined: 11 Dec 2013
Posts: 4481
Location: holland

PostPosted: Fri 10 Jul 2020, 07:17    Post subject:  

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
code_tray3.sh-test.tar.gz
Description  Extract and run code_tray3.sh
gz

 Download 
Filename  code_tray3.sh-test.tar.gz 
Filesize  6.72 KB 
Downloaded  94 Time(s) 
code_tray3.png
 Description   
 Filesize   204.04 KB
 Viewed   217 Time(s)

code_tray3.png


_________________
Dog Linux website
Tinylinux blog by wiak
Back to top
View user's profile Send private message 
sunburnt


Joined: 08 Jun 2005
Posts: 5089
Location: Arizona, U.S.A.

PostPosted: Fri 10 Jul 2020, 21:20    Post subject:  

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.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [9 Posts]  
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0791s ][ Queries: 13 (0.0362s) ][ GZIP on ]