Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 29 Aug 2016, 19:45
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
cli help overloading
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [24 Posts]   Goto page: 1, 2 Next
Author Message
learnhow2code

Joined: 12 Jun 2016
Posts: 1015

PostPosted: Mon 20 Jun 2016, 18:37    Post subject:  cli help overloading  

i wrote a program in python (somewhere) that would "listen" to what you typed at the cli, and provide hints. it "intercepted" whatever you typed by setting .bash_history to update on each command (there is a setting for this) and reading the file.

the python program would run with nohup, so if you typed things it recognized (including "shut up", which made it do that) it would respond accordingly.

the idea was, as you learned how to use the cli, it would give you pointers, tell you useful things you could do. id post it here, though i never loaded it with as many tips as i wanted (i think i started working on it with my wife in mind.)

anyway, here are some very simple things you can do in your .bashrc, unless youre using busybox:

Code:
alias usualhelp="bash -c 'help'"
alias help="/usr/local/bin/help"


if you want the usual (not terribly useful) help command, just type usualhelp.

then if you type help, you can put a file in there that will give you a text menu of options if you dont specify a word after "help" or if you say for example "help network" it can go directly to a "page" (or even another program) to help you with network stuff.

i know puppyhelp is quite useful. a cli version could be quite useful also.

pete, i know you like the idea. what should be added?
Back to top
View user's profile Send private message 
Pete

Joined: 02 Mar 2014
Posts: 543

PostPosted: Mon 20 Jun 2016, 19:50    Post subject: Re: cli help overloading  

learnhow2code wrote:
....
pete, i know you like the idea. what should be added?


I do like the idea.
One thing you could add is a better (clear)screen than the "normal" one
which does not really clear the whole screen but only fools you into thinking it did.

Code:

alias cls='printf "\033c"'
Back to top
View user's profile Send private message 
learnhow2code

Joined: 12 Jun 2016
Posts: 1015

PostPosted: Mon 20 Jun 2016, 20:51    Post subject: Re: cli help overloading  

Pete wrote:
learnhow2code wrote:
....
pete, i know you like the idea. what should be added?


I do like the idea.
One thing you could add is a better (clear)screen than the "normal" one
which does not really clear the whole screen but only fools you into thinking it did.

Code:

alias cls='printf "\033c"'


reset isnt working on your setup? aliases are cool, there should be a whole thread for those (yeah this ones fine too) but i was thinking along the lines of stuff to put in in an overhauled "help" command. like help networking:

Code:
echo -e \\nto connect to available network interfaces: \\n ; #### public domain
for p in $(ip link | cut -d " " -f 2 | tr -d ':') ;
do if [[ "$p" != "lo" ]] ; then echo dhclient $p ;
fi ; done ;
echo -e \\n \\nto find available network interfaces: \\n \\nip link \| 'cut -d " " -f 2 | tr -d' \':\'


output:

to connect to available network interfaces:

dhclient eth0


to find available network interfaces:

ip link | cut -d " " -f 2 | tr -d ':'
Back to top
View user's profile Send private message 
learnhow2code

Joined: 12 Jun 2016
Posts: 1015

PostPosted: Mon 20 Jun 2016, 22:24    Post subject: Re: cli help overloading  

here is a start on an improved help system (for cli users)

Code:
#!/usr/bin/env bash

#### license: creative commons cc0 1.0 (public domain)
#### http://creativecommons.org/publicdomain/zero/1.0/

proginf="cli help overloading 0.1"

# to "install":
# chmod +x this file and copy it to /usr/local/bin
# add these 2 lines to .bashrc: (without the # in front)
#alias usualhelp="bash -c 'help'"
#alias help="/usr/local/bin/help"

if [[ "$1" == "" ]] 
then echo -e \\n # -e "\\036[1;36mpuppy command line help:\\033[0m\n"

function pq()
{
echo -e "$q" | tr '(' '^' | sed "s/\ \@/\x1b\[1\;37m\ \@/g" | sed "s/\@\ /\@\ \x1b\[0\;37m/g" | sed "s/\@\^/\@\x1b\[0\;37m\^/g" | tr '^' '('
}

