pgsh.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. function pgsh() {
  2. this.prompt = '<span style="color:blueviolet">pgs </span><span style="color:green">$ </span>'
  3. this.welcome = '\
  4. Linux parsleygardens.net 3.4.5-6-7-i286 #8 PGS Vimputer 3.4.56-7 i286 \n\
  5. \n\
  6. ~ Welcome to Parsley Gardens! ~\n\
  7. "He maketh me to lie down in green pa..."\n\
  8. \n\
  9. Type "help" for list of commands\n\
  10. \n'
  11. this.commands = {
  12. 'about': {
  13. 'help': 'Author Information\nUsage: about',
  14. 'run': function(args) {
  15. if (args.length > 0) { return this.help }
  16. return 'Site by Weiyi Lou ' + new Date().getFullYear()
  17. }
  18. },
  19. 'clear': {
  20. 'help': 'Clears the screen\nUsage: clear',
  21. 'run' : function(args, shell, terminal) {
  22. terminal.tags.display.clear()
  23. }
  24. },
  25. 'version': {
  26. 'help': 'Shell Information\nUsage: version',
  27. 'run': function(args) {
  28. if (args.length > 0) { return this.help }
  29. return 'Parsley Gardens Shell (pgsh) 1.0.0. Built with <a target="_blank" href="http://riotjs.com/">Riot.js</a>'
  30. }
  31. },
  32. 'git': {
  33. 'help': 'Link to Code Repository\nUsage: git',
  34. 'run': function(args) {
  35. if (args.length > 0) { return this.help }
  36. return 'Self-Hosted Code Repository at <a target="_blank" href="https://code.parsleygardens.net/explore/projects">code.parsleygardens.net</a>'
  37. }
  38. },
  39. 'hello': {
  40. 'help': 'Usage: hello [name]',
  41. 'run': function(args) {
  42. address = args.join(' ').trim()
  43. if (address.length == 0) {
  44. return 'Hello to you too'
  45. } else if (address == 'pgsh') {
  46. return 'Hello human'
  47. } else {
  48. return 'My name is not "' + address + '"'
  49. }
  50. }
  51. },
  52. 'magic': {
  53. 'help': 'Link to Artist\nUsage: magic',
  54. 'run': function(args) {
  55. if (args.length > 0) { return this.help }
  56. return 'Animation and Illustration at <a target="_blank" href="http://slightlymagic.com.au">slightlymagic.com.au</a>'
  57. }
  58. },
  59. 'su': {
  60. 'help': 'Substitute as root user for Phenomenal Cosmic Power\nUsage: su',
  61. 'run': function(args, shell, terminal) {
  62. if (args.length > 0) { return this.help }
  63. var output = ''
  64. if (!shell.su) {
  65. terminal.tags.commandline.setPrompt('<span style="color:tomato">root </span><span style="color:red">% </span>')
  66. shell.su = true
  67. output = 'With Great Power comes Great'
  68. }
  69. return output
  70. }
  71. },
  72. 'exit': {
  73. 'help': 'Usage: exit',
  74. 'run': function(args, shell, terminal) {
  75. if (args.length > 0) { return this.help }
  76. var output = 'Close browser window to exit'
  77. if (shell.su) {
  78. terminal.tags.commandline.setPrompt(shell.prompt)
  79. shell.su = false
  80. output = ''
  81. }
  82. return output
  83. }
  84. },
  85. 'search': {
  86. 'help': 'Search the web\nUsage: search [query]',
  87. 'run': function(args) {
  88. window.open('https://duckduckgo.com/?q=' + args.join('+'), '_blank')
  89. return 'Searching for "' + args.join(' ') + '" in new window...'
  90. }
  91. },
  92. 'questions': {
  93. 'help': 'Answer some questions!\nUsage: questions',
  94. 'run': function() {
  95. return {
  96. 'run': function(input, terminal) {
  97. if (!this.running) {
  98. this.running = true
  99. terminal.tags.display.hide()
  100. terminal.tags.display.add('Welcome to the questions. Do you wish to continue?')
  101. terminal.tags.commandline.hidePrompt()
  102. return
  103. }
  104. if (input != 'exit') {
  105. terminal.tags.display.set('You answered the last question with "' + input + '"!\nWould you like another question?\n(Type "exit" to end)')
  106. } else {
  107. this.running = false
  108. terminal.tags.display.restore()
  109. terminal.tags.display.add('Thanks for answering questions!')
  110. terminal.tags.commandline.showPrompt()
  111. terminal.returnToShell()
  112. }
  113. }
  114. }
  115. }
  116. },
  117. 'help': {
  118. 'help': 'List all commands or view information for a command\nUsage: help [command]',
  119. 'run': function(args, shell) {
  120. command = args.join(' ').trim()
  121. if (command in shell.commands) {
  122. return shell.commands[command].help
  123. } else {
  124. var output = (command) ? 'Command not found: ' + command + '\n' : ''
  125. var commands = [];
  126. for(var name in shell.commands) {
  127. if (name !== 'Parent') { commands.push(name) }
  128. }
  129. output += 'Available commands:\n' + commands.sort().join(' ')
  130. return output
  131. }
  132. }
  133. }
  134. }
  135. this.run = function(input, terminal) {
  136. var parts = input.trim().split(' ')
  137. // First word is the command, all others are arguments.
  138. var command = parts.splice(0, 1)
  139. var args = parts
  140. var output = ''
  141. if (command in this.commands) {
  142. output = this.commands[command].run(args, this, terminal)
  143. }
  144. return output
  145. }
  146. }