pgsh.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. function pgsh() {
  2. this.prompt = '<span style="color:purple">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. Enter "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() { return 'clear' }
  22. },
  23. 'version': {
  24. 'help': 'Shell Information\nUsage: version',
  25. 'run': function(args) {
  26. if (args.length > 0) { return this.help }
  27. return 'Parsley Gardens Shell (pgsh) 1.0.0. Built with <a target="_blank" href="http://riotjs.com/">Riot.js</a>'
  28. }
  29. },
  30. 'git': {
  31. 'help': 'Link to Code Repository\nUsage: git',
  32. 'run': function(args) {
  33. if (args.length > 0) { return this.help }
  34. return 'Self-Hosted Code Repository at <a target="_blank" href="https://code.parsleygardens.net/explore/projects">code.parsleygardens.net</a>'
  35. }
  36. },
  37. 'hello': {
  38. 'help': 'Usage: hello [name]',
  39. 'run': function(args) {
  40. address = args.join(' ').trim()
  41. if (address.length == 0) {
  42. return 'Hello to you too'
  43. } else if (address == 'pgsh') {
  44. return 'Hello human'
  45. } else {
  46. return 'My name is not "' + address + '"'
  47. }
  48. }
  49. },
  50. 'magic': {
  51. 'help': 'Link to Artist\nUsage: magic',
  52. 'run': function(args) {
  53. if (args.length > 0) { return this.help }
  54. return 'Animation and Illustration at <a target="_blank" href="http://slightlymagic.com.au">slightlymagic.com.au</a>'
  55. }
  56. },
  57. 'su': {
  58. 'help': 'Substitute as root user for Phenomenal Cosmic Power\nUsage: su',
  59. 'run': function(args, context) {
  60. if (args.length > 0) { return this.help }
  61. var output = ''
  62. if (!context.su) {
  63. context.oldprompt = context.prompt
  64. context.prompt = '<span style="color:purple">root </span><span style="color:red">% </span>'
  65. context.su = true
  66. output = 'With Great Power comes Great'
  67. }
  68. return output
  69. }
  70. },
  71. 'exit': {
  72. 'help': 'Usage: exit',
  73. 'run': function(args, context) {
  74. if (args.length > 0) { return this.help }
  75. var output = 'Close browser window to exit'
  76. if (context.su) {
  77. context.prompt = context.oldprompt
  78. context.su = false
  79. output = ''
  80. }
  81. return output
  82. }
  83. },
  84. 'help': {
  85. 'help': 'List all commands or view information for a command\nUsage: help [command]',
  86. 'run': function(args, context) {
  87. command = args.join(' ').trim()
  88. if (command in context.commands) {
  89. return context.commands[command].help
  90. } else {
  91. var output = (command) ? 'Command not found: ' + command + '\n' : ''
  92. var commands = [];
  93. for(var name in context.commands) {
  94. if (name !== 'Parent') { commands.push(name) }
  95. }
  96. output += 'Available commands:\n' + commands.sort().join(' ')
  97. return output
  98. }
  99. }
  100. }
  101. }
  102. this.process = function(input) {
  103. var parts = input.trim().split(' ')
  104. // First word is the command, all others are arguments.
  105. var command = parts.splice(0, 1)
  106. var args = parts
  107. var output = ''
  108. if (command in this.commands) {
  109. var shell = this
  110. output += this.commands[command].run(args, shell)
  111. }
  112. return output
  113. }
  114. }