q='         @@@@@@@@@@@@@@@@                                 ' ; pq
q='     @@@@@@@@@@@@@@@@@@@@@@@@                             ' ; pq
q='    @@@@@@@@@@@@@@@@@@@@@@@@@@                            ' ; pq
q='    @@ @@@@@@@@@@@@@@@@@@@@ @@                            ' ; pq
q='       @@@@  @@@@@@@@  @@@@                               ' ; pq
q='       @@@  ` @@@@@@  ` @@@       \x1b[1;33mpuppy command line help\x1b[0m ' ; pq
q='        @@@  @@@@@@@@  @@@@                               ' ; pq
q='        @@@@@@@@@@@@@@@@@@                                ' ; pq
q='         @@@@@@@@@@@@@@@@                                 ' ; pq
q='          @@@@@(   @@@@@                                  ' ; pq
q='           @@@(     @@@                                   ' ; pq
q='            @@@(   @@@                                    ' ; pq
q='              @@@@@@                                      ' ; pq
q='                                                          ' ; pq

echo -e "    \x1b[1;33mhelp usual   \x1b[0m  standard bash help command"
echo -e "    \x1b[1;33mhelp network \x1b[0m  help with network commands"
echo -e "    \x1b[1;33mhelp files   \x1b[0m  help with file commands"
echo -e "    \x1b[1;33mhelp config  \x1b[0m  help with some puppy settings"
echo -e "    \x1b[1;33mhelp misc    \x1b[0m  commands to reboot, stop beeping, etc."
echo -e "    \x1b[1;33mhelp coding  \x1b[0m  quick help for coding"
echo -e "    \x1b[1;33mhelp alias   \x1b[0m  aliases to customize bash"
echo

else

if [[ "$1" == "usual" ]] 
then bash -c 'help'
fi

if [[ "$1" == "network" ]] 
then echo -e "help with network commands" \\n

echo -e \\nto connect to available network interfaces: '(use one)'\\n
for p in $(ip link | cut -d " " -f 2 | tr -d ':') ;
do if [[ "$p" != "lo" ]] ; then echo dhclient $p ;
fi ; done ;
echo -e \\n \\nto find available network interfaces: \\n \\nip link \| 'cut -d " " -f 2 | tr -d' \':\'

fi

if [[ "$1" == "files" ]] 
then echo "help with file commands"
fi

if [[ "$1" == "config" ]] 
then echo "help with some puppy settings"
fi

if [[ "$1" == "misc" ]] 
then echo "commands to reboot, stop beeping, etc."
fi

if [[ "$1" == "coding" ]] 
then echo "quick help for coding"
fi

if [[ "$1" == "alias" ]] 
then echo "aliases to customize bash"
fi

fi
Back to top
View user's profile Send private message 
ebisu

Joined: 25 Sep 2013
Posts: 171

PostPosted: Tue 21 Jun 2016, 00:57    Post subject:  

help case Wink
Back to top
View user's profile Send private message 
learnhow2code

Joined: 12 Jun 2016
Posts: 1015

PostPosted: Tue 21 Jun 2016, 02:03    Post subject:  

ebisu wrote:
help case Wink


edit: you meant a totally different thing than i thought you meant. Smile

Last edited by learnhow2code on Tue 21 Jun 2016, 07:32; edited 1 time in total
Back to top
View user's profile Send private message 
Pete

Joined: 02 Mar 2014
Posts: 543

PostPosted: Tue 21 Jun 2016, 03:55    Post subject:  

@learnhow2code

A few suggestions if I may, make the script available as an attachment
to make it easier for those that are starting to learn the CLI.
Include lots of help on how to run, change permissions and so on
and give it a version number.

Perhaps even start a new thread especially for it, similar to what I have done with fields.awk.

You don't necessarily have to limit it to just the help system but make it more
general with handy hints and tips for the CLI newcomers.

Lastly, I highly recommend LXTerminal (available in the PPM) over urxvt due to
it's superior handling of copy and paste.
Will certainly make a newcomers life on the CLI much easier being able to
copy/paste to/from the GUI.
Back to top
View user's profile Send private message 
ebisu

Joined: 25 Sep 2013
Posts: 171

PostPosted: Tue 21 Jun 2016, 05:04    Post subject:  

learnhow2code wrote:

Code:

     (.)  (.)


  ()))))))))))))
       ()     ()
       ()     ()
         ())))


