command line jarvis: this is a great job, but the examples are easier than they look

 

fig os has something vaguely like this, but i havent spent much time on it. ive written little things like this before, many of us have– the one shown here is a really good one, in my opinion. (found via the register.co.uk)

if you find this cool, my advice is to get working on your own version. you can make it do all kinds of things. source for “welcome” from fig os 2.0 is included here.

 

proginf = "fig os welcome 0.1, oct 2016 mn"

now ""  print
ckremote "pgrep sshd | wc -l"  arrshell  mid 1 1  int

iftrue ckremote
    now ""  print
    now "  you have sshd enabled... to prevent remote logins,"  colortext 12  print  ""  print
    now "  it is recommended you turn it off by typing: "  prints
    now "remote off"  colortext 14  print  colortext 7  ""  print  print
    fig

trythatfirst 0
while  
    qu 0
    rc 0

    ifequal trythatfirst 1
        now " "  times 11  prints  "you can get help simply by typing: " colortext 7  prints  
        now "help"  colortext 14  print  colortext 7  ""  print  print
        trythatfirst 2
    else
        ifequal trythatfirst 0
             trythatfirst 1
             fig  
        fig

    try
        p "type here: "  colortext 10  prints  colortext 7  ""  prints  "bash -c 'read -e t ; echo $t'"  arrshell  mid 1 1
        plen p len
        iftrue plen
            first p  asc
        else
            first 0    
            fig

        now p  ltrim rtrim lcase

        ckcmd " "  plus now  plus " "
        ckcmdremote instr ckcmd " remote " 
        ckcmdoff    instr ckcmd " off "  times ckcmdremote 
        iftrue ckcmdoff
            rc 1
            now " "  times 11  prints  "service ssh stop"  shell  ""  print
            fig

        ifequal now "help"
            rc 1
            trythatfirst 2  ## disable function that tells you about the help command
            now " "  times 11  prints  "valid commands are:"  colortext 3   print  ""  print
            now " "  times 11  prints  "      help"  colortext 14  prints ": to get help"  colortext  7  print
            now " "  times 11  prints  "remote off"  colortext 14  prints ": to turn off remote login"  colortext  7  print
            now " "  times 11  prints  "        sh"  colortext 14  prints ": if you know bash"  colortext  7  print
            now " "  times 11  prints  "      exit"  colortext 14  prints ": (or quit or q) to quit welcome program "  colortext  7  print
            now ""  colortext 7 print
            fig
        ifequal now "sh"
            rc 1
            qu 1
            now " "  times 11  prints  "running bash... welcome program will quit on exit:"  colortext 3   print  ""  print
            now "cd /root ; bash --rcfile /root/.bashrc"  shell
            fig
        ifequal now "exit"
            rc 1
            qu 1
            fig
        ifequal now "quit"
            rc 1
            qu 1
            fig
        ifequal now "q"  
            rc 1
            qu 1
            fig
    except
        qu 1
        resume
    iftrue qu
        now ""  print  system
        fig
    ifequal rc 0
        now " "  times 11  prints  colortext 3  "unrecognized command (no problem)"  prints  colortext 7  ""  print  print
    wend

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s