Code:
case $1 in
  files)  echo "help with file commands" ;;
  config) echo "help with some puppy settings"  ;;
  misc)   echo "commands to reboot, stop beeping, etc." ;;
  coding) echo "quick help for coding"  ;;
  alias)  echo "aliases to customize bash"  ;;
esac
Back to top
View user's profile Send private message 
learnhow2code

Joined: 12 Jun 2016
Posts: 1015

PostPosted: Tue 21 Jun 2016, 07:31    Post subject:  

[quote="ebisu"]
Code:
case $1 in
  files)  echo "help with file commands" ;;
  config) echo "help with some puppy settings"  ;;
  misc)   echo "commands to reboot, stop beeping, etc." ;;
  coding) echo "quick help for coding"  ;;
  alias)  echo "aliases to customize bash"  ;;
esac


i can see how this could be useful; i used the case structure in basic for years.

after over half a decade using python, case and i havent really stayed in touch. thanks for the fond feelings of an old friend.

that said, i would never use it in bash unless i had to-- the double semicolons are just about the most hideous syntax ive ever seriously considered using, and the rest of it simply makes it more difficult to find the conditional structure when the script gets large enough.

$1 is never going to be files and misc at the same time, and the rest of it is premature-optimizationy, but i will look out for a point where a "switch" (a ha) is needed.
Back to top
View user's profile Send private message 
learnhow2code

Joined: 12 Jun 2016
Posts: 1015

PostPosted: Tue 21 Jun 2016, 07:54    Post subject:  

Pete wrote:
A few suggestions if I may, make the script available as an attachment
to make it easier for those that are starting to learn the CLI.


good idea, but i was hoping people would look at it, offer ideas like you did, and (while its small) thats more likely to happen if you can just look at the code-- why download it (and install) if you dont know what its for? its not ready for that imo.

also the simpler it stays, the easier for a new scripter to learn how it works (thats one reason why i dont want case if i can help it. if then fi is more universal, and semantically closer to while and for loops. case, even in basic, may be better but its great to learn it as an alternative to if. the logo doesnt fit this theme, obviously.)


i confess that while i will consider any changes proposed, what im really looking for is suggestions for info i can add to help the user. thats the part i wish i could get input from *everyone* on.

Quote:
Include lots of help on how to run, change permissions and so on
and give it a version number.


it may come to that. i was hoping to entice devs to consider making it a standard feature. in which case not only can they figure it out, but i gave instructions:

Quote:
# to "install":
# chmod +x this file and copy it to /usr/local/bin
# add these 2 lines to .bashrc: (without the # in front)
#alias usualhelp="bash -c 'help'"
#alias help="/usr/local/bin/help"


they dont have to use the puppy part. i thought it was fun, its not the most important part of the script.

it has a version number. its even set in a variable near the top. what do you propose?


Quote:
Perhaps even start a new thread especially for it, similar to what I have done with fields.awk.


yeah, i might. there was only one post prior, so if i post without that, im removing the part that says "what should we do with this?" and context is good.


Quote:
You don't necessarily have to limit it to just the help system but make it more
general with handy hints and tips for the CLI newcomers.


im not sure how much to expand it, especially without a number of suggestions. im framing any of whatever gets added as "help system." doesnt have to be a single script. could be used to call interactive tutorials.

Quote:
I highly recommend LXTerminal (available in the PPM) over urxvt due to
it's superior handling of copy and paste.
Will certainly make a newcomers life on the CLI much easier being able to
copy/paste to/from the GUI.


same here. i even prefer it to the one in xfce. however, as long as the default is standard by comparison, helping people with what they have is a priority:

"why would i install a second term if i dont even use this one?"

"because youll like it more."

"thats ok, i probably wont use the term anyway. i dont need another one."

maybe puppy uses urxvt because its light, or no one cares, or because it has those awesome features they mentioned. like you, i really like the lx one. i often install it even when i dont use lxde.
Back to top
View user's profile Send private message 
Pete

Joined: 02 Mar 2014
Posts: 543

PostPosted: Tue 21 Jun 2016, 08:55    Post subject:  

I for one think that your help project is a good one but try and make the installation procedure all based on the GUI.
Include screenshots or even make available the procedure in html files.
This will help more people ease into the CLI.

To those that know the CLI already, things like chmod, mv and so on are not a big deal, but for those that don't?
Back to top
View user's profile Send private message 
learnhow2code

Joined: 12 Jun 2016
Posts: 1015

PostPosted: Tue 21 Jun 2016, 13:26    Post subject:  

Pete wrote:
I for one think that your help project is a good one but try and make the installation procedure all based on the GUI.
Include screenshots or even make available the procedure in html files.
This will help more people ease into the CLI.


the point is to have the user only need to type "help."

its a single bash script-- the user shouldnt have to install (or copy, or download) anything at all.

if it has good information (thats still the main thing its missing, otherwise its like a website but no content on it) then it would be reasonable for someone to overload the help command with it, in their puplet.

other than that use case, im happy to support people that want to install it, but i would not suggest making a package out of it.

making it a package would ensure that its useless and a waste of time. it should come pre-installed, thats what its for.

also pointless if no one suggests commands to include. yes, i can do all that myself, though i thought it would be far more reasonable to allow input first. who am i to rewrite "help" without input?

it should not be a package. its pointless as a package. and making it easier to install for people that cant use it they way it is right now? also pointless. the only people that should be installing it right now, are people who already get the idea of the standard help command. they will be able to run it quite easily.

anyone else would simply be wasting their time. this is a programming subforum, about code and writing code. i do know where the subforum for packages is.
Back to top
View user's profile Send private message 
ebisu

Joined: 25 Sep 2013
Posts: 171

PostPosted: Tue 21 Jun 2016, 20:49    Post subject:  

learnhow2code wrote:
that said, i would never use it in bash unless i had to-- the double semicolons are just about the most hideous syntax ive ever seriously considered using,
If you never use or seriously consider a more efficient option because you have problems with double semicolons then you are not a serious coder Laughing
Back to top
View user's profile Send private message 
learnhow2code

Joined: 12 Jun 2016
Posts: 1015

PostPosted: Tue 21 Jun 2016, 21:06    Post subject:  

ebisu wrote:
If you never use or seriously consider a more efficient option because you have problems with double semicolons then you are not a serious coder Laughing


thats not true at all-- i am serious enough that when you overload or double an already-redundant syntax element,, thats when i actually take offense. also, you claim that i didnt seriously consider it. ive thought about it more than once today;; its still appalling.

seriously though, the semicolon is overrated;; the one thing i do like about it is that it shows clearly the demarcation between logical loc,, without being tedious to type on us keyboards. (if youre in europe you may not enjoy semicolons as much as i do.)

i like the idea of code not confusing people without any real need;; theres no real purpose for a "double semicolon" syntactic element. whoever came up with that was smoking something-- even if it was charles babbage. who loves semicolons so much,, they want twice as many as they already have,, and four times as many as they even need? Razz you may think i reject it on aesthetics-- no, i think "redundancy, ambiguity, tediousness: at least try to maintain a limit of two!" Smile cheers.

honestly, its my fault for not being more explicit that was looking for tips for things to include as content. i dont mind the back-and-forth about minutiae, thats fun too. but as-is, the script does nothing anyway. too bad, it had potential. no intention of making it perfect at what it does until its useful-- theres nothing efficient about that... and a "serious coder" wouldve used c for this anyway!
Back to top
View user's profile Send private message 
ebisu

Joined: 25 Sep 2013
Posts: 171

PostPosted: Tue 21 Jun 2016, 22:43    Post subject:  

learnhow2code wrote:
thats not true at all-- i am serious enough that when you overload or double an already-redundant syntax element,, thats when i actually take offense. also, you claim that i didnt seriously consider it. ive thought about it more than once today;; its still appalling.

seriously though, the semicolon is overrated;;

Laughing If you feel so emotional about seemingly overloaded and redundant syntax elements then count the redundant semicolons in your code
Code:
for p in $(ip link | cut -d " " -f 2 | tr -d ':') ;
do if [[ "$p" != "lo" ]] ; then echo dhclient $p ;
fi ; done ;

I also wonder why you use double brackets and double equations. Don't you find those "appalling"? In your script they are not even needed.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 2 [24 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic 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.1464s ][ Queries: 11 (0.0063s) ][ GZIP on ]